Skip to content

Instantly share code, notes, and snippets.

@greenboxal
Forked from justincjahn/gist:3062860
Created July 6, 2012 22:43
Show Gist options
  • Save greenboxal/3063160 to your computer and use it in GitHub Desktop.
Save greenboxal/3063160 to your computer and use it in GitHub Desktop.
Gitlab init.d for RedHat based distributions.
#!/bin/bash
#
# GitLab Runs unicorn and resque for nginx integration.
###
# chkconfig: 35 98 55
# processname: unicorn
# processname: resque
# description: Runs unicorn and resque for nginx integration.
###
# Include RedHat function library
. /etc/rc.d/init.d/functions
# The name of the service
NAME=gitlab
# The username and path to the gitlab source
USER=$NAME
APP_PATH=/home/$USER/gitlabhq
# The PID and LOCK files used by unicorn and resque
UPID=$APP_PATH/tmp/pids/unicorn.pid
ULOCK=/var/lock/subsys/unicorn
RPID=$APP_PATH/tmp/pids/resque_worker.pid
RLOCK=/var/lock/subsys/resque
# The options to use when running unicorn
OPTS="-c $APP_PATH/config/unicorn.rb -E production -D"
start() {
cd $APP_PATH
# Start unicorn
echo -n $"Starting unicorn: "
daemon --pidfile=$UPID --user=$USER "/usr/local/bin/bundle exec /usr/local/bin/unicorn_rails $OPTS"
[ $? -eq 0 ] && touch $ULOCK
echo
# Start resque
echo -n $"Starting resque: "
daemon --pidfile=$RPID --user=$USER "/usr/local/bin/bundle exec /usr/local/bin/rake environment resque:work QUEUE=post_receive,mailer RAILS_ENV=production PIDFILE=tmp/pids/resque_worker.pid BACKGROUND=y"
[ $? -eq 0 ] && touch $RLOCK
echo
}
stop() {
cd $APP_PATH
# Stop unicorn
echo -n $"Stopping unicorn: "
killproc -p $UPID
[ $? -eq 0 ] && rm -f $ULOCK
echo
# Stop resque
echo -n $"Stopping resque: "
killproc -p $RPID
[ $? -eq 0 ] && rm -f $RLOCK
echo
}
c_status() {
status -p $UPID unicorn
status -p $RPID resque
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
c_status
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|status|restart)" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment