Lines 2-18
Link Here
|
2 |
|
2 |
|
3 |
# $FreeBSD: head/www/gitlab/files/gitlab.in 417194 2016-06-21 08:36:56Z tz $ |
3 |
# $FreeBSD: head/www/gitlab/files/gitlab.in 417194 2016-06-21 08:36:56Z tz $ |
4 |
|
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> |
5 |
# Maintainer: Torsten Zuehlsdorff <ports@toco-domains.de> |
17 |
# Based on work of: @charlienewey, rovanion.luckey@gmail.com, @randx |
6 |
# Based on work of: @charlienewey, rovanion.luckey@gmail.com, @randx |
18 |
|
7 |
|
Lines 51-80
Link Here
|
51 |
pid_path="$app_root/tmp/pids" |
40 |
pid_path="$app_root/tmp/pids" |
52 |
socket_path="$app_root/tmp/sockets" |
41 |
socket_path="$app_root/tmp/sockets" |
53 |
rails_socket="$socket_path/gitlab.socket" |
42 |
rails_socket="$socket_path/gitlab.socket" |
|
|
43 |
workhorse_socket=$socket_path/gitlab-workhorse.socket |
54 |
web_server_pid_path="$pid_path/unicorn.pid" |
44 |
web_server_pid_path="$pid_path/unicorn.pid" |
55 |
sidekiq_pid_path="$pid_path/sidekiq.pid" |
45 |
sidekiq_pid_path="$pid_path/sidekiq.pid" |
56 |
mail_room_enabled=false |
46 |
mail_room_enabled=false |
57 |
mail_room_pid_path="$pid_path/mail_room.pid" |
47 |
mail_room_pid_path="$pid_path/mail_room.pid" |
58 |
gitlab_workhorse_dir=$(cd $app_root/../gitlab-workhorse && pwd) |
48 |
gitlab_workhorse_dir=$(cd $app_root/../gitlab-workhorse && pwd) |
59 |
gitlab_workhorse_pid_path="$pid_path/gitlab-workhorse.pid" |
49 |
gitlab_workhorse_pid_path="$pid_path/gitlab-workhorse.pid" |
60 |
gitlab_workhorse_options="-listenUmask 0 -listenNetwork unix -listenAddr $socket_path/gitlab-workhorse.socket -authBackend http://127.0.0.1:8080 -authSocket $rails_socket -documentRoot $app_root/public" |
50 |
gitlab_workhorse_options="-listenNetwork unix -listenAddr $workhorse_socket -authSocket $rails_socket -documentRoot $app_root/public" |
61 |
gitlab_workhorse_log="$app_root/log/gitlab-workhorse.log" |
51 |
gitlab_workhorse_log="$app_root/log/gitlab-workhorse.log" |
62 |
shell_path="/bin/bash" |
52 |
shell_path="/bin/bash" |
63 |
|
53 |
|
64 |
# Read configuration variable file if it is present |
54 |
# Read configuration variable file if it is present |
65 |
test -f /etc/default/gitlab && . /etc/default/gitlab |
55 |
# test -f /etc/default/gitlab && . /etc/default/gitlab |
66 |
|
56 |
|
67 |
# Switch to the app_user if it is not he/she who is running the script. |
57 |
# Switch to the app_user if it is not he/she who is running the script. |
68 |
if [ "$USER" != "$app_user" ]; then |
58 |
# if [ "$USER" != "$app_user" ]; then |
69 |
eval su - "$app_user" -c $(echo \")$0 "$@"$(echo \"); exit; |
59 |
# eval su - "$app_user" -c $(echo \")$0 "$@"$(echo \"); exit; |
70 |
fi |
60 |
# fi |
71 |
|
61 |
|
72 |
# Switch to the gitlab path, exit on failure. |
62 |
# Switch to the gitlab path, exit on failure. |
73 |
if ! cd "$app_root" ; then |
63 |
# if ! cd "$app_root" ; then |
74 |
echo "Failed to cd into $app_root, exiting!"; exit 1 |
64 |
# echo "Failed to cd into $app_root, exiting!"; exit 1 |
|
|
65 |
# fi |
66 |
|
67 |
if ! su - $app_user -c "echo \$RAILS_ENV" >/dev/null |
68 |
then |
69 |
echo "ERROR: RAILS_ENV not set for user $app_user, login.conf(5)" |
70 |
exit 80 |
75 |
fi |
71 |
fi |
76 |
|
72 |
|
77 |
|
|
|
78 |
### Init Script functions |
73 |
### Init Script functions |
79 |
|
74 |
|
80 |
## Gets the pids from the files |
75 |
## Gets the pids from the files |
Lines 218-251
Link Here
|
218 |
start_gitlab() { |
213 |
start_gitlab() { |
219 |
check_stale_pids |
214 |
check_stale_pids |
220 |
|
215 |
|
221 |
if [ "$web_status" != "0" ]; then |
|
|
222 |
echo "Starting GitLab Unicorn" |
223 |
fi |
224 |
if [ "$sidekiq_status" != "0" ]; then |
225 |
echo "Starting GitLab Sidekiq" |
226 |
fi |
227 |
if [ "$gitlab_workhorse_status" != "0" ]; then |
228 |
echo "Starting gitlab-workhorse" |
229 |
fi |
230 |
if [ "$mail_room_enabled" = true ] && [ "$mail_room_status" != "0" ]; then |
231 |
echo "Starting GitLab MailRoom" |
232 |
fi |
233 |
|
234 |
# Then check if the service is running. If it is: don't start again. |
216 |
# Then check if the service is running. If it is: don't start again. |
235 |
if [ "$web_status" = "0" ]; then |
217 |
if [ "$web_status" = "0" ]; then |
236 |
echo "The Unicorn web server already running with pid $wpid, not restarting." |
218 |
echo "The Unicorn web server already running with pid $wpid, not restarting." |
237 |
else |
219 |
else |
|
|
220 |
echo "Starting GitLab Unicorn" |
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 |
# unicorn may break the current process on freebsd during |
241 |
RAILS_ENV=$RAILS_ENV bin/web start |
224 |
# deamonizing (defunct exists until new master has prefilled |
|
|
225 |
# caches) - therefore start itself is decoupled |
226 |
/usr/sbin/daemon -u ${app_user} ${app_root}/bin/web start |
227 |
# |
242 |
fi |
228 |
fi |
243 |
|
229 |
|
244 |
# If sidekiq is already running, don't start it again. |
230 |
# If sidekiq is already running, don't start it again. |
245 |
if [ "$sidekiq_status" = "0" ]; then |
231 |
if [ "$sidekiq_status" = "0" ]; then |
246 |
echo "The Sidekiq job dispatcher is already running with pid $spid, not restarting" |
232 |
echo "The Sidekiq job dispatcher is already running with pid $spid, not restarting" |
247 |
else |
233 |
else |
248 |
RAILS_ENV=$RAILS_ENV bin/background_jobs start & |
234 |
echo "Starting GitLab Sidekiq" |
|
|
235 |
su - $app_user -c "${app_root}/bin/background_jobs start" |
249 |
fi |
236 |
fi |
250 |
|
237 |
|
251 |
if [ "$gitlab_workhorse_status" = "0" ]; then |
238 |
if [ "$gitlab_workhorse_status" = "0" ]; then |
Lines 254-263
Link Here
|
254 |
# No need to remove a socket, gitlab-workhorse does this itself. |
241 |
# No need to remove a socket, gitlab-workhorse does this itself. |
255 |
# Because gitlab-workhorse has multiple executables we need to fix |
242 |
# Because gitlab-workhorse has multiple executables we need to fix |
256 |
# the PATH. |
243 |
# the PATH. |
257 |
$app_root/bin/daemon_with_pidfile $gitlab_workhorse_pid_path \ |
244 |
echo "Starting gitlab-workhorse" |
258 |
/usr/bin/env PATH=$gitlab_workhorse_dir:$PATH \ |
245 |
cd ${gitlab_workhorse_dir} && |
259 |
gitlab-workhorse $gitlab_workhorse_options \ |
246 |
/usr/sbin/daemon -p ${gitlab_workhorse_pid_path} -u ${app_user} \ |
260 |
>> $gitlab_workhorse_log 2>&1 & |
247 |
$gitlab_workhorse_dir/gitlab-workhorse $gitlab_workhorse_options \ |
|
|
248 |
>> $gitlab_workhorse_log 2>&1 |
261 |
fi |
249 |
fi |
262 |
|
250 |
|
263 |
if [ "$mail_room_enabled" = true ]; then |
251 |
if [ "$mail_room_enabled" = true ]; then |
Lines 265-271
Link Here
|
265 |
if [ "$mail_room_status" = "0" ]; then |
253 |
if [ "$mail_room_status" = "0" ]; then |
266 |
echo "The MailRoom email processor is already running with pid $mpid, not restarting" |
254 |
echo "The MailRoom email processor is already running with pid $mpid, not restarting" |
267 |
else |
255 |
else |
268 |
RAILS_ENV=$RAILS_ENV bin/mail_room start & |
256 |
echo "Starting GitLab MailRoom" |
|
|
257 |
/usr/sbin/daemon -u ${app_user} ${app_root}/bin/mail_room start |
269 |
fi |
258 |
fi |
270 |
fi |
259 |
fi |
271 |
|
260 |
|
Lines 281-299
Link Here
|
281 |
|
270 |
|
282 |
if [ "$web_status" = "0" ]; then |
271 |
if [ "$web_status" = "0" ]; then |
283 |
echo "Shutting down GitLab Unicorn" |
272 |
echo "Shutting down GitLab Unicorn" |
284 |
RAILS_ENV=$RAILS_ENV bin/web stop |
273 |
su - $app_user -c "${app_root}/bin/web stop" |
|
|
274 |
[ -S ${rails_socket} ] && rm -f ${rails_socket} |
285 |
fi |
275 |
fi |
286 |
if [ "$sidekiq_status" = "0" ]; then |
276 |
if [ "$sidekiq_status" = "0" ]; then |
287 |
echo "Shutting down GitLab Sidekiq" |
277 |
echo "Shutting down GitLab Sidekiq" |
288 |
RAILS_ENV=$RAILS_ENV bin/background_jobs stop |
278 |
su - $app_user -c "${app_root}/bin/background_jobs stop" |
289 |
fi |
279 |
fi |
290 |
if [ "$gitlab_workhorse_status" = "0" ]; then |
280 |
if [ "$gitlab_workhorse_status" = "0" ]; then |
291 |
echo "Shutting down gitlab-workhorse" |
281 |
echo "Shutting down gitlab-workhorse" |
292 |
kill -- $(cat $gitlab_workhorse_pid_path) |
282 |
kill -- $(cat $gitlab_workhorse_pid_path) |
|
|
283 |
[ -S ${workhorse_socket} ] && rm -f ${workhorse_socket} |
293 |
fi |
284 |
fi |
294 |
if [ "$mail_room_enabled" = true ] && [ "$mail_room_status" = "0" ]; then |
285 |
if [ "$mail_room_enabled" = true ] && [ "$mail_room_status" = "0" ]; then |
295 |
echo "Shutting down GitLab MailRoom" |
286 |
echo "Shutting down GitLab MailRoom" |
296 |
RAILS_ENV=$RAILS_ENV bin/mail_room stop |
287 |
su - $app_user -c "${rails_root}/bin/mail_room stop" |
297 |
fi |
288 |
fi |
298 |
|
289 |
|
299 |
# If something needs to be stopped, lets wait for it to stop. Never use SIGKILL in a script. |
290 |
# If something needs to be stopped, lets wait for it to stop. Never use SIGKILL in a script. |
Lines 361-375
Link Here
|
361 |
exit 1 |
352 |
exit 1 |
362 |
fi |
353 |
fi |
363 |
printf "Reloading GitLab Unicorn configuration... " |
354 |
printf "Reloading GitLab Unicorn configuration... " |
364 |
RAILS_ENV=$RAILS_ENV bin/web reload |
355 |
$sudo env RAILS_ENV=$RAILS_ENV bin/web reload |
365 |
echo "Done." |
356 |
echo "Done." |
366 |
|
357 |
|
367 |
echo "Restarting GitLab Sidekiq since it isn't capable of reloading its config..." |
358 |
echo "Restarting GitLab Sidekiq since it isn't capable of reloading its config..." |
368 |
RAILS_ENV=$RAILS_ENV bin/background_jobs restart |
359 |
$sudo env RAILS_ENV=$RAILS_ENV bin/background_jobs restart |
369 |
|
360 |
|
370 |
if [ "$mail_room_enabled" != true ]; then |
361 |
if [ "$mail_room_enabled" != true ]; then |
371 |
echo "Restarting GitLab MailRoom since it isn't capable of reloading its config..." |
362 |
echo "Restarting GitLab MailRoom since it isn't capable of reloading its config..." |
372 |
RAILS_ENV=$RAILS_ENV bin/mail_room restart |
363 |
$sudo env RAILS_ENV=$RAILS_ENV bin/mail_room restart |
373 |
fi |
364 |
fi |
374 |
|
365 |
|
375 |
wait_for_pids |
366 |
wait_for_pids |
Lines 386-414
Link Here
|
386 |
} |
377 |
} |
387 |
|
378 |
|
388 |
|
379 |
|
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 |
|
380 |
|
414 |
exit |
381 |
run_rc_command "$1" |