Created
October 13, 2011 07:06
-
-
Save rchampourlier/1283619 to your computer and use it in GitHub Desktop.
Template for startup script to launch unicorn instance for a given rails app. To be used with our Capistrano deployment recipe
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/bash | |
# | |
# <%= "#{application}" %> <%= "#{application}" %> Rails application served through an Unicorn instance | |
# | |
# Author Romain Champourlier @ softr.li | |
# | |
# chkconfig: - <%= "#{unicorn_startorder} #{unicorn_killorder}" %> | |
# | |
# description: This a web application developed in Ruby On Rails | |
# which is served through an Unicorn instance. | |
# processname: unicorn_rails | |
# config: <%= "#{deploy_to}/shared/configs/unicorn.rb" %> | |
# pidfile: <%= "#{deploy_to}/shared/pids/unicorn.pid" %> | |
# | |
### BEGIN INIT INFO | |
# Provides: <%= "#{application}" %> | |
# Required-Start: $local_fs $remote_fs $network $syslog | |
# Required-Stop: $local_fs $remote_fs $network $syslog | |
# Default-Start: <%= "#{unicorn_runlevels}" %> | |
# Default-Stop: <%= "#{unicorn_stoplevels}" %> | |
# Short-Description: starts unicorn for <%= "#{application}" %> | |
# Description: starts unicorn web server for <%= "#{application}" %> Rails app | |
### END INIT INFO | |
CMD='cd <%= "#{current_path}" %> && bundle exec <%= "#{unicorn_binary}" %> -c <%= "#{unicorn_config}" %> -E <%= "#{rails_env}" %> -D' | |
NAME=unicorn_rails | |
DESC=unicorn_rails | |
PID=<%= "#{deploy_to}/shared/pids/unicorn.pid" %> | |
case "$1" in | |
start) | |
echo -n "Starting $DESC: " | |
su - <%= "#{user}" %> -c "$CMD" | |
echo "$NAME." | |
;; | |
stop) | |
echo -n "Stopping $DESC: " | |
kill -QUIT `cat $PID` | |
echo "$NAME." | |
;; | |
restart) | |
echo -n "Restarting $DESC: " | |
kill -QUIT `cat $PID` | |
sleep 1 | |
su - <%= "#{user}" %> -c $CMD | |
echo "$NAME." | |
;; | |
reload) | |
echo -n "Reloading $DESC 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