Running Rails apps with thin as a service

帅比萌擦擦* 提交于 2019-12-03 16:35:32

I came up with this, but I don't feel like it is the best solution as it does not take advantage of thin's "--all" option where it reads the config files from a directory. Instead I modified the file that starts/stops/restarts the thin service so for each app I give it a specific command for starting/stopping/restarting. I'm certain this command could be improved, but for now it works for my needs.

#!/bin/sh

# This is a pretty bad, but effective workaround for starting thin as a service per application.

DAEMON=/usr/local/lib/ruby/gems/1.9.1/bin/thin
# DAEMON=/usr/local/bin/bundler thin
SCRIPT_NAME=/etc/init.d/thin
CONFIG_PATH=/etc/thin

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

case "$1" in
  start)
  cd /srv/hub/current && bundle exec thin start -d -C /etc/thin/hub.yml
  ;;
  stop)
  cd /srv/hub/current && bundle exec thin stop -d -C /etc/thin/hub.yml
  ;;
  restart)
  cd /srv/hub/current && bundle exec thin restart -d -C /etc/thin/hub.yml
  ;;
  *)
  echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
  exit 3
  ;;
esac
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!