Skip to content

Instantly share code, notes, and snippets.

@furu
Last active June 10, 2016 11:56
Show Gist options
  • Save furu/7fd69194640211826f14181ddd32a757 to your computer and use it in GitHub Desktop.
Save furu/7fd69194640211826f14181ddd32a757 to your computer and use it in GitHub Desktop.
sinatra アプリケーションを unicorn で動かすときの unicorn の init スクリプト
#!/bin/sh
# chkconfig: 345 60 40
# description: unicorn application server
# processname: unicorn
USER="ec2-user"
APP_ENV="production"
APP_ROOT="/home/ec2-user/www/foo/current"
UNICORN_CONF_FILE="$APP_ROOT/config/unicorn.rb"
PID="$APP_ROOT/tmp/pids/unicorn.pid"
BUNDLE="/usr/local/bin/bundle"
cd $APP_ROOT || exit 1
start() {
su - $USER -c "cd $APP_ROOT && \
SINATRA_ENV=$APP_ENV RAILS_ENV=$APP_ENV \
$BUNDLE exec unicorn -c $UNICORN_CONF_FILE -E deployment -D"
}
sig() {
test -s $PID && kill -$1 `cat $PID`
}
case "$1" in
start)
sig 0 && echo >&2 "Already running" && exit 0
$1
;;
stop)
sig QUIT && exit 0
echo >&2 "Not running"
;;
force-stop)
sig TERM && exit 0
echo >&2 "Not running"
;;
status)
sig 0 && echo >&2 "unicorn is running" && exit 0
echo >&2 "unicorn is not running"
;;
*)
echo $"Usage: $0 {start|stop|force-stop|status}"
exit 2
esac