Skip to content

Instantly share code, notes, and snippets.

@mauricio
Created February 10, 2012 14:55
Show Gist options
  • Save mauricio/1790062 to your computer and use it in GitHub Desktop.
Save mauricio/1790062 to your computer and use it in GitHub Desktop.
#! /bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME="/etc/init.d/unicorn"
USER=deployer
APP=transitoweb
GEMSET=transitoweb
PID="/home/$USER/$APP/shared/pids/unicorn.pid"
RUBY="1.9.3"
start() {
su $USER -c "/home/$USER/.rvm/bin/rvm-shell 'ruby-$RUBY@$GEMSET' -c 'cd /home/$USER/$APP/current; bundle exec unicorn_rails -c /home/$USER/$APP/current/unicorn.rb -E production -D' ";
}
case "$1" in
start)
echo -n "Starting $NAME: "
start
echo "$NAME."
;;
stop)
echo -n "Stopping $NAME: "
kill -QUIT `cat $PID`
echo "$NAME."
;;
restart)
echo -n "Restarting $NAME: "
kill -QUIT `cat $PID`
sleep 1
start
echo "$NAME."
;;
reload)
echo -n "Reloading $NAME configuration: "
kill -HUP `cat $PID`
echo "$NAME."
;;
*)
echo "Usage: $NAME {start|stop|restart|reload}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment