Skip to content

Instantly share code, notes, and snippets.

@mauricio
Created July 30, 2012 20:49
Show Gist options
  • Select an option

  • Save mauricio/3210059 to your computer and use it in GitHub Desktop.

Select an option

Save mauricio/3210059 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"
PID=/home/deployer/clipit/shared/pids/unicorn.pid
start() {
su deployer -c "/home/deployer/.rvm/bin/rvm-shell 'ruby-1.9.2@clipagens' -c 'cd /home/deployer/clipit/current; bundle exec unicorn_rails -c /home/deployer/clipit/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
@mauricio
Copy link
Author

Yes, it's currently running in a production server at this moment. If you're sending more parameters, make sure they are correctly quoted.

@poori
Copy link

poori commented Jul 31, 2012

cool thanks. btw I've been using your tutorial to get my hands wet with unicorn. Thanks for the awesome tutorial.

The only part I ended up getting hung up on was the item above. I wanted to avoid sudo as much as possible so I modified the cap deploy scripts to use 'run' instead of 'sudo' but when I rebooted the server, the init.d/unicorn script started up as root and I could no longer use the cap deploy scripts.

I have a slightly different init script now so I ended up having to wrap the unicorn init.d script in a separate file with this one liner

su deploy -c -- "/etc/init.d/unicorn $1"

(just an fyi for other people who might run into this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment