0.3.3: allow argv jobs (create), fix zero timeout, longer stop wait, template name without .conf
This commit is contained in:
1 parent
5bdd3c82c6
commit
e989df97a5
5 files changed
+24
-7
No files matched your search
+13
-4
@@ -20,7 +20,8 @@ if ($job === null) {
|
||||
|
||||
$verb = (string)$job['verb'];
|
||||
$name = (string)$job['vm'];
|
||||
if (!isset(VMM_ACTIONS[$verb])) {
|
||||
$action = VMM_ACTIONS[$verb] ?? null;
|
||||
if ($action === null && (!isset($job['argv']) || !is_array($job['argv']) || $job['argv'] === [])) {
|
||||
$job['state'] = 'failed';
|
||||
$job['error'] = 'unknown verb';
|
||||
$job['ended'] = time();
|
||||
@@ -61,7 +62,7 @@ vmm_job_write($job);
|
||||
|
||||
$argvVm = isset($job['argv']) && is_array($job['argv']) && $job['argv'] !== []
|
||||
? $job['argv']
|
||||
: array_merge(VMM_ACTIONS[$verb]['argv'], [$name]);
|
||||
: array_merge($action['argv'], [$name]);
|
||||
joblog($log, 'start: vm ' . implode(' ', $argvVm));
|
||||
|
||||
$vm = vmm_resolve('vm');
|
||||
@@ -120,7 +121,10 @@ fclose($pipes[0]);
|
||||
stream_set_blocking($pipes[1], false);
|
||||
stream_set_blocking($pipes[2], false);
|
||||
|
||||
$timeout = (int)($job['timeout'] ?? (VMM_ACTIONS[$verb]['timeout'] ?? 300));
|
||||
$timeout = (int)($job['timeout'] ?? 0);
|
||||
if ($timeout <= 0) {
|
||||
$timeout = (int)($action['timeout'] ?? 300);
|
||||
}
|
||||
$start = time();
|
||||
$timedOut = false;
|
||||
$cancelFile = VMM_JOBDIR . '/' . $id . '.cancel';
|
||||
@@ -179,10 +183,15 @@ $accept = [
|
||||
'reset' => ['running', 'bootloader'],
|
||||
'poweroff' => ['stopped'],
|
||||
'destroy' => ['absent'],
|
||||
'create' => ['stopped'],
|
||||
'install' => ['stopped'],
|
||||
][$verb] ?? [];
|
||||
|
||||
// a graceful stop can take a while (ACPI), and vm-bhyve reports "locked" while
|
||||
// it works - never treat that as the final state
|
||||
$waitFor = ['stop' => 180, 'poweroff' => 120, 'start' => 60, 'restart' => 90, 'reset' => 60, 'create' => 60, 'install' => 60][$verb] ?? 30;
|
||||
$stateAfter = vmm_vm_state($name);
|
||||
$deadline = time() + 30;
|
||||
$deadline = time() + $waitFor;
|
||||
while ($accept !== [] && !in_array($stateAfter, $accept, true) && time() < $deadline) {
|
||||
usleep(500000);
|
||||
$stateAfter = vmm_vm_state($name);
|
||||
|
||||
Reference in new issue
Block a user