Skip to content

Instantly share code, notes, and snippets.

@simonoff
Created December 21, 2010 19:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save simonoff/750379 to your computer and use it in GitHub Desktop.
Save simonoff/750379 to your computer and use it in GitHub Desktop.
unicorn init script
#!/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
DAEMON=/usr/local/bin/unicorn_rails
DAEMON_OPTS="-c /path/to/unicorn.conf.rb -E production -D"
NAME=unicorn_rails
DESC=unicorn_rails
PID=/path/to/unicorn.pid
OLDPID="$PID.oldbin"
sig () {
test -s "$PID" && kill -$1 `cat $PID`
}
oldsig () {
test -s $OLDPID && kill -$1 `cat $OLDPID`
}
case "$1" in
start)
echo -n "Starting $DESC: "
$DAEMON $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
sig QUIT
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
sig QUIT
sleep 1
$DAEMON $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC code: "
sig USR2
echo "$NAME."
;;
reopen-logs)
echo -n "Reopening $DESC logs: "
sig USR1
echo "$NAME."
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|reopen-logs}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment