Skip to content

Commit 63a8779

Browse files
DOMjudge teameldering
authored andcommitted
Make judgedaemon service shut down gracefully
Also let it listen to SIGQUIT for a harder shutdown aborting any ongoing judging, besides of course SIGKILL.
1 parent 3d55513 commit 63a8779

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

judge/[email protected]

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Type=simple
2020

2121
ExecStart=@judgehost_bindir@/judgedaemon -n %i
2222
User=@DOMJUDGE_USER@
23+
KillSignal=SIGTERM
24+
TimeoutStopSec=180
25+
FinalKillSignal=SIGKILL
2326

2427
Restart=always
2528
RestartSec=3

lib/lib.misc.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ function alert(string $msgtype, string $description = '')
7575
}
7676

7777
/**
78-
* Functions to support graceful shutdown of daemons upon receiving a signal
78+
* Functions to support (graceful) shutdown of daemons upon receiving a
79+
* signal.
7980
*/
8081
function sig_handler(int $signal, $siginfo = null)
8182
{
@@ -85,10 +86,11 @@ function sig_handler(int $signal, $siginfo = null)
8586

8687
switch ($signal) {
8788
case SIGHUP:
88-
$gracefulexitsignalled = true;
89-
// no break
9089
case SIGINT: # Ctrl+C
9190
case SIGTERM:
91+
$gracefulexitsignalled = true;
92+
// no break
93+
case SIGQUIT: # Ctrl+/
9294
$exitsignalled = true;
9395
}
9496
}
@@ -106,12 +108,13 @@ function initsignals()
106108

107109
logmsg(LOG_DEBUG, "Installing signal handlers");
108110

109-
// Install signal handler for TERMINATE, HANGUP and INTERRUPT
110-
// signals. The sleep() call will automatically return on
111-
// receiving a signal.
112-
pcntl_signal(SIGTERM, "sig_handler");
111+
// Install signal handler for HANGUP, INTERRUPT, QUIT and TERMINATE
112+
// signals. All but the QUIT signal should trigger a graceful shutdown.
113+
// The sleep() call will automatically return on receiving a signal.
113114
pcntl_signal(SIGHUP, "sig_handler");
114115
pcntl_signal(SIGINT, "sig_handler");
116+
pcntl_signal(SIGQUIT, "sig_handler");
117+
pcntl_signal(SIGTERM, "sig_handler");
115118
}
116119

117120
/**

0 commit comments

Comments
 (0)