diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-09-09 14:56:02 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-09-09 14:56:02 +0200 |
commit | 0b5d627cd4a3f81934e7772e3558356c9dd2e3cf (patch) | |
tree | a232d232e543ef372d91d0dfffbc93985f37d982 /bin | |
parent | 90c338a49541c95452181af9e0d0bcf9da6c51ad (diff) | |
parent | 0d610270d9634b783137bc6318eff4aa82572a7d (diff) | |
download | gitlab-ce-0b5d627cd4a3f81934e7772e3558356c9dd2e3cf.tar.gz |
Merge branch 'master' into ci-and-ce-sitting-in-a-tree-k-i-s-s-i-n-g
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/daemon_with_pidfile | 33 | ||||
-rwxr-xr-x | bin/mail_room | 4 |
2 files changed, 34 insertions, 3 deletions
diff --git a/bin/daemon_with_pidfile b/bin/daemon_with_pidfile new file mode 100755 index 00000000000..f138c27a0e2 --- /dev/null +++ b/bin/daemon_with_pidfile @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +# daemon_with_pidfile +# +# Daemonize, write a pidfile, and exec the remainder of the command line. + +def main(pidfile, cmd) + if middle_pid = Process.fork + # outer process + # Do not exit the outer process before the middle process finishes + Process.waitpid(middle_pid) + exit $?.exitstatus + end + + if final_pid = Process.fork + # middle process + open(pidfile, 'w') { |f| f.puts final_pid } + exit + end + + # Standard daemon things: become session leader, ignore SIGHUP, close stdin. + Signal.trap("HUP", "IGNORE") + Process.setsid + IO.new(0).close + + exec(*cmd) +end + +if ARGV.count < 2 + abort "Usage: #$0 pidfile command [args...]" +end + +pidfile = ARGV.shift +main(pidfile, ARGV) diff --git a/bin/mail_room b/bin/mail_room index f4f1a170c04..74a84f5b2b4 100755 --- a/bin/mail_room +++ b/bin/mail_room @@ -19,9 +19,7 @@ get_mail_room_pid() start() { - bundle exec mail_room -q -c $mail_room_config >> $mail_room_logfile 2>&1 & - PID=$! - echo $PID > $mail_room_pidfile + bin/daemon_with_pidfile $mail_room_pidfile bundle exec mail_room -q -c $mail_room_config >> $mail_room_logfile 2>&1 } stop() |