0.2.1: fix job spawn (CLI php), transitional states, zfs hold release before destroy, API error logging
This commit is contained in:
1 parent
485a267ffe
commit
364ab42ffe
6 files changed
+233
-69
No files matched your search
+35
-13
@@ -82,6 +82,21 @@ if ($grub['source'] === 'bundle') {
|
||||
$env['PATH'] = VMM_ROOT . '/vendor/grub2-bhyve:' . ($env['PATH'] ?? '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin');
|
||||
}
|
||||
|
||||
// destroying a VM fails when backup tools (znapzend/zrepl) hold its snapshots
|
||||
if ($verb === 'destroy') {
|
||||
$ds = vmm_dataset_for_vm($name);
|
||||
if ($ds !== '') {
|
||||
joblog($log, 'checking zfs holds on ' . $ds);
|
||||
$released = vmm_release_holds($ds);
|
||||
foreach ($released as $r) {
|
||||
joblog($log, 'released hold: ' . $r);
|
||||
}
|
||||
if ($released === []) {
|
||||
joblog($log, 'no holds to release');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cmd = array_merge([$vm['path']], $argvVm);
|
||||
$spec = [
|
||||
0 => ['pipe', 'r'],
|
||||
@@ -152,18 +167,25 @@ fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
$rc = proc_close($proc);
|
||||
|
||||
$stateAfter = vmm_vm_state($name);
|
||||
|
||||
// vm-bhyve often returns 0 even when it refused the operation, so the
|
||||
// resulting state is what counts.
|
||||
$expected = [
|
||||
'start' => 'running',
|
||||
'stop' => 'stopped',
|
||||
'restart' => 'running',
|
||||
'reset' => 'running',
|
||||
'poweroff' => 'stopped',
|
||||
'destroy' => 'absent',
|
||||
][$verb] ?? '';
|
||||
// resulting state is what counts. Some states are transitional (a guest that
|
||||
// just booted reports "bootloader" for a moment), so wait a little.
|
||||
$accept = [
|
||||
'start' => ['running', 'bootloader', 'starting'],
|
||||
'stop' => ['stopped'],
|
||||
'restart' => ['running', 'bootloader', 'starting'],
|
||||
'reset' => ['running', 'bootloader'],
|
||||
'poweroff' => ['stopped'],
|
||||
'destroy' => ['absent'],
|
||||
][$verb] ?? [];
|
||||
|
||||
$stateAfter = vmm_vm_state($name);
|
||||
$deadline = time() + 30;
|
||||
while ($accept !== [] && !in_array($stateAfter, $accept, true) && time() < $deadline) {
|
||||
usleep(500000);
|
||||
$stateAfter = vmm_vm_state($name);
|
||||
}
|
||||
joblog($log, 'state after action: ' . $stateAfter);
|
||||
|
||||
$job['rc'] = $rc;
|
||||
$job['ended'] = time();
|
||||
@@ -174,9 +196,9 @@ if ($timedOut) {
|
||||
} elseif ($rc !== 0) {
|
||||
$job['state'] = 'failed';
|
||||
$job['error'] = 'vm exited with code ' . $rc;
|
||||
} elseif ($expected !== '' && $stateAfter !== $expected) {
|
||||
} elseif ($accept !== [] && !in_array($stateAfter, $accept, true)) {
|
||||
$job['state'] = 'failed';
|
||||
$job['error'] = sprintf('unexpected state after %s: %s (expected %s)', $verb, $stateAfter, $expected);
|
||||
$job['error'] = sprintf('unexpected state after %s: %s (expected %s)', $verb, $stateAfter, implode('/', $accept));
|
||||
} else {
|
||||
$job['state'] = 'done';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user