Skip to content

Instantly share code, notes, and snippets.

@filterfish
Created June 25, 2012 02:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filterfish/2986142 to your computer and use it in GitHub Desktop.
Save filterfish/2986142 to your computer and use it in GitHub Desktop.
Debian Unicorn startup script.

A Debian (or any Debian derivative) start up script for unicorn. You will to change: the name of the /etc/{default,init.d}/unicorn to reflect the name of the application; the lines that check and then source /etc/default/unicorn (lines 5 & 6) and the INIT INFO line: "Provides" & "Short-Description" lines (8 & 13). There should be no reason to change anything anything else in /etc/init.d/unicorn.

h2.Bundler

You might find that bundler just works (unlikely) or (more likely) you will have to fuck around until it does. So if it doesn't work the following:

  • add ruby_path=/bin to /etc/defaults/unicorn
  • sed 's/^DAEMON=.*$/DAEMON=$ruby_path/bundle exec unicorn"

probably will.

Dear the Ruby community, please, pretty fucking please, ditch bundler it's a fucking up piece of shite.

# Application specific config for unicorn
# This file: /etc/default/unicorn
root=<application root path>
pid=$app_root/tmp/pids/unicorn.pid
env=production
user=<application user>
long_name="<long application name>"
name=<application name>
options="--daemonize --env $env --config $root/config/unicorn.rb"
# vim: ft=sh
#!/bin/sh -e
# This file: /etc/init.d/unicorn
if [ -f /netc/default/unicorn ]; then
. /etc/default/unicorn
fi
### BEGIN INIT INFO
# Provides: <application name>
# Required-Start: $local_fs $network $time postgresql
# Required-Stop: $local_fs $network $time postgresql
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: <application description>
### END INIT INFO
cd $root || exit 1
. /lib/lsb/init-functions
DEAMON="/usr/bin/unicorn"
case $1 in
start)
log_daemon_msg "Starting $long_name" "$name"
start-stop-daemon --start --quiet --chdir $root --chuid $user --oknodo --pidfile $pid --exec $DEAMON -- $options
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping $long_name" "$name"
start-stop-daemon --stop --quiet --chdir $root --chuid $user --oknodo --pidfile $pid
log_end_msg $?
;;
restart)
log_daemon_msg "Restarting $long_name" "$name"
start-stop-daemon --stop --quiet --chdir $root --chuid $user --oknodo --retry 30 --pidfile $pid
start-stop-daemon --start --quiet --chdir $root --chuid $user --oknodo --pidfile $pid --exec $DEAMON -- $options
log_end_msg $?
;;
reload)
log_daemon_msg "Reloading $long_name" "$name"
start-stop-daemon --stop --quiet --chdir $root --chuid $user --oknodo --signal USR2 --pidfile $pid
log_end_msg $?
;;
*)
log_action_msg "Usage: /etc/init.d/$name {start|stop|restart|reload}"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment