From c83a66f3cfc29560873256736ac45c65f9fb4bfb Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 26 Nov 2016 22:56:54 -0800 Subject: [PATCH] jobd.pl: support graceful restart If the string "restart" is written to jobd's lock file, then restart the next time the queue is about to be run. This allows a graceful restart of jobd.pl to be scheduled by an update install. Signed-off-by: Kyle J. McKay --- jobd/jobd.pl | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/jobd/jobd.pl b/jobd/jobd.pl index e2ad822..75b112c 100755 --- a/jobd/jobd.pl +++ b/jobd/jobd.pl @@ -18,6 +18,7 @@ use Girocco::Project; use Girocco::User; use Girocco::Util; BEGIN {noFatalsToBrowser} +use Girocco::ExecUtil; # Options my $quiet; @@ -465,15 +466,27 @@ sub run_perpetually { close LOCK; $locked = 1; + my $result = ""; while ($perpetual) { # touch ctime of lockfile to prevent it from being removed by /tmp cleaning - chmod 0444, $lockfile; + chmod 0640, $lockfile; chmod 0644, $lockfile; + # check for restart request + open LOCK, '<', $lockfile || die "Lock file '$lockfile' has disappeared!"; + my $request = ; + close LOCK; + chomp $request if defined($request); + if (defined($request) && $request eq "restart") { + $result = $request; + last; + } queue_all(); run_queue(); sleep($restart_delay) if $perpetual; # Let the system breathe for a moment } unlink $lockfile; + $locked = 0; + return $result; } ######### Helpers {{{1 @@ -491,6 +504,7 @@ sub fatal($) { ######### Main {{{1 +my $reexec = Girocco::ExecUtil->new; chdir "/"; close(DATA) if fileno(DATA); # Parse options @@ -531,7 +545,15 @@ if ($all_once) { exit; } -run_perpetually(); +{ + if (run_perpetually() eq "restart") { + error("Restarting in response to restart request... "); + $reexec->reexec; + error("Continuing after failed restart: $!"); + chdir "/"; + redo; + } +} ########## Documentation {{{1 -- 2.11.4.GIT