#!/bin/sh # # gitlab-unicorn gitlab-unicorn short service description # # chkconfig: 345 82 18 # description: Runs unicorn # processname: sidekiq # # Related (kudos @4sak3n0ne): # https://github.com/gitlabhq/gitlabhq/issues/1049#issuecomment-8386882 # https://gist.github.com/3062860 # Source function library . /etc/rc.d/init.d/functions # Get network config . /etc/sysconfig/network # Check that networking is up. if is_yes "${NETWORKING}"; then if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then msg_network_down "GitLab Unicorn" exit 1 fi else exit 0 fi ### Environment variables RAILS_ENV="production" # The username and path to the gitlab source USER=git APP_PATH=/var/lib/gitlab # The PID and LOCK files used by unicorn and sidekiq pidfile=$APP_PATH/pids/unicorn.pid lockfile=/var/lock/subsys/gitlab-unicorn # Get service config - may override defaults [ -f /etc/sysconfig/gitlab-unicorn ] && . /etc/sysconfig/gitlab-unicorn start() { # Check if the service is already running? if [ -f $lockfile ]; then msg_already_running "GitLab Unicorn" return fi msg_starting "GitLab Unicorn" daemon --pidfile $pidfile --user $USER --chdir "$APP_PATH" \ "env RAILS_ENV=$RAILS_ENV bin/web start" RETVAL=$? [ $RETVAL -eq 0 ] && touch $lockfile } stop() { if [ ! -f $lockfile ]; then msg_not_running "GitLab Unicorn" return fi # Stop daemons. msg_stopping "GitLab Unicorn" killproc --pidfile $pidfile unicorn rm -f $lockfile } condrestart() { if [ ! -f $lockfile ]; then msg_not_running "GitLab Unicorn" RETVAL=$1 return fi stop start } RETVAL=0 # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) stop start ;; try-restart) condrestart 0 ;; force-reload) condrestart 7 ;; status) status --pidfile $pidfile unicorn_rails RETVAL=$? ;; *) msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}" exit 3 esac exit $RETVAL