Skip to content

Commit

Permalink
Make judgedaemon service shut down gracefully
Browse files Browse the repository at this point in the history
Also let it listen to SIGQUIT for a harder shutdown aborting any
ongoing judging, besides of course SIGKILL.
  • Loading branch information
DOMjudge team authored and meisterT committed Apr 20, 2024
1 parent 9f44e13 commit 5968d14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions judge/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Type=simple

ExecStart=@judgehost_bindir@/judgedaemon -n %i
User=@DOMJUDGE_USER@
KillSignal=SIGTERM
TimeoutStopSec=180
FinalKillSignal=SIGKILL

Restart=always
RestartSec=3
Expand Down
17 changes: 10 additions & 7 deletions lib/lib.misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ function alert(string $msgtype, string $description = '')
}

/**
* Functions to support graceful shutdown of daemons upon receiving a signal
* Functions to support (graceful) shutdown of daemons upon receiving a
* signal.
*/
function sig_handler(int $signal, $siginfo = null)
{
Expand All @@ -85,10 +86,11 @@ function sig_handler(int $signal, $siginfo = null)

switch ($signal) {
case SIGHUP:
$gracefulexitsignalled = true;
// no break
case SIGINT: # Ctrl+C
case SIGTERM:
$gracefulexitsignalled = true;
// no break
case SIGQUIT: # Ctrl+/
$exitsignalled = true;
}
}
Expand All @@ -106,12 +108,13 @@ function initsignals()

logmsg(LOG_DEBUG, "Installing signal handlers");

// Install signal handler for TERMINATE, HANGUP and INTERRUPT
// signals. The sleep() call will automatically return on
// receiving a signal.
pcntl_signal(SIGTERM, "sig_handler");
// Install signal handler for HANGUP, INTERRUPT, QUIT and TERMINATE
// signals. All but the QUIT signal should trigger a graceful shutdown.
// The sleep() call will automatically return on receiving a signal.
pcntl_signal(SIGHUP, "sig_handler");
pcntl_signal(SIGINT, "sig_handler");
pcntl_signal(SIGQUIT, "sig_handler");
pcntl_signal(SIGTERM, "sig_handler");
}

/**
Expand Down

0 comments on commit 5968d14

Please sign in to comment.