Skip to content

Instantly share code, notes, and snippets.

@TheNaoX
Created October 9, 2012 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheNaoX/3861056 to your computer and use it in GitHub Desktop.
Save TheNaoX/3861056 to your computer and use it in GitHub Desktop.
init.d script for deploy unicorn on VPS
#!/bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
UNICORN=/path/to/your/app/vendor/bundle/ruby/1.9.1/bin/unicorn_rails
KILL=/bin/kill
APP_ROOT=/path/to/your/app
PID=$APP_ROOT/tmp/pids/unicorn.pid
GEM_HOME=/path/to/your/app/vendor/bundle/ruby/1.9.1/gems
source /usr/local/rvm/scripts/rvm
sig () {
test -s "$PID" && kill -$1 `cat $PID`
}
case "$1" in
start)
echo "Starting unicorn..."
cd $APP_ROOT
if [[ $EUID -ne 1002 ]]; then
su app_user -c 'source /usr/local/rvm/scripts/rvm ; bundle exec unicorn_rails -D -E staging -c /path/to/your/app/config/unicorn_staging.rb -p 5000';
else
bundle exec $UNICORN -D -E staging -c /path/to/your/app/config/unicorn_staging.rb -p 5000;
fi
;;
stop)
sig QUIT && exit 0
echo >&2 "Not running"
;;
restart)
$0 stop
$0 start
;;
status)
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment