]>
Commit | Line | Data |
---|---|---|
7db376f0 ER |
1 | #!/bin/sh |
2 | # | |
3 | # gitlab-unicorn gitlab-unicorn short service description | |
4 | # | |
5 | # chkconfig: 345 82 18 | |
6 | # description: Runs unicorn | |
7 | # processname: sidekiq | |
8 | # | |
9 | # Related (kudos @4sak3n0ne): | |
10 | # https://github.com/gitlabhq/gitlabhq/issues/1049#issuecomment-8386882 | |
11 | # https://gist.github.com/3062860 | |
12 | ||
13 | # Source function library | |
14 | . /etc/rc.d/init.d/functions | |
15 | ||
16 | # Get network config | |
17 | . /etc/sysconfig/network | |
18 | ||
19 | # Check that networking is up. | |
20 | if is_yes "${NETWORKING}"; then | |
21 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
22 | msg_network_down "GitLab Unicorn" | |
23 | exit 1 | |
24 | fi | |
25 | else | |
26 | exit 0 | |
27 | fi | |
28 | ||
29 | ### Environment variables | |
30 | RAILS_ENV="production" | |
31 | ||
32 | # The username and path to the gitlab source | |
33 | USER=git | |
34 | APP_PATH=/var/lib/gitlab | |
35 | ||
36 | # The PID and LOCK files used by unicorn and sidekiq | |
37 | pidfile=$APP_PATH/tmp/pids/unicorn.pid | |
38 | lockfile=/var/lock/subsys/gitlab-unicorn | |
39 | ||
40 | # Get service config - may override defaults | |
41 | [ -f /etc/sysconfig/gitlab-unicorn ] && . /etc/sysconfig/gitlab-unicorn | |
42 | ||
43 | start() { | |
44 | # Check if the service is already running? | |
45 | if [ -f $lockfile ]; then | |
46 | msg_already_running "GitLab Unicorn" | |
47 | return | |
48 | fi | |
49 | ||
50 | msg_starting "GitLab Unicorn" | |
51 | daemon --pidfile $pidfile --user $USER --chdir "$APP_PATH" \ | |
52 | "env RAILS_ENV=$RAILS_ENV bin/web start" | |
53 | RETVAL=$? | |
54 | [ $RETVAL -eq 0 ] && touch $lockfile | |
55 | } | |
56 | ||
57 | stop() { | |
58 | if [ ! -f $lockfile ]; then | |
59 | msg_not_running "GitLab Unicorn" | |
60 | return | |
61 | fi | |
62 | ||
63 | # Stop daemons. | |
64 | msg_stopping "GitLab Unicorn" | |
65 | killproc --pidfile $pidfile unicorn | |
66 | rm -f $lockfile | |
67 | } | |
68 | ||
69 | reload() { | |
70 | if [ ! -f $lockfile ]; then | |
71 | msg_not_running "GitLab Unicorn" | |
72 | RETVAL=7 | |
73 | return | |
74 | fi | |
75 | ||
76 | msg_reloading "GitLab Unicorn" | |
77 | killproc <procname> -HUP | |
78 | killproc --pidfile $pidfile <procname> -HUP | |
79 | RETVAL=$? | |
80 | } | |
81 | ||
82 | condrestart() { | |
83 | if [ ! -f $lockfile ]; then | |
84 | msg_not_running "GitLab Unicorn" | |
85 | RETVAL=$1 | |
86 | return | |
87 | fi | |
88 | ||
89 | stop | |
90 | start | |
91 | } | |
92 | ||
93 | RETVAL=0 | |
94 | # See how we were called. | |
95 | case "$1" in | |
96 | start) | |
97 | start | |
98 | ;; | |
99 | stop) | |
100 | stop | |
101 | ;; | |
102 | restart) | |
103 | stop | |
104 | start | |
105 | ;; | |
106 | try-restart) | |
107 | condrestart 0 | |
108 | ;; | |
109 | force-reload) | |
110 | condrestart 7 | |
111 | ;; | |
112 | status) | |
113 | status --pidfile $pidfile unicorn | |
114 | RETVAL=$? | |
115 | ;; | |
116 | *) | |
117 | msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}" | |
118 | exit 3 | |
119 | esac | |
120 | ||
121 | exit $RETVAL |