Files
gitlab-recipes/init.d/gitlab-centos
Vanja Radovanović 1528537f32 usage fix
2012-12-27 14:53:49 +01:00

117 lines
2.1 KiB
Bash

#!/bin/bash
#
# GitLab
# Maintainer: @elvanja, @troyanov
# App Version: 4.0
# chkconfig: 2345 82 55
# processname: unicorn
# processname: rescue
# description: Runs unicorn and resque for nginx integration.
# Related (kudos @4sak3n0ne):
# https://github.com/gitlabhq/gitlabhq/issues/1049#issuecomment-8386882
# https://gist.github.com/3062860
# 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/gitlab
# 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"
# Ruby related path update
RUBY_PATH_PATCH="PATH=$PATH:/usr/local/bin:/usr/local/lib && export PATH && "
start() {
cd $APP_PATH
# Start unicorn
echo -n $"Starting unicorn: "
daemon --pidfile=$UPID --user=$USER "$RUBY_PATH_PATCH bundle exec unicorn_rails $OPTS"
unicorn=$?
[ $unicorn -eq 0 ] && touch $ULOCK
echo
# Start resque
echo -n $"Starting resque: "
daemon --pidfile=$RPID --user=$USER "$RUBY_PATH_PATCH ./resque.sh"
resque=$?
[ $resque -eq 0 ] && touch $RLOCK
echo
retval=$unicorn || $resque
return $retval
}
stop() {
cd $APP_PATH
# Stop unicorn
echo -n $"Stopping unicorn: "
killproc -p $UPID
unicorn=$?
[ $unicorn -eq 0 ] && rm -f $ULOCK
echo
# Stop resque
echo -n $"Stopping resque: "
killproc -p $RPID
resque=$?
[ $resque -eq 0 ] && rm -f $RLOCK
echo
retval=$unicorn || $resque
return $retval
}
restart() {
stop
start
}
get_status() {
status -p $UPID unicorn
status -p $RPID resque
}
query_status() {
get_status >/dev/null 2>&1
}
case "$1" in
start)
query_status && exit 0
start
;;
stop)
query_status || exit 0
stop
;;
restart)
restart
;;
status)
get_status
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0