Created
April 4, 2011 20:57
Revisions
-
troex revised this gist
Aug 9, 2012 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ # ## RAILS_ENV=production ## RAILS_ROOT=/var/apps/www/my_app/current ## PID=$RAILS_ROOT/tmp/pids/unicorn.pid ## START_CMD="bundle exec unicorn_rails" ## USER="www-data" ## RESTART_SLEEP=5 @@ -27,8 +27,8 @@ ## APP_ROOT = ENV["RAILS_ROOT"] ## RAILS_ENV = ENV["RAILS_ENV"] ## ## pid "#{APP_ROOT}/tmp/pids/unicorn.pid" ## listen "#{APP_ROOT}/tmp/sockets/unicorn.sock" ## stderr_path "#{APP_ROOT}/log/unicorn_error.log" ## ## working_directory "#{APP_ROOT}" @@ -125,7 +125,7 @@ handle_delayed_job () { case $1 in start|stop|restart|reload|status) CMD="env RAILS_ENV=$RAILS_ENV bundle exec ./script/delayed_job $1" if [ "$USER" != `whoami` ]; then CMD="sudo -u $USER -- env $CMD" fi -
troex revised this gist
Aug 9, 2012 . 1 changed file with 67 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -9,15 +9,30 @@ # Description: Unicorn is an HTTP server for Rack application ### END INIT INFO # Author: Troex Nevelin <troex@fury.scancode.ru> # based on http://gist.github.com/308216 by http://github.com/mguterl # A sample /etc/unicorn/my_app.conf, only RAILS_ROOT is required, other are optional # ## RAILS_ENV=production ## RAILS_ROOT=/var/apps/www/my_app/current ## PID=$RAILS_ROOT/tmp/unicorn.pid ## START_CMD="bundle exec unicorn_rails" ## USER="www-data" ## RESTART_SLEEP=5 ## HANDLE_DELAYED_JOB=true # A recommended /etc/unicorn/my_app.unicorn.rb # ## APP_ROOT = ENV["RAILS_ROOT"] ## RAILS_ENV = ENV["RAILS_ENV"] ## ## pid "#{APP_ROOT}/tmp/unicorn.pid" ## listen "#{APP_ROOT}/tmp/unicorn.sock" ## stderr_path "#{APP_ROOT}/log/unicorn_error.log" ## ## working_directory "#{APP_ROOT}" ## worker_processes 1 set -e @@ -30,12 +45,11 @@ oldsig () { } cmd () { case $1 in start) sig 0 && echo >&2 "Already running" && return echo "Starting" $CMD ;; stop) sig QUIT && echo "Stopping" && return @@ -46,7 +60,7 @@ cmd () { echo >&2 "Not running" ;; restart|reload) sig USR2 && sleep $RESTART_SLEEP && oldsig QUIT && echo "Killing old master" `cat $OLD_PID` && return echo >&2 "Couldn't reload, starting '$CMD' instead" $CMD ;; @@ -64,7 +78,7 @@ cmd () { echo >&2 "Not running" && return ;; *) echo >&2 "Usage: $0 <start|stop|restart|reload|status|upgrade|rotate|force-stop>" return ;; esac @@ -74,13 +88,22 @@ setup () { echo -n "$RAILS_ROOT: " cd $RAILS_ROOT || exit 1 if [ -z "$RAILS_ENV" ]; then RAILS_ENV=development fi if [ -z "$PID" ]; then PID=$RAILS_ROOT/tmp/pids/unicorn.pid fi if [ -z "$RESTART_SLEEP" ]; then RESTART_SLEEP=5 fi export PID export OLD_PID="$PID.oldbin" export RAILS_ROOT export RESTART_SLEEP if [ -z "$START_CMD" ]; then START_CMD="bundle exec unicorn_rails" @@ -94,18 +117,39 @@ setup () { #echo $CMD } handle_delayed_job () { # $1 contains command if [ "$HANDLE_DELAYED_JOB" != "true" ]; then return fi case $1 in start|stop|restart|reload|status) CMD="RAILS_ENV=$RAILS_ENV bundle exec ./script/delayed_job $1" if [ "$USER" != `whoami` ]; then CMD="sudo -u $USER -- env $CMD" fi $CMD ;; esac } start_stop () { # either run the start/stop/reload/etc command for every config under /etc/unicorn # or just do it for a specific one # $1 contains the start/stop/etc command # $2 if it exists, should be the specific config we want to act on if [ -n "$2" ]; then if [ -f "/etc/unicorn/$2.conf" ]; then . /etc/unicorn/$2.conf export UNICORN_CONFIG="/etc/unicorn/$2.unicorn.rb" setup cmd $1 handle_delayed_job $1 else echo >&2 "/etc/unicorn/$2.conf: not found" fi else for CONFIG in /etc/unicorn/*.conf; do # import the variables @@ -115,7 +159,17 @@ start_stop () { # run the start/stop/etc command cmd $1 handle_delayed_job $1 # clean enviroment unset PID unset OLD_PID unset RAILS_ROOT unset RAILS_ENV unset CMD unset USER unset START_CMD unset UNICORN_CONFIG done fi } -
troex revised this gist
Feb 16, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -88,7 +88,7 @@ setup () { CMD="$START_CMD -c $UNICORN_CONFIG -E $RAILS_ENV -D" if [ "$USER" != `whoami` ]; then CMD="sudo -u $USER -- env RAILS_ROOT=$RAILS_ROOT $CMD" fi export CMD #echo $CMD -
troex revised this gist
Dec 1, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
Empty file. -
troex revised this gist
Dec 1, 2011 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ #!/bin/sh ### BEGIN INIT INFO # Provides: unicorn # Required-Start: $local_fs $remote_fs mysql # Required-Stop: $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: unicorn initscript # Description: Unicorn is an HTTP server for Rack application ### END INIT INFO # based on http://gist.github.com/308216 by http://github.com/mguterl @@ -15,6 +15,9 @@ ## ## RAILS_ENV=production ## RAILS_ROOT=/var/apps/www/my_app/current ## PID=$RAILS_ROOT/tmp/unicorn.pid ## START_CMD="bundle exec unicorn" ## USER="www-data" set -e -
troex revised this gist
Dec 1, 2011 . 1 changed file with 27 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ #!/bin/sh ### BEGIN INIT INFO # Provides: thin # Required-Start: $local_fs $remote_fs mysql # Required-Stop: $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 @@ -30,56 +30,65 @@ cmd () { case $1 in start) sig 0 && echo >&2 "Already running" && return echo "Starting" `$CMD` ;; stop) sig QUIT && echo "Stopping" && return echo >&2 "Not running" ;; force-stop) sig TERM && echo "Forcing a stop" && return echo >&2 "Not running" ;; restart|reload) sig USR2 && sleep 5 && oldsig QUIT && echo "Killing old master" `cat $OLD_PID` && return echo >&2 "Couldn't reload, starting '$CMD' instead" $CMD ;; upgrade) sig USR2 && echo Upgraded && return echo >&2 "Couldn't upgrade, starting '$CMD' instead" $CMD ;; rotate) sig USR1 && echo rotated logs OK && return echo >&2 "Couldn't rotate logs" && return ;; status) sig 0 && echo >&2 "Already running" && return echo >&2 "Not running" && return ;; *) echo >&2 "Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>" return ;; esac } setup () { echo -n "$RAILS_ROOT: " cd $RAILS_ROOT || exit 1 if [ -z "$PID" ]; then PID=$RAILS_ROOT/tmp/pids/unicorn.pid fi export PID export OLD_PID="$PID.oldbin" export RAILS_ROOT if [ -z "$START_CMD" ]; then START_CMD="bundle exec unicorn_rails" fi CMD="$START_CMD -c $UNICORN_CONFIG -E $RAILS_ENV -D" if [ "$USER" != `whoami` ]; then CMD="sudo -u $USER -- $CMD" fi export CMD #echo $CMD } start_stop () { @@ -103,6 +112,7 @@ start_stop () { # run the start/stop/etc command cmd $1 unset PID done fi } -
troex revised this gist
Nov 30, 2011 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -73,8 +73,13 @@ setup () { export OLD_PID="$PID.oldbin" export RAILS_ROOT if [ -z $START_CMD ]; then START_CMD="bundle exec unicorn_rails" fi CMD="$START_CMD -c $UNICORN_CONFIG -E $RAILS_ENV -D" echo $CMD exit } start_stop () { -
troex revised this gist
Sep 2, 2011 . 1 changed file with 88 additions and 58 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,76 +1,106 @@ #!/bin/sh ### BEGIN INIT INFO # Provides: thin # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: thin initscript # Description: thin ### END INIT INFO # based on http://gist.github.com/308216 by http://github.com/mguterl # ## A sample /etc/unicorn/my_app.conf ## ## RAILS_ENV=production ## RAILS_ROOT=/var/apps/www/my_app/current set -e sig () { test -s "$PID" && kill -$1 `cat "$PID"` } oldsig () { test -s "$OLD_PID" && kill -$1 `cat "$OLD_PID"` } cmd () { case $1 in start) sig 0 && echo >&2 "Already running" && exit 0 echo "Starting" $CMD ;; stop) sig QUIT && echo "Stopping" && exit 0 echo >&2 "Not running" ;; force-stop) sig TERM && echo "Forcing a stop" && exit 0 echo >&2 "Not running" ;; restart|reload) sig USR2 && sleep 5 && oldsig QUIT && echo "Killing old master" `cat $OLD_PID` && exit 0 echo >&2 "Couldn't reload, starting '$CMD' instead" $CMD ;; upgrade) sig USR2 && echo Upgraded && exit 0 echo >&2 "Couldn't upgrade, starting '$CMD' instead" $CMD ;; rotate) sig USR1 && echo rotated logs OK && exit 0 echo >&2 "Couldn't rotate logs" && exit 1 ;; *) echo >&2 "Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>" exit 1 ;; esac } setup () { echo -n "$RAILS_ROOT: " cd $RAILS_ROOT || exit 1 if [ -z $PID ]; then PID=$RAILS_ROOT/tmp/pids/unicorn.pid fi export PID export OLD_PID="$PID.oldbin" export RAILS_ROOT CMD="bundle exec unicorn_rails -c $UNICORN_CONFIG -E $RAILS_ENV -D" #echo $CMD } start_stop () { # either run the start/stop/reload/etc command for every config under /etc/unicorn # or just do it for a specific one # $1 contains the start/stop/etc command # $2 if it exists, should be the specific config we want to act on if [ -f "/etc/unicorn/$2.conf" ]; then . /etc/unicorn/$2.conf export UNICORN_CONFIG="/etc/unicorn/$2.unicorn.rb" setup cmd $1 else for CONFIG in /etc/unicorn/*.conf; do # import the variables export UNICORN_CONFIG=`echo ${CONFIG} | sed 's/conf/unicorn.rb/'` . $CONFIG setup # run the start/stop/etc command cmd $1 done fi } ARGS="$1 $2" start_stop $ARGS -
troex revised this gist
Apr 4, 2011 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,12 +4,12 @@ # Provides: unicorn-kk # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Should-Start: mysql # Should-Stop: mysql # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: unicorn # Description: unicorn ### END INIT INFO -
troex created this gist
Apr 4, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,76 @@ #!/bin/sh ### BEGIN INIT INFO # Provides: unicorn-kk # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Should-Start: mysql memcached sphinx-kk # Should-Stop: mysql memcached sphinx-kk # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: unicorn kk # Description: unicorn kk ### END INIT INFO set -u set -e # Example init script, this can be used with nginx, too, # since nginx and unicorn accept the same signals # Feel free to change any of the following variables for your app: APP_ROOT=/var/www/app/current PID=/var/www/app/shared/pids/unicorn.pid ENV=production CMD="/usr/bin/unicorn_rails -D -E $ENV -c config/unicorn.rb" old_pid="$PID.oldbin" cd $APP_ROOT || exit 1 sig () { test -s "$PID" && kill -$1 `cat $PID` } oldsig () { test -s $old_pid && kill -$1 `cat $old_pid` } case $1 in start) sig 0 && echo >&2 "Already running" && exit 0 $CMD echo >&2 "Started" ;; stop) sig QUIT && exit 0 echo >&2 "Not running" ;; force-stop) sig TERM && exit 0 echo >&2 "Not running" ;; reload) sig HUP && echo reloaded OK && exit 0 echo >&2 "Couldn't reload" #$CMD ;; restart) sig USR2 echo >&2 "Starting new master, waiting 10 sec..." sleep 10 echo -n >&2 "Quiting old master... " oldsig QUIT echo >&2 "done" #echo >&2 "Couldn't upgrade, starting '$CMD' instead" #$CMD ;; rotate) sig USR1 && echo rotated logs OK && exit 0 echo >&2 "Couldn't rotate logs" && exit 1 ;; *) echo >&2 "Usage: $0 <start|stop|reload|restart|rotate|force-stop>" exit 1 ;; esac