Commit 87f4e1f153ef763bbdbd614f3c9e1f2ea4798830
1 parent
66d6c809
Exists in
master
and in
4 other branches
init.d script for unicorn
Showing
1 changed file
with
138 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,138 @@ |
1 | +#! /bin/bash | |
2 | + | |
3 | +# GITLAB | |
4 | +# Maintainer: @randx | |
5 | +# App Version: 6.0 | |
6 | + | |
7 | +### BEGIN INIT INFO | |
8 | +# Provides: gitlab | |
9 | +# Required-Start: $local_fs $remote_fs $network $syslog redis-server | |
10 | +# Required-Stop: $local_fs $remote_fs $network $syslog | |
11 | +# Default-Start: 2 3 4 5 | |
12 | +# Default-Stop: 0 1 6 | |
13 | +# Short-Description: GitLab git repository management | |
14 | +# Description: GitLab git repository management | |
15 | +### END INIT INFO | |
16 | + | |
17 | + | |
18 | +APP_ROOT="/home/git/gitlab" | |
19 | +APP_USER="git" | |
20 | +DAEMON_OPTS="-C $APP_ROOT/config/unicorn.rb -E production" | |
21 | +PID_PATH="$APP_ROOT/tmp/pids" | |
22 | +SOCKET_PATH="$APP_ROOT/tmp/sockets" | |
23 | +WEB_SERVER_PID="$PID_PATH/unicorn.pid" | |
24 | +SIDEKIQ_PID="$PID_PATH/sidekiq.pid" | |
25 | +STOP_SIDEKIQ="RAILS_ENV=production bundle exec rake sidekiq:stop" | |
26 | +START_SIDEKIQ="RAILS_ENV=production bundle exec rake sidekiq:start" | |
27 | +NAME="gitlab" | |
28 | +DESC="GitLab service" | |
29 | + | |
30 | +check_pid(){ | |
31 | + if [ -f $WEB_SERVER_PID ]; then | |
32 | + PID=`cat $WEB_SERVER_PID` | |
33 | + SPID=`cat $SIDEKIQ_PID` | |
34 | + STATUS=`ps aux | grep $PID | grep -v grep | wc -l` | |
35 | + else | |
36 | + STATUS=0 | |
37 | + PID=0 | |
38 | + fi | |
39 | +} | |
40 | + | |
41 | +execute() { | |
42 | + sudo -u $APP_USER -H bash -l -c "$1" | |
43 | +} | |
44 | + | |
45 | +start() { | |
46 | + cd $APP_ROOT | |
47 | + check_pid | |
48 | + if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then | |
49 | + # Program is running, exit with error code 1. | |
50 | + echo "Error! $DESC $NAME is currently running!" | |
51 | + exit 1 | |
52 | + else | |
53 | + if [ `whoami` = root ]; then | |
54 | + execute "rm -f $SOCKET_PATH/gitlab.socket" | |
55 | + execute "RAILS_ENV=production bundle exec unicorn_rails $DAEMON_OPTS > /dev/null 2>&1 &" | |
56 | + execute "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &" | |
57 | + echo "$DESC started" | |
58 | + fi | |
59 | + fi | |
60 | +} | |
61 | + | |
62 | +stop() { | |
63 | + cd $APP_ROOT | |
64 | + check_pid | |
65 | + if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then | |
66 | + ## Program is running, stop it. | |
67 | + kill -QUIT `cat $WEB_SERVER_PID` | |
68 | + execute "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &" | |
69 | + rm "$WEB_SERVER_PID" >> /dev/null | |
70 | + echo "$DESC stopped" | |
71 | + else | |
72 | + ## Program is not running, exit with error. | |
73 | + echo "Error! $DESC not started!" | |
74 | + exit 1 | |
75 | + fi | |
76 | +} | |
77 | + | |
78 | +restart() { | |
79 | + cd $APP_ROOT | |
80 | + check_pid | |
81 | + if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then | |
82 | + echo "Restarting $DESC..." | |
83 | + kill -USR2 `cat $WEB_SERVER_PID` | |
84 | + execute "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &" | |
85 | + if [ `whoami` = root ]; then | |
86 | + execute "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &" | |
87 | + fi | |
88 | + echo "$DESC restarted." | |
89 | + else | |
90 | + echo "Error, $NAME not running!" | |
91 | + exit 1 | |
92 | + fi | |
93 | +} | |
94 | + | |
95 | +status() { | |
96 | + cd $APP_ROOT | |
97 | + check_pid | |
98 | + if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then | |
99 | + echo "$DESC / Puma with PID $PID is running." | |
100 | + echo "$DESC / Sidekiq with PID $SPID is running." | |
101 | + else | |
102 | + echo "$DESC is not running." | |
103 | + exit 1 | |
104 | + fi | |
105 | +} | |
106 | + | |
107 | +## Check to see if we are running as root first. | |
108 | +## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html | |
109 | +if [ "$(id -u)" != "0" ]; then | |
110 | + echo "This script must be run as root" | |
111 | + exit 1 | |
112 | +fi | |
113 | + | |
114 | +case "$1" in | |
115 | + start) | |
116 | + start | |
117 | + ;; | |
118 | + stop) | |
119 | + stop | |
120 | + ;; | |
121 | + restart) | |
122 | + restart | |
123 | + ;; | |
124 | + reload|force-reload) | |
125 | + echo -n "Reloading $NAME configuration: " | |
126 | + kill -HUP `cat $PID` | |
127 | + echo "done." | |
128 | + ;; | |
129 | + status) | |
130 | + status | |
131 | + ;; | |
132 | + *) | |
133 | + echo "Usage: sudo service gitlab {start|stop|restart|reload}" >&2 | |
134 | + exit 1 | |
135 | + ;; | |
136 | +esac | |
137 | + | |
138 | +exit 0 | ... | ... |