Skip to content

Instantly share code, notes, and snippets.

@pjammer
Created February 9, 2012 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pjammer/1780624 to your computer and use it in GitHub Desktop.
Save pjammer/1780624 to your computer and use it in GitHub Desktop.
i put this into /usr/local/bin/eunic and you can your server using eunic -s && eunic -N
#!/bin/bash
set -u
set -e
#change this below to your actual path. If you another environemnt like staging, fucking change N to -e staging instead.
APP_PATH=/youpath/to/app/root
PID=$APP_PATH/tmp/pids/unicorn.pid
OLD_PID=$APP_PATH/tmp/pids/unicorn.pid.oldbin
UNICORN_COMMAND="unicorn_rails -c $APP_PATH/config/unicorn.rb -D"
while getopts ":nsNr" opt; do
case $opt in
N)
echo "Starting Unicorn in Production"
unicorn_rails -E production -c $APP_PATH/config/unicorn.rb -D
;;
n)
echo "Starting Unicorn in Development"
$UNICORN_COMMAND
;;
s)
echo "Stopping Unicorn"
kill -15 `cat $PID`
;;
r)
echo "Reloading Unicorn if USR2 is enabled"
kill -USR2 `cat $PID`
if [ -s $OLD_PID ]
then
kill -WINCH `cat $OLD_PID` && kill -QUIT `cat $OLD_PID`
fi
;;
?)
echo "Usage: -n [start dev mode] | -N [ start Production mode] | -r [restart/reload] | -s [stop unicorn]"
exit 1
;;
esac
done
@pjammer
Copy link
Author

pjammer commented Feb 9, 2012

i hope those are comments in bash too, but make sure you chmod +x /usr/local/bin/eunic after you create this file on your server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment