Lines 1-23
Link Here
|
1 |
#! /bin/sh |
1 |
#! /bin/sh |
2 |
|
2 |
|
3 |
# $FreeBSD$ |
|
|
4 |
|
5 |
### BEGIN INIT INFO |
6 |
# Provides: gitlab |
7 |
# Required-Start: $local_fs $remote_fs $network $syslog redis-server |
8 |
# Required-Stop: $local_fs $remote_fs $network $syslog |
9 |
# Default-Start: 2 3 4 5 |
10 |
# Default-Stop: 0 1 6 |
11 |
# Short-Description: GitLab git repository management |
12 |
# Description: GitLab git repository management |
13 |
# chkconfig: - 85 14 |
14 |
### END INIT INFO |
15 |
|
16 |
# Maintainer: Torsten Zuehlsdorff <ports@toco-domains.de> |
3 |
# Maintainer: Torsten Zuehlsdorff <ports@toco-domains.de> |
17 |
# Based on work of: @charlienewey, rovanion.luckey@gmail.com, @randx |
4 |
# Based on work of: @charlienewey, rovanion.luckey@gmail.com, @randx |
18 |
|
5 |
|
19 |
# PROVIDE: gitlab |
6 |
# PROVIDE: gitlab |
20 |
# REQUIRE: LOGIN |
7 |
# REQUIRE: redis nginx LOGIN |
21 |
# KEYWORD: shutdown |
8 |
# KEYWORD: shutdown |
22 |
# |
9 |
# |
23 |
# Add the following line to /etc/rc.conf to enable GitLab: |
10 |
# Add the following line to /etc/rc.conf to enable GitLab: |
Lines 32-52
Link Here
|
32 |
rcvar=gitlab_enable |
19 |
rcvar=gitlab_enable |
33 |
extra_commands=status |
20 |
extra_commands=status |
34 |
|
21 |
|
35 |
status_cmd="print_status" |
22 |
: ${gitlab_user="git"} |
36 |
start_cmd="start_gitlab" |
23 |
: ${gitlab_railsenv="production"} |
37 |
stop_cmd="stop_gitlab" |
|
|
38 |
restart_cmd="restart_gitlab" |
39 |
|
24 |
|
|
|
25 |
status_cmd="${name}_status" |
26 |
start_cmd="${name}_start" |
27 |
stop_cmd="${name}_stop" |
28 |
#restart_cmd="${name}_restart" |
29 |
|
30 |
extra_commands="status reload" |
31 |
|
40 |
gitlab_enable=${gitlab_enable:-"NO"} |
32 |
gitlab_enable=${gitlab_enable:-"NO"} |
41 |
|
33 |
|
42 |
load_rc_config $name |
34 |
load_rc_config $name |
43 |
|
35 |
|
44 |
### Environment variables |
36 |
### Environment variables |
45 |
RAILS_ENV="production" |
|
|
46 |
|
37 |
|
47 |
# Script variable names should be lower-case not to conflict with |
38 |
# Script variable names should be lower-case not to conflict with |
48 |
# internal /bin/sh variables such as PATH, EDITOR or SHELL. |
39 |
# internal /bin/sh variables such as PATH, EDITOR or SHELL. |
49 |
app_user="git" |
40 |
app_user=${gitlab_user} |
50 |
app_root="/usr/local/www/gitlab" |
41 |
app_root="/usr/local/www/gitlab" |
51 |
pid_path="$app_root/tmp/pids" |
42 |
pid_path="$app_root/tmp/pids" |
52 |
socket_path="$app_root/tmp/sockets" |
43 |
socket_path="$app_root/tmp/sockets" |
Lines 61-74
Link Here
|
61 |
gitlab_workhorse_log="$app_root/log/gitlab-workhorse.log" |
52 |
gitlab_workhorse_log="$app_root/log/gitlab-workhorse.log" |
62 |
shell_path="/bin/bash" |
53 |
shell_path="/bin/bash" |
63 |
|
54 |
|
64 |
# Read configuration variable file if it is present |
|
|
65 |
test -f /etc/default/gitlab && . /etc/default/gitlab |
66 |
|
67 |
# Switch to the app_user if it is not he/she who is running the script. |
68 |
if [ "$USER" != "$app_user" ]; then |
69 |
eval su - "$app_user" -c $(echo \")$0 "$@"$(echo \"); exit; |
70 |
fi |
71 |
|
72 |
# Switch to the gitlab path, exit on failure. |
55 |
# Switch to the gitlab path, exit on failure. |
73 |
if ! cd "$app_root" ; then |
56 |
if ! cd "$app_root" ; then |
74 |
echo "Failed to cd into $app_root, exiting!"; exit 1 |
57 |
echo "Failed to cd into $app_root, exiting!"; exit 1 |
Lines 215-221
Link Here
|
215 |
} |
198 |
} |
216 |
|
199 |
|
217 |
## Starts Unicorn and Sidekiq if they're not running. |
200 |
## Starts Unicorn and Sidekiq if they're not running. |
218 |
start_gitlab() { |
201 |
gitlab_start() { |
219 |
check_stale_pids |
202 |
check_stale_pids |
220 |
|
203 |
|
221 |
if [ "$web_status" != "0" ]; then |
204 |
if [ "$web_status" != "0" ]; then |
Lines 238-244
Link Here
|
238 |
# Remove old socket if it exists |
221 |
# Remove old socket if it exists |
239 |
rm -f "$socket_path"/gitlab.socket 2>/dev/null |
222 |
rm -f "$socket_path"/gitlab.socket 2>/dev/null |
240 |
# Start the web server |
223 |
# Start the web server |
241 |
RAILS_ENV=$RAILS_ENV bin/web start |
224 |
RAILS_ENV=$gitlab_railsenv bin/web start |
242 |
fi |
225 |
fi |
243 |
|
226 |
|
244 |
# If sidekiq is already running, don't start it again. |
227 |
# If sidekiq is already running, don't start it again. |
Lines 245-251
Link Here
|
245 |
if [ "$sidekiq_status" = "0" ]; then |
228 |
if [ "$sidekiq_status" = "0" ]; then |
246 |
echo "The Sidekiq job dispatcher is already running with pid $spid, not restarting" |
229 |
echo "The Sidekiq job dispatcher is already running with pid $spid, not restarting" |
247 |
else |
230 |
else |
248 |
RAILS_ENV=$RAILS_ENV bin/background_jobs start & |
231 |
RAILS_ENV=$gitlab_railsenv bin/background_jobs start & |
249 |
fi |
232 |
fi |
250 |
|
233 |
|
251 |
if [ "$gitlab_workhorse_status" = "0" ]; then |
234 |
if [ "$gitlab_workhorse_status" = "0" ]; then |
Lines 265-271
Link Here
|
265 |
if [ "$mail_room_status" = "0" ]; then |
248 |
if [ "$mail_room_status" = "0" ]; then |
266 |
echo "The MailRoom email processor is already running with pid $mpid, not restarting" |
249 |
echo "The MailRoom email processor is already running with pid $mpid, not restarting" |
267 |
else |
250 |
else |
268 |
RAILS_ENV=$RAILS_ENV bin/mail_room start & |
251 |
RAILS_ENV=$gitlab_railsenv bin/mail_room start & |
269 |
fi |
252 |
fi |
270 |
fi |
253 |
fi |
271 |
|
254 |
|
Lines 272-291
Link Here
|
272 |
# Wait for the pids to be planted |
255 |
# Wait for the pids to be planted |
273 |
wait_for_pids |
256 |
wait_for_pids |
274 |
# Finally check the status to tell wether or not GitLab is running |
257 |
# Finally check the status to tell wether or not GitLab is running |
275 |
print_status |
258 |
gitlab_status |
276 |
} |
259 |
} |
277 |
|
260 |
|
278 |
## Asks Unicorn, Sidekiq and MailRoom if they would be so kind as to stop, if not kills them. |
261 |
## Asks Unicorn, Sidekiq and MailRoom if they would be so kind as to stop, if not kills them. |
279 |
stop_gitlab() { |
262 |
gitlab_stop() { |
280 |
exit_if_not_running |
263 |
exit_if_not_running |
281 |
|
264 |
|
282 |
if [ "$web_status" = "0" ]; then |
265 |
if [ "$web_status" = "0" ]; then |
283 |
echo "Shutting down GitLab Unicorn" |
266 |
echo "Shutting down GitLab Unicorn" |
284 |
RAILS_ENV=$RAILS_ENV bin/web stop |
267 |
RAILS_ENV=$gitlab_railsenv bin/web stop |
285 |
fi |
268 |
fi |
286 |
if [ "$sidekiq_status" = "0" ]; then |
269 |
if [ "$sidekiq_status" = "0" ]; then |
287 |
echo "Shutting down GitLab Sidekiq" |
270 |
echo "Shutting down GitLab Sidekiq" |
288 |
RAILS_ENV=$RAILS_ENV bin/background_jobs stop |
271 |
RAILS_ENV=$gitlab_railsenv bin/background_jobs stop |
289 |
fi |
272 |
fi |
290 |
if [ "$gitlab_workhorse_status" = "0" ]; then |
273 |
if [ "$gitlab_workhorse_status" = "0" ]; then |
291 |
echo "Shutting down gitlab-workhorse" |
274 |
echo "Shutting down gitlab-workhorse" |
Lines 293-299
Link Here
|
293 |
fi |
276 |
fi |
294 |
if [ "$mail_room_enabled" = true ] && [ "$mail_room_status" = "0" ]; then |
277 |
if [ "$mail_room_enabled" = true ] && [ "$mail_room_status" = "0" ]; then |
295 |
echo "Shutting down GitLab MailRoom" |
278 |
echo "Shutting down GitLab MailRoom" |
296 |
RAILS_ENV=$RAILS_ENV bin/mail_room stop |
279 |
RAILS_ENV=$gitlab_railsenv bin/mail_room stop |
297 |
fi |
280 |
fi |
298 |
|
281 |
|
299 |
# If something needs to be stopped, lets wait for it to stop. Never use SIGKILL in a script. |
282 |
# If something needs to be stopped, lets wait for it to stop. Never use SIGKILL in a script. |
Lines 316-326
Link Here
|
316 |
rm "$mail_room_pid_path" 2>/dev/null |
299 |
rm "$mail_room_pid_path" 2>/dev/null |
317 |
fi |
300 |
fi |
318 |
|
301 |
|
319 |
print_status |
302 |
gitlab_status |
320 |
} |
303 |
} |
321 |
|
304 |
|
322 |
## Prints the status of GitLab and its components. |
305 |
## Prints the status of GitLab and its components. |
323 |
print_status() { |
306 |
gitlab_status() { |
324 |
check_status |
307 |
check_status |
325 |
if [ "$web_status" != "0" ] && [ "$sidekiq_status" != "0" ] && [ "$gitlab_workhorse_status" != "0" ] && { [ "$mail_room_enabled" != true ] || [ "$mail_room_status" != "0" ]; }; then |
308 |
if [ "$web_status" != "0" ] && [ "$sidekiq_status" != "0" ] && [ "$gitlab_workhorse_status" != "0" ] && { [ "$mail_room_enabled" != true ] || [ "$mail_room_status" != "0" ]; }; then |
326 |
echo "GitLab is not running." |
309 |
echo "GitLab is not running." |
Lines 361-414
Link Here
|
361 |
exit 1 |
344 |
exit 1 |
362 |
fi |
345 |
fi |
363 |
printf "Reloading GitLab Unicorn configuration... " |
346 |
printf "Reloading GitLab Unicorn configuration... " |
364 |
RAILS_ENV=$RAILS_ENV bin/web reload |
347 |
RAILS_ENV=$gitlab_railsenv bin/web reload |
365 |
echo "Done." |
348 |
echo "Done." |
366 |
|
349 |
|
367 |
echo "Restarting GitLab Sidekiq since it isn't capable of reloading its config..." |
350 |
echo "Restarting GitLab Sidekiq since it isn't capable of reloading its config..." |
368 |
RAILS_ENV=$RAILS_ENV bin/background_jobs restart |
351 |
RAILS_ENV=$gitlab_railsenv bin/background_jobs restart |
369 |
|
352 |
|
370 |
if [ "$mail_room_enabled" != true ]; then |
353 |
if [ "$mail_room_enabled" != true ]; then |
371 |
echo "Restarting GitLab MailRoom since it isn't capable of reloading its config..." |
354 |
echo "Restarting GitLab MailRoom since it isn't capable of reloading its config..." |
372 |
RAILS_ENV=$RAILS_ENV bin/mail_room restart |
355 |
RAILS_ENV=$gitlab_railsenv bin/mail_room restart |
373 |
fi |
356 |
fi |
374 |
|
357 |
|
375 |
wait_for_pids |
358 |
wait_for_pids |
376 |
print_status |
359 |
gitlab_status |
377 |
} |
360 |
} |
378 |
|
361 |
|
379 |
## Restarts Sidekiq and Unicorn. |
362 |
## Restarts Sidekiq and Unicorn. |
380 |
restart_gitlab(){ |
363 |
gitlab_restart(){ |
381 |
check_status |
364 |
check_status |
382 |
if [ "$web_status" = "0" ] || [ "$sidekiq_status" = "0" ] || [ "$gitlab_workhorse" = "0" ] || { [ "$mail_room_enabled" = true ] && [ "$mail_room_status" = "0" ]; }; then |
365 |
if [ "$web_status" = "0" ] || [ "$sidekiq_status" = "0" ] || [ "$gitlab_workhorse" = "0" ] || { [ "$mail_room_enabled" = true ] && [ "$mail_room_status" = "0" ]; }; then |
383 |
stop_gitlab |
366 |
gitlab_stop |
384 |
fi |
367 |
fi |
385 |
start_gitlab |
368 |
gitlab_start |
386 |
} |
369 |
} |
387 |
|
370 |
|
388 |
|
371 |
run_rc_command "$1" |
389 |
### Finally the input handling. |
|
|
390 |
|
391 |
case "$1" in |
392 |
start) |
393 |
start_gitlab |
394 |
;; |
395 |
stop) |
396 |
stop_gitlab |
397 |
;; |
398 |
restart) |
399 |
restart_gitlab |
400 |
;; |
401 |
reload|force-reload) |
402 |
reload_gitlab |
403 |
;; |
404 |
status) |
405 |
print_status |
406 |
exit $gitlab_status |
407 |
;; |
408 |
*) |
409 |
echo "Usage: service gitlab {start|stop|restart|reload|status}" |
410 |
exit 1 |
411 |
;; |
412 |
esac |
413 |
|
414 |
exit |