Sha256: fdd4ed1a28ab1c52cb8f52d8364a09f56b9b0eb7539a5619a69e9144aed26585

Contents?: true

Size: 1.44 KB

Versions: 15

Compression:

Stored size: 1.44 KB

Contents

#!/bin/sh

set -u

TIMEOUT=${TIMEOUT-60}
RBENV_ROOT="{{ rbenv_root }}"
PATH="$RBENV_ROOT/bin:$RBENV_ROOT/shims:$PATH"
APP_ROOT="{{be_app_path}}"
APP_USER="{{ deployer_user.name }}"
PID="$APP_ROOT/tmp/unicorn.pid"
CMD="$APP_ROOT/bin/unicorn -E {{be_app_env}} -D -c $APP_ROOT/config/unicorn.rb"

action="$1"
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
  rm -f $PID && $CMD
  ;;
stop)
  sig QUIT && echo "Stopping" && exit 0
  echo >&2 "Unicorn master process with ID `cat $PID` not found (see: $PID)"
  ;;
force-stop)
  pkill -9 -f "unicorn master" && echo "Forcing a stop\n" && rm -f $PID && echo "Cleaning up pid" && exit 0
  ;;
restart|reload)
  sig HUP && echo reloaded OK && exit 0
  echo >&2 "Couldn't reload, starting '$CMD' instead"
  $CMD
  ;;
upgrade)
  if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
  then
    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

15 entries across 15 versions & 1 rubygems

Version Path
taperole-1.2.6 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.2.5 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.2.4 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.2.3 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.2.2 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.2.1 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.2.0 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.1.5 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.1.4 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.1.3 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.1.2 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.1.1 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.1.0 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.0.1 roles/unicorn_install/templates/unicorn_init.j2
taperole-1.0.0 roles/unicorn_install/templates/unicorn_init.j2