{"action":"opened","issue":{"url":"https://api.github.com/repos/iobuild/iobuild.github.io/issues/4","labels_url":"https://api.github.com/repos/iobuild/iobuild.github.io/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/iobuild/iobuild.github.io/issues/4/comments","events_url":"https://api.github.com/repos/iobuild/iobuild.github.io/issues/4/events","html_url":"https://github.com/iobuild/iobuild.github.io/issues/4","id":85709655,"number":4,"title":"Simple unicorn script in /etc/init.d","user":{"login":"arlyxiao","id":42704,"avatar_url":"https://avatars.githubusercontent.com/u/42704?v=3","gravatar_id":"","url":"https://api.github.com/users/arlyxiao","html_url":"https://github.com/arlyxiao","followers_url":"https://api.github.com/users/arlyxiao/followers","following_url":"https://api.github.com/users/arlyxiao/following{/other_user}","gists_url":"https://api.github.com/users/arlyxiao/gists{/gist_id}","starred_url":"https://api.github.com/users/arlyxiao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arlyxiao/subscriptions","organizations_url":"https://api.github.com/users/arlyxiao/orgs","repos_url":"https://api.github.com/users/arlyxiao/repos","events_url":"https://api.github.com/users/arlyxiao/events{/privacy}","received_events_url":"https://api.github.com/users/arlyxiao/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-06T06:26:06Z","updated_at":"2015-06-06T06:26:06Z","closed_at":null,"body":"From: http://benjaminknofe.com/blog/2014/03/08/zero-downtime-deployment-with-unicorn-and-capistrano/\r\n\r\n#!/bin/sh\r\n### BEGIN INIT INFO\r\n# Provides:          unicorn\r\n# Required-Start:    $remote_fs $syslog\r\n# Required-Stop:     $remote_fs $syslog\r\n# Default-Start:     2 3 4 5\r\n# Default-Stop:      0 1 6\r\n# Short-Description: Manage unicorn server\r\n# Description:       Start, stop, restart unicorn server for a specific application.\r\n### END INIT INFO\r\nset -e\r\n\r\n# Feel free to change any of the following variables for your app:\r\nexport RUBY_GC_HEAP_MIN_SLOTS=800000\r\nexport RUBY_GC_HEAP_SLOTS_INCREMENT=250000\r\nexport RUBY_GC_HEAP_SLOTS_GROWTH_FACTOR=1\r\nexport RUBY_GC_MALLOC_LIMIT=50000000\r\n\r\nTIMEOUT=${TIMEOUT-60}\r\nAPP_ROOT=/home/deployer/current\r\nPID=$APP_ROOT/tmp/pids/unicorn.pid\r\nCMD=\"cd $APP_ROOT && BUNDLE_GEMFILE=$APP_ROOT/Gemfile bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production\"\r\nAS_USER=deployer\r\nset -u\r\n\r\nOLD_PIN=\"$PID.oldbin\"\r\n\r\nsig () {\r\n  test -s \"$PID\" && kill -s $1 `cat $PID`\r\n}\r\n\r\nrun () {\r\n  if [ \"$(id -un)\" = \"$AS_USER\" ]; then\r\n    eval $1\r\n  else\r\n    su -c \"$1\" - $AS_USER\r\n  fi\r\n}\r\n\r\ncase \"$1\" in\r\nstart)\r\n  sig 0 && echo >&2 \"Already running\" && exit 0\r\n  run \"$CMD\"\r\n  ;;\r\nstop)\r\n  sig QUIT && exit 0\r\n  echo >&2 \"Not running\"\r\n  ;;\r\nforce-stop)\r\n  sig TERM && exit 0\r\n  echo >&2 \"Not running\"\r\n  ;;\r\nrestart|reload)\r\n  sig HUP && echo reloaded OK && exit 0\r\n  echo >&2 \"Couldn't reload, starting '$CMD' instead\"\r\n  run \"$CMD\"\r\n  ;;\r\nupgrade)\r\n  if sig USR2 && sleep 3\r\n  then\r\n    n=$TIMEOUT\r\n    while test -s $OLD_PIN && test $n -ge 0\r\n    do\r\n      printf '.' && sleep 1 && n=$(( $n - 1 ))\r\n    done\r\n    echo\r\n\r\n    if test $n -lt 0 && test -s $OLD_PIN\r\n    then\r\n      echo >&2 \"$OLD_PIN still exists after $TIMEOUT seconds\"\r\n      exit 1\r\n    fi\r\n    exit 0\r\n  fi\r\n  echo >&2 \"Couldn't upgrade, starting '$CMD' instead\"\r\n  run \"$CMD\"\r\n  ;;\r\nreopen-logs)\r\n  sig USR1\r\n  ;;\r\n*)\r\n  echo >&2 \"Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>\"\r\n  exit 1\r\n  ;;\r\nesac\r\n"}}