Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 151 lines (136 sloc) 3.795 kb
#! /bin/bash
# GITLAB
# Maintainer: @randx
# App Version: 4.0
# After https://github.com/gitlabhq/gitlab-recipes/blob/master/init.d/gitlab
### BEGIN INIT INFO
# Provides: gitlab
# Required-Start: $local_fs $remote_fs $network $syslog redis-server
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: GitLab git repository management
# Description: GitLab git repository management
### END INIT INFO
APP_ROOT="${H}/gitlab/github"
START_DAEMON_PROCESS="bundle exec puma $DAEMON_OPTS"
DAEMON_OPTS="-C $APP_ROOT/config/puma.rb -e production"
PID_PATH="$APP_ROOT/tmp/pids"
PUMA_PID="$PID_PATH/puma.pid"
SIDEKIQ_PID="$PID_PATH/sidekiq.pid"
STOP_SIDEKIQ="${H}/gitlab/sidekiqd stop"
START_SIDEKIQ="${H}/gitlab/sidekiqd start"
NAME="PUMA"
DESC="Gitlab service"
CD_TO_APP_ROOT="cd ${APP_ROOT}"
check_pid(){
if [ -f $PUMA_PID ]; then
PID=`cat $PUMA_PID`
SPID=`cat $SIDEKIQ_PID`
#echo "ps aux | grep $PID | grep -v grep | wc -l"
STATUS=`ps aux | grep $PID | grep -v grep | wc -l`
else
STATUS=0
PID=0
fi
SSTATUS="$(sidekiqd status)"
}
start() {
cd $APP_ROOT
check_pid
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
# Program is running, exit with error code 1.
echo "Error! $DESC $NAME is currently running!"
if [[ "${SSTATUS##(v)}" == "${SSTATUS}" ]] ; then $START_SIDEKIQ ; fi
sidekiqd status
exit 1
else
echo "Starting $DESC: "
#echo "nohup RAILS_ENV=production bundle exec puma $DAEMON_OPTS > /dev/null 2>&1 &"
RAILS_ENV=production bundle exec puma $DAEMON_OPTS
#echo "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &"
mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &
echo "$DESC started"
read -t10 -n1 -r -p "Waiting for sidekiq: "
check_pid
if [[ "${SSTATUS##(v)}" == "${SSTATUS}" ]] ; then $START_SIDEKIQ ; fi
sidekiqd status
fi
}
stop() {
cd $APP_ROOT
check_pid
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
## Program is running, stop it.
kill -QUIT `cat $PUMA_PID`
mkdir -p $PID_PATH && $STOP_SIDEKIQ
rm -f "$PUMA_PID" >> /dev/null
echo "$DESC stopped"
check_pid
if [[ "${SSTATUS##(x)}" == "${SSTATUS}" ]] ; then $STOP_SIDEKIQ ; fi
sidekiqd status
else
## Program is not running, exit with error.
echo "Error! $DESC not started!"
if [[ "${SSTATUS##(x)}" == "${SSTATUS}" ]] ; then $STOP_SIDEKIQ ; fi
sidekiqd status
exit 1
fi
}
restart() {
cd $APP_ROOT
check_pid
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
echo "Restarting $DESC..."
kill -USR2 `cat $PUMA_PID`
mkdir -p $PID_PATH && $STOP_SIDEKIQ && $START_SIDEKIQ
echo "$DESC restarted."
else
echo "Error, $NAME not running!"
exit 1
fi
}
status() {
cd $APP_ROOT
check_pid
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
echo "$DESC / puma with PID $PID is running."
"${H}/gitlab/sidekiqd" status
else
echo "$DESC is not running."
sidekiqd status
exit 1
fi
}
## Check to see if we are running as root first.
## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html
#if [ "$(id -u)" != "0" ]; then
# echo "This script must be run as root"
# exit 1
#fi
if [[ ! -e "${APP_ROOT}" ]]; then exit 0 ; fi
if [[ ! -e "${H}/gitlab/gitlab.yml" ]] ; then exit 0 ; fi
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload|force-reload)
echo -n "Reloading $NAME configuration: "
kill -HUP `cat $PID`
echo "done."
;;
status)
status
;;
*)
echo "Usage: sudo service gitlab {start|stop|status|restart|reload}" >&2
exit 1
;;
esac
exit 0
Jump to Line
Something went wrong with that request. Please try again.