0.3.2: register boot integration in config.xml (loaderconf + rc postinit); stop editing generated files

This commit is contained in:
Claw committed 2026-11-17 20:30:40 +01:00
1 parent 29365ce649
commit 5bdd3c82c6
5 files changed
+157 -18

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"appname": "VM Manager",
"version": "0.3.1",
"version": "0.3.2",
"rootfolder": "/mnt/Daten/extensions/vmmngr",
"vm_source": "auto",
"bridges": ["ix0bridge"],
+108
View File
@@ -0,0 +1,108 @@
<?php
/**
* vmmngr-config-lib.inc - boot integration through the XigmaNAS configuration.
*
* /boot/loader.conf.local and /etc/rc.conf are generated from /conf/config.xml
* at boot, so writing those files directly does not survive a reboot. This is
* the supported path: put the entries into $config and let write_config()
* persist them.
*/
if (!function_exists('vmm_register_boot')) {
/**
* Ensure vmm_load/nmdm_load and the postinit hook exist in config.xml.
*
* @return array list of added entries ('' when everything was present)
*/
function vmm_register_boot(): array
{
global $config;
$added = [];
// 1) loader.conf entries
$want = ['vmm_load' => 'YES', 'nmdm_load' => 'YES'];
if (!isset($config['loaderconf']) || !is_array($config['loaderconf'])) {
$config['loaderconf'] = [];
}
if (!isset($config['loaderconf']['param']) || !is_array($config['loaderconf']['param'])) {
$config['loaderconf']['param'] = [];
}
$have = [];
foreach ($config['loaderconf']['param'] as $p) {
if (isset($p['name'])) {
$have[(string)$p['name']] = true;
}
}
foreach ($want as $key => $value) {
if (isset($have[$key])) {
continue;
}
$config['loaderconf']['param'][] = [
'uuid' => uuid(),
'enable' => '',
'name' => $key,
'value' => $value,
'comment' => '',
];
$added[] = $key;
}
// 2) postinit hook: repairs symlinks and loads modules at every boot
$cmd = VMM_ROOT . '/vmm-init -p';
$found = false;
if (isset($config['rc']['param']) && is_array($config['rc']['param'])) {
foreach ($config['rc']['param'] as $p) {
if (trim((string)($p['value'] ?? '')) === $cmd) {
$found = true;
break;
}
}
} else {
if (!isset($config['rc']) || !is_array($config['rc'])) {
$config['rc'] = [];
}
$config['rc']['param'] = [];
}
if (!$found) {
$config['rc']['param'][] = [
'uuid' => uuid(),
'name' => 'VM Manager Extension',
'value' => $cmd,
'comment' => 'Start VM Manager',
'typeid' => '2',
'enable' => true,
];
$added[] = 'rc postinit';
}
if ($added !== []) {
write_config();
}
return $added;
}
function vmm_boot_state(): array
{
global $config;
$loader = [];
foreach (($config['loaderconf']['param'] ?? []) as $p) {
if (isset($p['name'])) {
$loader[(string)$p['name']] = (string)($p['value'] ?? '');
}
}
$rcCmd = VMM_ROOT . '/vmm-init -p';
$rcOk = false;
foreach (($config['rc']['param'] ?? []) as $p) {
if (trim((string)($p['value'] ?? '')) === $rcCmd) {
$rcOk = true;
break;
}
}
return [
'vmm_load' => $loader['vmm_load'] ?? '',
'nmdm_load' => $loader['nmdm_load'] ?? '',
'rc_postinit' => $rcOk,
];
}
}
+39
View File
@@ -4,6 +4,16 @@
*/
require_once 'vmmngr-boot.inc';
require_once 'vmmngr-config-lib.inc';
if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && ($_POST['act'] ?? '') === 'register') {
$added = vmm_register_boot();
$_SESSION['vmmngr_error'] = $added === []
? gettext('Boot integration was already complete - nothing changed.')
: sprintf(gettext('Added to config.xml: %s. Modules take effect at the next boot.'), implode(', ', $added));
header('Location: vmmngr_config.php');
exit;
}
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), gettext('Configuration')];
$sc = vmm_selfcheck();
@@ -16,6 +26,35 @@ vmm_nav('config'); ?>
<form action="vmmngr_config.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
<?php if (!empty($_SESSION['vmmngr_error'])): ?>
<?php print_info_box(vmm_h((string)$_SESSION['vmmngr_error'])); unset($_SESSION['vmmngr_error']); ?>
<?php endif; ?>
<?php $bs = vmm_boot_state(); ?>
<table class="area_data_settings" style="width:100%;border-collapse:collapse;">
<colgroup><col class="area_data_settings_col_tag"><col class="area_data_settings_col_data"></colgroup>
<thead>
<?php html_separator2(); html_titleline2(gettext('Boot integration (config.xml)'), 2); ?>
</thead>
<tbody>
<tr><td class="celltag">vmm_load</td><td class="celldata">
<span class="<?=$bs['vmm_load'] !== '' ? 'vmm-ok' : 'vmm-miss';?>"><?=$bs['vmm_load'] !== '' ? vmm_h($bs['vmm_load']) : gettext('missing');?></span>
</td></tr>
<tr><td class="celltag">nmdm_load</td><td class="celldata">
<span class="<?=$bs['nmdm_load'] !== '' ? 'vmm-ok' : 'vmm-miss';?>"><?=$bs['nmdm_load'] !== '' ? vmm_h($bs['nmdm_load']) : gettext('missing');?></span>
</td></tr>
<tr><td class="celltag"><?=gettext('Postinit hook');?></td><td class="celldata">
<span class="<?=$bs['rc_postinit'] ? 'vmm-ok' : 'vmm-miss';?>"><?=$bs['rc_postinit'] ? gettext('registered') : gettext('missing');?></span>
</td></tr>
<tr><td class="celltag"><?=gettext('Action');?></td><td class="celldata">
<button type="submit" class="formbtn" name="act" value="register"><?=gettext('Register in config.xml');?></button>
<span style="opacity:.75;margin-left:8px;"><?=gettext('XigmaNAS regenerates loader.conf.local and rc.conf from config.xml at boot; direct file edits do not survive.');?></span>
</td></tr>
</tbody>
</table>
<br />
<table class="area_data_settings" style="width:100%;border-collapse:collapse;">
<colgroup>
<col class="area_data_settings_col_tag">