Skip to content

Commit 132a277

Browse files
committed
listen SIGTERM for docker
1 parent 572ec18 commit 132a277

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Worker.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ protected static function parseCommand()
953953
case 'stop':
954954
if ($command2 === '-g') {
955955
static::$_gracefulStop = true;
956-
$sig = \SIGTERM;
956+
$sig = \SIGHUP;
957957
static::log("Workerman[$start_file] is gracefully stopping ...");
958958
} else {
959959
static::$_gracefulStop = false;
@@ -1101,8 +1101,10 @@ protected static function installSignal()
11011101
$signalHandler = '\Workerman\Worker::signalHandler';
11021102
// stop
11031103
\pcntl_signal(\SIGINT, $signalHandler, false);
1104-
// graceful stop
1104+
// stop
11051105
\pcntl_signal(\SIGTERM, $signalHandler, false);
1106+
// graceful stop
1107+
\pcntl_signal(\SIGHUP, $signalHandler, false);
11061108
// reload
11071109
\pcntl_signal(\SIGUSR1, $signalHandler, false);
11081110
// graceful reload
@@ -1128,8 +1130,10 @@ protected static function reinstallSignal()
11281130
$signalHandler = '\Workerman\Worker::signalHandler';
11291131
// uninstall stop signal handler
11301132
\pcntl_signal(\SIGINT, \SIG_IGN, false);
1131-
// uninstall graceful stop signal handler
1133+
// uninstall stop signal handler
11321134
\pcntl_signal(\SIGTERM, \SIG_IGN, false);
1135+
// uninstall graceful stop signal handler
1136+
\pcntl_signal(\SIGHUP, \SIG_IGN, false);
11331137
// uninstall reload signal handler
11341138
\pcntl_signal(\SIGUSR1, \SIG_IGN, false);
11351139
// uninstall graceful reload signal handler
@@ -1141,7 +1145,7 @@ protected static function reinstallSignal()
11411145
// reinstall stop signal handler
11421146
static::$globalEvent->add(\SIGINT, EventInterface::EV_SIGNAL, $signalHandler);
11431147
// reinstall graceful stop signal handler
1144-
static::$globalEvent->add(\SIGTERM, EventInterface::EV_SIGNAL, $signalHandler);
1148+
static::$globalEvent->add(\SIGHUP, EventInterface::EV_SIGNAL, $signalHandler);
11451149
// reinstall reload signal handler
11461150
static::$globalEvent->add(\SIGUSR1, EventInterface::EV_SIGNAL, $signalHandler);
11471151
// reinstall graceful reload signal handler
@@ -1162,11 +1166,12 @@ public static function signalHandler($signal)
11621166
switch ($signal) {
11631167
// Stop.
11641168
case \SIGINT:
1169+
case \SIGTERM:
11651170
static::$_gracefulStop = false;
11661171
static::stopAll();
11671172
break;
11681173
// Graceful stop.
1169-
case \SIGTERM:
1174+
case \SIGHUP:
11701175
static::$_gracefulStop = true;
11711176
static::stopAll();
11721177
break;
@@ -1826,7 +1831,7 @@ public static function stopAll()
18261831
$worker_pid_array = static::getAllWorkerPids();
18271832
// Send stop signal to all child processes.
18281833
if (static::$_gracefulStop) {
1829-
$sig = \SIGTERM;
1834+
$sig = \SIGHUP;
18301835
} else {
18311836
$sig = \SIGINT;
18321837
}

0 commit comments

Comments
 (0)