summaryrefslogtreecommitdiffstats
path: root/SOURCES/gitlab.init
blob: a000af51f2f5ceefa6bce9e7cf758f10c516d4c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
#
# GitLab
# Contributors  : @elvanja, @troyanov, @eiyaya, @foyo23, @nielsbasjes, @relip, @JasonMing, @andronat, @axilleas
# App Version   : 6.x

# chkconfig: 2345 82 55
# processname: sidekiq
# description: Runs sidekiq for nginx integration.

# Related (kudos @4sak3n0ne):
# https://github.com/gitlabhq/gitlabhq/issues/1049#issuecomment-8386882
# https://gist.github.com/3062860

# Save original $PATH
# /etc/rc.d/init.d/functions resets $PATH to default(/sbin:/usr/sbin:/bin:/usr/bin).
# Consequently, rvm and compiled ruby with custom path (which isn't /usr/bin) cannot be executed.
ORIGINAL_PATH=$PATH

# Include RedHat function library
. /etc/rc.d/init.d/functions

# Restore original $PATH
PATH=$ORIGINAL_PATH

# The name of the service
NAME=git

# The username and path to the gitlab source
USER=git
APP_PATH=/var/www/gitlab/gitlab

# The PID and LOCK files used by unicorn and sidekiq
SPID=$APP_PATH/tmp/pids/sidekiq.pid
SLOCK=/var/lock/subsys/sidekiq

# Ruby related path update
export PATH="/opt/ruby-1.9.3/bin:$PATH"

start() {
  cd $APP_PATH

  # Start sidekiq
  echo -n $"Starting sidekiq: "
  daemon --pidfile=$SPID --user=$USER "RAILS_ENV=production bundle exec rake sidekiq:start"
  sidekiq=$?
  [ $sidekiq -eq 0 ] && touch $SLOCK
  echo

  return $sidekiq
}

stop() {
  cd $APP_PATH

  # Stop sidekiq
  echo -n $"Stopping sidekiq: "
  killproc -p $SPID
  sidekiq=$?
  [ $sidekiq -eq 0 ] && rm -f $SLOCK
  echo

  return $sidekiq
}

restart() {
  stop
  start
}

get_status() {
  status -p $SPID sidekiq
}

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