mirror of
https://github.com/unraid/webgui.git
synced 2026-04-22 10:08:25 -05:00
Execute docker commands with timeout
This commit is contained in:
@@ -14,7 +14,12 @@
|
||||
<?
|
||||
$user_prefs = '/boot/config/plugins/dockerMan/userprefs.cfg';
|
||||
|
||||
exec("docker ps -a --format='{{.Names}}'",$all_containers);
|
||||
# controlled docker execution
|
||||
function docker($cmd) {
|
||||
return exec("timeout 20 docker $cmd 2>/dev/null");
|
||||
}
|
||||
|
||||
exec("timeout 20 docker ps -a --format='{{.Names}}' 2>/dev/null",$all_containers);
|
||||
|
||||
if (file_exists($user_prefs)) {
|
||||
$prefs = parse_ini_file($user_prefs); $sort = [];
|
||||
@@ -29,6 +34,6 @@ switch ($action) {
|
||||
}
|
||||
|
||||
foreach ($all_containers as $ct) {
|
||||
if (exec("docker inspect --format='{{.State.Running}}' $ct")==$state) exec("docker $action $ct >/dev/null");
|
||||
if (docker("inspect --format='{{.State.Running}}' $ct")==$state) docker("$action $ct >/dev/null");
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -34,9 +34,9 @@ $DockerTemplates = new DockerTemplates();
|
||||
$echo = function($m){echo "<pre>".print_r($m, true)."</pre>";};
|
||||
|
||||
unset($custom);
|
||||
exec("docker network ls --filter driver='macvlan' --format='{{.Name}}'", $custom);
|
||||
exec("timeout 20 docker network ls --filter driver='macvlan' --format='{{.Name}}' 2>/dev/null", $custom);
|
||||
$subnet = ['bridge'=>'', 'host'=>'', 'none'=>''];
|
||||
foreach ($custom as $network) $subnet[$network] = substr(exec("docker network inspect --format='{{range .IPAM.Config}}{{.Subnet}}, {{end}}' $network"),0,-1);
|
||||
foreach ($custom as $network) $subnet[$network] = substr(docker("network inspect --format='{{range .IPAM.Config}}{{.Subnet}}, {{end}}' $network"),0,-1);
|
||||
|
||||
function stopContainer($name) {
|
||||
global $DockerClient;
|
||||
@@ -514,8 +514,8 @@ function getUsedPorts() {
|
||||
foreach ($names as $name) {
|
||||
$list = [];
|
||||
$list['Name'] = $name;
|
||||
$port = explode('|',exec("docker inspect --format='{{range \$c := .HostConfig.PortBindings}}{{(index \$c 0).HostPort}}|{{end}}' $name 2>/dev/null"));
|
||||
if (count($port)<2) $port = explode('|',str_replace(['/tcp','/udp'],'',exec("docker inspect --format='{{range \$p,\$c := .Config.ExposedPorts}}{{\$p}}|{{end}}' $name 2>/dev/null")));
|
||||
$port = explode('|',docker("inspect --format='{{range \$c := .HostConfig.PortBindings}}{{(index \$c 0).HostPort}}|{{end}}' $name"));
|
||||
if (count($port)<2) $port = explode('|',str_replace(['/tcp','/udp'],'',docker("inspect --format='{{range \$p,\$c := .Config.ExposedPorts}}{{\$p}}|{{end}}' $name")));
|
||||
natsort($port);
|
||||
$list['Port'] = implode(' ',array_unique($port));
|
||||
$ports[] = $list;
|
||||
@@ -529,8 +529,8 @@ function getUsedIPs() {
|
||||
foreach ($names as $name) {
|
||||
$list = [];
|
||||
$list['Name'] = $name;
|
||||
$mode = exec("docker inspect --format='{{lower .HostConfig.NetworkMode}}' $name 2>/dev/null");
|
||||
$list['ip'] = (exec("docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name 2>/dev/null") ?: $eth0['IPADDR:0'])." ($mode)";
|
||||
$mode = docker("inspect --format='{{lower .HostConfig.NetworkMode}}' $name");
|
||||
$list['ip'] = (docker("inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name") ?: $eth0['IPADDR:0'])." ($mode)";
|
||||
$ips[] = $list;
|
||||
}
|
||||
return $ips;
|
||||
@@ -747,7 +747,7 @@ if ($_GET['xmlTemplate']) {
|
||||
echo "<script>var Settings=".json_encode($xml).";</script>";
|
||||
}
|
||||
}
|
||||
exec("docker ps --format='{{.Names}}' 2>/dev/null",$names);
|
||||
exec("timeout 20 docker ps --format='{{.Names}}' 2>/dev/null",$names);
|
||||
echo "<script>var UsedPorts=".json_encode(getUsedPorts()).";</script>";
|
||||
echo "<script>var UsedIPs=".json_encode(getUsedIPs()).";</script>";
|
||||
$authoringMode = $dockercfg["DOCKER_AUTHORING_MODE"] == "yes" ? true : false;
|
||||
|
||||
@@ -27,9 +27,12 @@ $dockerManPaths = [
|
||||
'update-status' => '/var/lib/docker/unraid-update-status.json'
|
||||
];
|
||||
|
||||
#load network variables if needed.
|
||||
if (!isset($eth0) && is_file("$docroot/state/network.ini")) {
|
||||
extract(parse_ini_file("$docroot/state/network.ini",true));
|
||||
# load network variables if needed.
|
||||
if (!isset($eth0) && is_file("$docroot/state/network.ini")) extract(parse_ini_file("$docroot/state/network.ini",true));
|
||||
|
||||
# controlled docker execution
|
||||
function docker($cmd) {
|
||||
return exec("timeout 20 docker $cmd 2>/dev/null");
|
||||
}
|
||||
|
||||
// Docker configuration file - guaranteed to exist
|
||||
@@ -248,7 +251,7 @@ class DockerTemplates {
|
||||
$myIP = $this->getTemplateValue($Repository, 'MyIP');
|
||||
$network = $this->getTemplateValue($Repository, 'Network');
|
||||
if (!$myIP && preg_match("%^(br|eth|bond)[0-9]%",$network)) {
|
||||
$myIP = exec("docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name");
|
||||
$myIP = docker("inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name");
|
||||
}
|
||||
if (preg_match("%\[IP\]%", $WebUI)) {
|
||||
$WebUI = preg_replace("%\[IP\]%", $myIP ?: $eth0['IPADDR:0'], $WebUI);
|
||||
|
||||
@@ -60,24 +60,24 @@ foreach ($all_containers as $ct) {
|
||||
$status = $ct['Running'] ? 'started':'stopped';
|
||||
$icon = $info['icon'] ?: '/plugins/dynamix.docker.manager/images/question.png';
|
||||
$ports = [];
|
||||
$binds = explode('|',exec("docker inspect --format='{{range \$p,\$c := .HostConfig.PortBindings}}{{\$p}}:{{(index \$c 0).HostPort}}|{{end}}' $name 2>/dev/null"));
|
||||
$binds = explode('|',docker("inspect --format='{{range \$p,\$c := .HostConfig.PortBindings}}{{\$p}}:{{(index \$c 0).HostPort}}|{{end}}' $name"));
|
||||
if (count($binds)>1) {
|
||||
$ip = $ct['Running'] ? exec("docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name 2>/dev/null") : '0.0.0.0';
|
||||
$ip = $ct['Running'] ? docker("inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name") : '0.0.0.0';
|
||||
foreach ($binds as $bind) {
|
||||
if (!$bind) continue;
|
||||
list($container_port,$host_port) = explode(':',$bind);
|
||||
$ports[] = sprintf('%s:%s<i class="fa fa-arrows-h" style="margin:0 6px"></i>%s:%s',$ip, $container_port, $eth0['IPADDR:0'], $host_port);
|
||||
}
|
||||
} else {
|
||||
$binds = explode('|',exec("docker inspect --format='{{range \$p,\$c := .Config.ExposedPorts}}{{\$p}}|{{end}}' $name 2>/dev/null"));
|
||||
$ip = $ct['Running'] ? (exec("docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name 2>/dev/null") ?: $eth0['IPADDR:0']) : '0.0.0.0';
|
||||
$binds = explode('|',docker("inspect --format='{{range \$p,\$c := .Config.ExposedPorts}}{{\$p}}|{{end}}' $name"));
|
||||
$ip = $ct['Running'] ? (docker("inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $name") ?: $eth0['IPADDR:0']) : '0.0.0.0';
|
||||
foreach ($binds as $bind) {
|
||||
if (!$bind) continue;
|
||||
$ports[] = sprintf('%s:%s<i class="fa fa-arrows-h" style="margin:0 6px"></i>%s:%s',$ip, $bind, $ip, str_replace(['/tcp','/udp'],'',$bind));
|
||||
}
|
||||
}
|
||||
$paths = [];
|
||||
$mounts = explode('|',exec("docker inspect --format='{{range \$c := .HostConfig.Binds}}{{\$c}}|{{end}}' $name 2>/dev/null"));
|
||||
$mounts = explode('|',docker("inspect --format='{{range \$c := .HostConfig.Binds}}{{\$c}}|{{end}}' $name"));
|
||||
foreach ($mounts as $mount) {
|
||||
if (!$mount) continue;
|
||||
list($host_path,$container_path,$access_mode) = explode(':',$mount);
|
||||
|
||||
Reference in New Issue
Block a user