Sha256: d8c03b3547fff055b6b8b04c1fc0db53c4e89f9058cf076e9a108747a1731d9a

Contents?: true

Size: 1.84 KB

Versions: 9

Compression:

Stored size: 1.84 KB

Contents

<%
  @path = "/etc/init.d/unicorn"
  @perms = 0755
  current_path = "/mnt/#{rubber_env.app_name}-#{Rubber.env}/current"
%>

#!/bin/sh
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:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=<%= current_path %>
PID=/var/run/unicorn.pid
CMD="<%= "bundle exec unicorn_rails -c #{current_path}/config/unicorn.rb -E #{Rubber.env} -D" %>"
action="$1"
set -u

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 $action in
start)
  sig 0 && echo >&2 "Already running" && exit 0
  $CMD
  ;;
stop)
  sig QUIT && exit 0
  echo >&2 "Not running"
  ;;
force-stop)
  sig TERM && exit 0
  echo >&2 "Not running"
  ;;
restart|reload)
  sig HUP && echo reloaded OK && exit 0
  echo >&2 "Couldn't reload, starting '$CMD' instead"
  $CMD
  ;;
upgrade)
  if sig USR2
  then
    printf 'Waiting for new workers'
    n=$TIMEOUT
    while (! (test -s $PID && ps --no-headers --ppid `cat $PID` > /dev/null)) && test $n -ge 0
    do
      printf '.' && sleep 1 && n=$(( $n - 1 ))
    done
    if test ! -s $old_pid
    then
      echo
      echo >&2 'New workers failed to start; see error log'
      exit 1
    fi
    printf '\nStopping old master' && oldsig QUIT

    n=$TIMEOUT
    while test -s $old_pid && test $n -ge 0
    do
      printf '.' && sleep 1 && n=$(( $n - 1 ))
    done
    echo

    if test $n -lt 0 && test -s $old_pid
    then
      echo >&2 "$old_pid still exists after $TIMEOUT seconds"
      exit 1
    fi
    exit 0
  fi
  echo >&2 "Couldn't upgrade, starting '$CMD' instead"
  $CMD
  ;;
reopen-logs)
  sig USR1
  ;;
*)
  echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
  exit 1
  ;;
esac

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubber-2.9.0 templates/unicorn/config/rubber/role/unicorn/unicorn
rubber-2.8.1 templates/unicorn/config/rubber/role/unicorn/unicorn
rubber-2.8.0 templates/unicorn/config/rubber/role/unicorn/unicorn
rubber-2.7.5 templates/unicorn/config/rubber/role/unicorn/unicorn
rubber-2.7.4 templates/unicorn/config/rubber/role/unicorn/unicorn
rubber-2.7.3 templates/unicorn/config/rubber/role/unicorn/unicorn
rubber-2.7.2 templates/unicorn/config/rubber/role/unicorn/unicorn
rubber-2.7.1 templates/unicorn/config/rubber/role/unicorn/unicorn
rubber-2.7.0 templates/unicorn/config/rubber/role/unicorn/unicorn