Skip to content

Instantly share code, notes, and snippets.

@tomkersten
Created February 23, 2011 05:40
Show Gist options
  • Select an option

  • Save tomkersten/840074 to your computer and use it in GitHub Desktop.

Select an option

Save tomkersten/840074 to your computer and use it in GitHub Desktop.
/etc/init.d/unicorn_example1.com file used for restarting the herd associated w/ the example1.com application
# Mostly yanked from:
# http://bit.ly/nginx-unicorn-setup
upstream example1-herd {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
server unix:/tmp/example1.com.socket fail_timeout=0;
}
server {
listen 80;
server_name example1.com;
root /home/example1.com/website/public;
access_log /var/log/nginx/example1.com-access.log;
error_log /var/log/nginx/example1.com-error.log;
rewrite_log on;
include proxy.include;
proxy_redirect off;
location / {
try_files $uri/index.html $uri.html $uri @example1_herd;
}
location ~ ^/(images|javascripts|stylesheets|system)/ {
root /home/example1.com/website/public;
try_files $uri $uri/;
expires max;
break;
}
location @example1_herd {
proxy_pass http://example1-herd;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
}
#! /bin/bash
### 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
USER=example1.com
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=unicorn
DAEMON_OPTS="-c /home/$USER/website/config/unicorn.rb -E production -D"
NAME=unicorn
DESC="Unicorn app for $USER"
PID=/home/$USER/website/tmp/pids/unicorn.pid
case "$1" in
start)
INIT_RVM="source /usr/local/lib/rvm"
CD_TO_APP_DIR="cd /home/$USER/website"
START_DAEMON_PROCESS="bundle exec $DAEMON $DAEMON_OPTS"
echo -n "Starting $DESC: "
if [ `whoami` = root ]; then
su - $USER -c "$INIT_RVM && $CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS"
else
$INIT_RVM && $CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS
fi
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
kill -QUIT `cat $PID`
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
kill -USR2 `cat $PID`
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
kill -HUP `cat $PID`
echo "$NAME."
;;
*)
echo "Usage: $NAME {start|stop|restart|reload}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment