Skip to content

Instantly share code, notes, and snippets.

@cheynewallace
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheynewallace/7be7093e36836bfcc08c to your computer and use it in GitHub Desktop.
Save cheynewallace/7be7093e36836bfcc08c to your computer and use it in GitHub Desktop.
Run Rails Unicorn Server As Ubuntu Service
# Add this line to your web app users crontab to start unicorn after reboot
@reboot service unicorn start
#!/bin/bash
# Drop this file into /etc/init.d on Ubuntu
# Stop, Start and Restart unicorn like a normal service
# Usage: service unicorn stop|start|restart
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
APP_PATH=/home/deploy/app/current # Change this to your app path
NAME=unicorn
DESC="Unicorn Rails"
PID=/tmp/unicorn.pid
case "$1" in
start)
echo -n "Starting $DESC: "
source /usr/local/rvm/scripts/rvm && cd $APP_PATH && unicorn_rails -c $APP_PATH/config/unicorn.rb -D -E production
;;
stop)
echo -n "Stopping $DESC: "
kill -QUIT `cat $PID`
;;
restart)
echo -n "Restarting $DESC: "
kill -QUIT `cat $PID`
sleep 1
source /usr/local/rvm/scripts/rvm && cd $APP_PATH && unicorn_rails -c $APP_PATH/config/unicorn.rb -D -E production
;;
*)
echo "Usage: $NAME {start|stop|restart}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment