mirror of
https://github.com/unraid/webgui.git
synced 2026-04-21 17:29:28 -05:00
Docker code optimization
This commit is contained in:
@@ -18,22 +18,15 @@ $user_prefs = '/boot/config/plugins/dockerMan/userprefs.cfg';
|
||||
function docker($cmd, &$var=null) {
|
||||
return exec("timeout 20 /usr/bin/docker $cmd 2>/dev/null",$var);
|
||||
}
|
||||
|
||||
$all_containers=[]; docker("ps -a --format='{{.Names}}'", $all_containers);
|
||||
$action = $_POST['action'];
|
||||
$status = $action=='start' ? 'exited' : 'running';
|
||||
$all_containers=[]; docker("ps -a --filter status='$status' --format='{{.Names}}'", $all_containers);
|
||||
|
||||
if (file_exists($user_prefs)) {
|
||||
$prefs = parse_ini_file($user_prefs); $sort = [];
|
||||
foreach ($all_containers as $ct) $sort[] = array_search($ct,$prefs) ?? 999;
|
||||
array_multisort($sort,SORT_NUMERIC,$all_containers);
|
||||
array_multisort($sort, ($action=='start'?SORT_ASC:SORT_DESC), SORT_NUMERIC, $all_containers);
|
||||
}
|
||||
|
||||
$action = $_POST['action'];
|
||||
switch ($action) {
|
||||
case 'stop' : $state = 'true'; $all_containers = array_reverse($all_containers); break;
|
||||
case 'start': $state = 'false'; break;
|
||||
}
|
||||
|
||||
foreach ($all_containers as $ct) {
|
||||
if (docker("inspect --format='{{.State.Running}}' $ct")==$state) docker("$action $ct >/dev/null");
|
||||
}
|
||||
foreach ($all_containers as $ct) docker("$action $ct >/dev/null");
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user