Skip to content

Instantly share code, notes, and snippets.

@turhn
Created January 12, 2015 23:49
Show Gist options
  • Save turhn/561e2dbf405c614f99c1 to your computer and use it in GitHub Desktop.
Save turhn/561e2dbf405c614f99c1 to your computer and use it in GitHub Desktop.
root@vagrant-ubuntu-trusty-64:~# sh -x /etc/init.d/unicorn start
+ set -e
+ USAGE=Usage: /etc/init.d/unicorn <start|stop|restart|upgrade|rotate|force-stop>
+ USER=vagrant
+ APP_NAME=safir
+ APP_ROOT=/vagrant
+ RAILS_ENV=production
+ export RBENV_ROOT=/home/vagrant/.rbenv
+ export PATH=/home/vagrant/.rbenv/bin:/home/vagrant/.rbenv/shims:/home/vagrant/.rbenv/bin:/home/vagrant/.rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ SET_RUBY=cd /vagrant && rbenv rehash && rbenv local 2.2.0
+ CMD=cd /vagrant && rbenv rehash && rbenv local 2.2.0;bundle exec unicorn -c config/unicorn.rb -E production -D
+ PID=/vagrant/tmp/pids/unicorn.pid
+ OLD_PID=/vagrant/tmp/pids/unicorn.pid.oldbin
+ cd /vagrant
+ sig 0
+ test -s /vagrant/tmp/pids/unicorn.pid
+ echo Starting safir
Starting safir
+ su - vagrant -c echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn app server
# Description: starts unicorn using start-stop-daemon
### END INIT INFO
set -e
USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"
# app settings
USER="vagrant"
APP_NAME="safir"
APP_ROOT="/vagrant"
RAILS_ENV="production"
export RBENV_ROOT="/home/$USER/.rbenv"
# environment settings
export PATH=$RBENV_ROOT/bin:$RBENV_ROOT/shims:$PATH
SET_RUBY="cd $APP_ROOT && rbenv rehash && rbenv local 2.2.0"
CMD="$SET_RUBY;bundle exec unicorn -c config/unicorn.rb -E $RAILS_ENV -D"
PID="$APP_ROOT/tmp/pids/unicorn.pid"
OLD_PID="$PID.oldbin"
# make sure the app exists
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
echo "Starting $APP_NAME"
su - $USER -c 'echo $PATH'
#su - $USER -c "PATH=$PATH; $CMD"
;;
stop)
echo "Stopping $APP_NAME"
sig QUIT && exit 0
echo >&2 "Not running"
;;
force-stop)
echo "Force stopping $APP_NAME"
sig TERM && exit 0
echo >&2 "Not running"
;;
restart|reload|upgrade)
sig USR2 && echo "reloaded $APP_NAME" && exit 0
echo >&2 "Couldn't reload, starting '$CMD' instead"
$CMD
;;
rotate)
sig USR1 && echo rotated logs OK && exit 0
echo >&2 "Couldn't rotate logs" && exit 1
;;
status)
sig 0 && echo >&2 "Already running" && return
echo >&2 "Not running" && return
;;
*)
echo >&2 $USAGE
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment