Commit 76d958ebe79d6ee6fa3229f02e91ba21bc65ecb6

Authored by rezigned
1 parent 25d5c1f6

Update init.d script

The original init.d script uses a fixed username (e.g. git). Which is not flexible
when we using other user. So, I've updated it to use $APP_USER variable
instead and wrap it in a function to reduce repetitive codes.
Showing 1 changed file with 10 additions and 5 deletions   Show diff stats
lib/support/init.d/gitlab
... ... @@ -16,6 +16,7 @@
16 16  
17 17  
18 18 APP_ROOT="/home/git/gitlab"
  19 +APP_USER="git"
19 20 DAEMON_OPTS="-C $APP_ROOT/config/puma.rb -e production"
20 21 PID_PATH="$APP_ROOT/tmp/pids"
21 22 WEB_SERVER_PID="$PID_PATH/puma.pid"
... ... @@ -36,6 +37,10 @@ check_pid(){
36 37 fi
37 38 }
38 39  
  40 +execute() {
  41 + sudo -u $APP_USER -H bash -l -c "$1"
  42 +}
  43 +
39 44 start() {
40 45 cd $APP_ROOT
41 46 check_pid
... ... @@ -45,8 +50,8 @@ start() {
45 50 exit 1
46 51 else
47 52 if [ `whoami` = root ]; then
48   - sudo -u git -H bash -l -c "RAILS_ENV=production bundle exec puma $DAEMON_OPTS"
49   - sudo -u git -H bash -l -c "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &"
  53 + execute "RAILS_ENV=production bundle exec puma $DAEMON_OPTS"
  54 + execute "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &"
50 55 echo "$DESC started"
51 56 fi
52 57 fi
... ... @@ -58,7 +63,7 @@ stop() {
58 63 if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
59 64 ## Program is running, stop it.
60 65 kill -QUIT `cat $WEB_SERVER_PID`
61   - sudo -u git -H bash -l -c "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &"
  66 + execute "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &"
62 67 rm "$WEB_SERVER_PID" >> /dev/null
63 68 echo "$DESC stopped"
64 69 else
... ... @@ -74,9 +79,9 @@ restart() {
74 79 if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
75 80 echo "Restarting $DESC..."
76 81 kill -USR2 `cat $WEB_SERVER_PID`
77   - sudo -u git -H bash -l -c "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &"
  82 + execute "mkdir -p $PID_PATH && $STOP_SIDEKIQ > /dev/null 2>&1 &"
78 83 if [ `whoami` = root ]; then
79   - sudo -u git -H bash -l -c "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &"
  84 + execute "mkdir -p $PID_PATH && $START_SIDEKIQ > /dev/null 2>&1 &"
80 85 fi
81 86 echo "$DESC restarted."
82 87 else
... ...