Docker: honor user setting of stop time-out

This commit is contained in:
bergware
2022-12-30 13:20:07 +01:00
parent 2967e30bba
commit 6ce9bc9de3
4 changed files with 8 additions and 11 deletions

View File

@@ -182,9 +182,9 @@ if (isset($_GET['updateContainer'])){
$cmd = str_replace('/docker create ', '/docker run -d ', $cmd);
$startContainer = true;
// attempt graceful stop of container first
stopContainer($Name, $echo);
stopContainer($Name, false, $echo);
}
// force kill container if still running after 10 seconds
// force kill container if still running after time-out
if (empty($_GET['communityApplications'])) removeContainer($Name, $echo);
execCommand($cmd, $echo);
if ($startContainer) addRoute($Name); // add route for remote WireGuard access

View File

@@ -780,10 +780,7 @@ class DockerClient {
public function stopContainer($id, $t=false) {
global $dockercfg;
if ( ! $t )
$t = intval($dockercfg['DOCKER_TIMEOUT']) ?: 10;
$this->getDockerJSON("/containers/$id/stop?t=$t", 'POST', $code);
$this->getDockerJSON("/containers/$id/stop?t=".($t?:$dockercfg['DOCKER_TIMEOUT']??10), 'POST', $code);
$this->flushCache($this::$containersCache);
return $code;
}

View File

@@ -311,7 +311,7 @@ function xmlToCommand($xml, $create_paths=false) {
$cmdName, $cmdNetwork, $cmdMyIP, $cmdCPUset, $logSize, $logFile, $cmdPrivileged, implode(' -e ', $Variables), implode(' -l ', $Labels), implode(' -p ', $Ports), implode(' -v ', $Volumes), implode(' --device=', $Devices), $xml['ExtraParams'], escapeshellarg($xml['Repository']), $xml['PostArgs']);
return [preg_replace('/\s\s+/', ' ', $cmd), $xml['Name'], $xml['Repository']];
}
function stopContainer($name, $t=10, $echo=true) {
function stopContainer($name, $t=false, $echo=true) {
global $DockerClient;
$waitID = mt_rand();
if ($echo) {

View File

@@ -1,6 +1,6 @@
<?PHP
/* Copyright 2005-2020, Lime Technology
* Copyright 2012-2020, Bergware International.
/* Copyright 2005-2022, Lime Technology
* Copyright 2012-2022, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
@@ -108,9 +108,9 @@ case 'ct':
// since container was already running, put it back it to a running state after update
$cmd = str_replace('/docker create ', '/docker run -d ', $cmd);
// attempt graceful stop of container first
$DockerClient->stopContainer($ct,30);
$DockerClient->stopContainer($ct);
}
// force kill container if still running after 30 seconds
// force kill container if still running after time-out
$DockerClient->removeContainer($ct);
execCommand($cmd,false);
$DockerClient->flushCaches();