Created
August 21, 2012 09:10
-
-
Save mswart/3413790 to your computer and use it in GitHub Desktop.
Init.d-Script for unicorn with bundle and rvm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UNICORN_USER=www-data | |
UNICORN_GROUP=www-data | |
BUNDLE_GEMFILE=/var/www/current/Gemfile | |
RVM_EXE=/usr/local/rvm/bin/rvm | |
RAILS_ROOT=/var/www/current/ | |
RAILS_ENV=production | |
RAILS_VERSION=ree | |
UNICORN_CONFIG="${RAILS_ROOT}/config/unicorn.rb" | |
UNICORN_PIDFILE=${RAILS_ROOT}/tmp/pids/unicorn.pid | |
RAILS_EXE=/usr/local/rvm/rubies/ree-1.8.7-2012.02/bin/ruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: unicorn | |
# Required-Start: $remote_fs $syslog | |
# Required-Stop: $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: | |
# Short-Description: unicorn server init.d script | |
### END INIT INFO | |
set -e | |
umask 022 | |
if test -f /etc/default/unicorn; then | |
. /etc/default/unicorn | |
fi | |
. /lib/lsb/init-functions | |
cd $RAILS_ROOT | |
export BUNDLE_GEMFILE | |
case "$1" in | |
start) | |
log_daemon_msg "Starting Unicorn Webserver" "unicorn_rails" || true | |
start-stop-daemon --start --chuid $UNICORN_USER:$UNICORN_GROUP --chdir $RAILS_ROOT --pidfile $UNICORN_PIDFILE --exec $RVM_EXE -- $RUBY_VERSION do bundle exec unicorn_rails -c $UNICORN_CONFIG -E $RAILS_ENV -D | |
log_end_msg $? || true | |
;; | |
stop) | |
log_daemon_msg "Stopping Unicorn web server" "unicorn_rails" || true | |
if start-stop-daemon --stop --quiet --oknodo --pidfile "${UNICORN_PIDFILE}"; then | |
log_end_msg 0 || true | |
else | |
log_end_msg 1 || true | |
fi | |
;; | |
restart) | |
log_daemon_msg "Restarting Unicorn web server" "unicorn_rails" || true | |
kill -s USR2 `cat $UNICORN_PIDFILE` | |
log_end_msg $? || true | |
;; | |
status) | |
status_of_proc -p $UNICORN_PIDFILE $RAILS_EXE unicorn_rails && exit 0 || exit $? | |
;; | |
*) | |
log_action_msg "Usage: /etc/init.d/unicorn {start|stop|restart|status}" || true | |
exit 1 | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment