このシェルスクリプトは config/thin_example.sh に書きました
#!/bin/sh
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/deployer/apps/example/current
PID=$APP_ROOT/tmp/pids/thin.pid
CMD="cd $APP_ROOT; bundle exec rackup -D -P $PID $APP_ROOT/config/faye.ru -s thin -E production"
AS_USER=deployer
set -u
startme() {
run "$CMD"
}
stopme() {
run "pkill -f $PID"
}
run () {
if [ "$(id -un)" = "$AS_USER" ]; then
eval $1
else
su -c "$1" - $AS_USER
fi
}
case "$1" in
start) startme ;;
stop) stopme ;;
restart) stopme; startme ;;
*) echo "usage: $0 start|stop|restart" >&2
exit 1
;;
esac
Ryan Bates がVPS 展開 railscast (pro only)で使用したユニコーン スクリプトを大まかに変更したもの。
実行可能にする
chmod +x config/thin_example.sh
これを init.d にシンボリック リンクする必要があります (実行可能にするために chmod +x を実行した後)。
sudo ln -nfs /home/deployer/apps/example/current/config/thin_example.sh /etc/init.d/thin_example
次に、サーバーで起動する場合
sudo update-rc.d thin_example defaults
それ以外の場合は、できるはずです/etc/init.d/thin_example [start|stop|restart]
。注意すべき重要な点は、rackup をデーモン モード (-D) で開始するように指示し、PID を明示的に設定して、後で停止できるようにしていることです。