|
16 | 16 |
|
17 | 17 |
|
18 | 18 | APP_ROOT="/home/gitlab/gitlab"
|
19 |
| -DAEMON_OPTS="-c $APP_ROOT/config/unicorn.rb -E production -D" |
| 19 | +DAEMON_OPTS="-c $APP_ROOT/config/unicorn.rb -E production" |
| 20 | +PID_PATH="$APP_ROOT/tmp/pids" |
| 21 | +UNICORN_PID="$PID_PATH/unicorn.pid" |
| 22 | +RESQUE_PID="$PID_PATH/resque_worker.pid" |
20 | 23 | NAME="unicorn"
|
21 | 24 | DESC="Gitlab service"
|
22 |
| -PID="$APP_ROOT/tmp/pids/unicorn.pid" |
23 |
| -RESQUE_PID="$APP_ROOT/tmp/pids/resque_worker.pid" |
| 25 | + |
| 26 | +check_pid(){ |
| 27 | + if [ -f $UNICORN_PID ]; then |
| 28 | + PID=`cat $UNICORN_PID` |
| 29 | + STATUS=`ps aux | grep $PID | grep -v grep | wc -l` |
| 30 | + else |
| 31 | + STATUS=0 |
| 32 | + PID=0 |
| 33 | + fi |
| 34 | +} |
| 35 | + |
| 36 | +start() { |
| 37 | + cd $APP_ROOT |
| 38 | + check_pid |
| 39 | + if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then |
| 40 | + # Program is running, exit with error code 1. |
| 41 | + echo "Error! $DESC $NAME is currently running!" |
| 42 | + exit 1 |
| 43 | + else |
| 44 | + if [ `whoami` = root ]; then |
| 45 | + sudo -u gitlab -H sh -l -c "nohup bundle exec unicorn_rails $DAEMON_OPTS > /dev/null 2>&1 &" |
| 46 | + sudo -u gitlab -H sh -l -c "mkdir -p $PID_PATH && nohup bundle exec rake environment resque:work QUEUE=post_receive,mailer,system_hook RAILS_ENV=production PIDFILE=$RESQUE_PID > /dev/null 2>&1 &" |
| 47 | + echo "$DESC started" |
| 48 | + fi |
| 49 | + fi |
| 50 | +} |
| 51 | + |
| 52 | +stop() { |
| 53 | + cd $APP_ROOT |
| 54 | + check_pid |
| 55 | + if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then |
| 56 | + ## Program is running, stop it. |
| 57 | + kill -QUIT `cat $UNICORN_PID` |
| 58 | + kill -QUIT `cat $RESQUE_PID` |
| 59 | + rm "$UNICORN_PID" >> /dev/null |
| 60 | + rm "$RESQUE_PID" >> /dev/null |
| 61 | + echo "$DESC stopped" |
| 62 | + else |
| 63 | + ## Program is not running, exit with error. |
| 64 | + echo "Error! $DESC not started!" |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +} |
| 68 | + |
| 69 | +restart() { |
| 70 | + cd $APP_ROOT |
| 71 | + check_pid |
| 72 | + if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then |
| 73 | + echo -n "Restarting $DESC: " |
| 74 | + kill -USR2 `cat $UNICORN_PID` |
| 75 | + kill -USR2 `cat $RESQUE_PID` |
| 76 | + echo "$NAME." |
| 77 | + else |
| 78 | + echo "Error, $NAME not running!" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | +} |
| 82 | + |
| 83 | +status() { |
| 84 | + cd $APP_ROOT |
| 85 | + check_pid |
| 86 | + if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then |
| 87 | + echo "$DESC with PID $PID is running." |
| 88 | + else |
| 89 | + echo "$DESC is not running." |
| 90 | + exit 1 |
| 91 | + fi |
| 92 | +} |
| 93 | + |
| 94 | +## Check to see if we are running as root first. |
| 95 | +## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html |
| 96 | +if [ "$(id -u)" != "0" ]; then |
| 97 | + echo "This script must be run as root" |
| 98 | + exit 1 |
| 99 | +fi |
24 | 100 |
|
25 | 101 | case "$1" in
|
26 | 102 | start)
|
27 |
| - CD_TO_APP_DIR="cd $APP_ROOT" |
28 |
| - START_DAEMON_PROCESS="bundle exec unicorn_rails $DAEMON_OPTS" |
29 |
| - START_RESQUE_PROCESS="./resque.sh" |
30 |
| - |
31 |
| - echo -n "Starting $DESC: " |
32 |
| - if [ `whoami` = root ]; then |
33 |
| - sudo -u gitlab sh -l -c "$CD_TO_APP_DIR && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS" |
34 |
| - else |
35 |
| - $CD_TO_APP_DIR && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS |
36 |
| - fi |
37 |
| - echo "$NAME." |
| 103 | + start |
38 | 104 | ;;
|
39 | 105 | stop)
|
40 |
| - echo -n "Stopping $DESC: " |
41 |
| - kill -QUIT `cat $PID` |
42 |
| - kill -QUIT `cat $RESQUE_PID` |
43 |
| - echo "$NAME." |
| 106 | + stop |
44 | 107 | ;;
|
45 | 108 | restart)
|
46 |
| - echo -n "Restarting $DESC: " |
47 |
| - kill -USR2 `cat $PID` |
48 |
| - echo "$NAME." |
| 109 | + restart |
49 | 110 | ;;
|
50 |
| - reload) |
| 111 | + reload|force-reload) |
51 | 112 | echo -n "Reloading $DESC configuration: "
|
52 | 113 | kill -HUP `cat $PID`
|
53 | 114 | echo "$NAME."
|
54 | 115 | ;;
|
| 116 | + status) |
| 117 | + status |
| 118 | + ;; |
55 | 119 | *)
|
56 | 120 | echo "Usage: $NAME {start|stop|restart|reload}" >&2
|
57 | 121 | exit 1
|
|
0 commit comments