Last active
August 29, 2015 14:06
-
-
Save cheynewallace/7be7093e36836bfcc08c to your computer and use it in GitHub Desktop.
Run Rails Unicorn Server As Ubuntu Service
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
# Add this line to your web app users crontab to start unicorn after reboot | |
@reboot service unicorn start |
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 | |
# 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