Created
July 30, 2012 20:49
-
-
Save mauricio/3210059 to your computer and use it in GitHub Desktop.
This file contains hidden or 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: $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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)