scheduler: add Array Starting / Array Stopping event triggers
Two hardcoded event-triggered entries appear at the top of the scheduler (array_started.sh / array_stopping.sh). They show an ⚡ Array Start / ⚡ Array Stop badge instead of a cron field and are enabled/disabled via the normal toggle. Static event scripts fire them via Unraid's event system: - event/disks_mounted/array_start_jobs → runs in background (non-blocking) - event/disks_unmounting/array_stop_jobs → runs foreground (blocks until done) vv_cron_rebuild() skips @array_* entries so they never land in the cron file. Scripts executed on each event are managed in master.conf via ARRAY_START_SCRIPTS and ARRAY_STOP_SCRIPTS arrays.
This commit is contained in:
@@ -57,6 +57,8 @@ function vv_cron_rebuild(array $schedule): bool {
|
||||
$scriptsDir = SCRIPTS_DIR;
|
||||
foreach ($schedule as $entry) {
|
||||
if (empty($entry['enabled']) || empty($entry['cron']) || empty($entry['id'])) continue;
|
||||
// Event-triggered jobs (@array_start / @array_stop) are handled by static event scripts, not cron.
|
||||
if (str_starts_with($entry['cron'], '@array_')) continue;
|
||||
$script = "$scriptsDir/{$entry['id']}";
|
||||
$flags = !empty($entry['log_enabled']) ? ' --log' : '';
|
||||
$id = $entry['id'];
|
||||
@@ -193,31 +195,55 @@ function vv_custom_scripts(): array {
|
||||
}
|
||||
|
||||
// Walk the scripts repo and return the job tree:
|
||||
// orchestrators as top-level, individual scripts as children
|
||||
// hardcoded array-event entries first, then cron-scheduled orchestrators
|
||||
function vv_job_tree(): array {
|
||||
$scriptsDir = SCRIPTS_DIR;
|
||||
$schedule = vv_schedule_load();
|
||||
|
||||
// Orchestrators are in Orchestrators/ and their children are all scripts they call
|
||||
// For now: walk top-level folders, treat *_management.sh or *_maintenance.sh as orchs
|
||||
$orchPattern = "$scriptsDir/Orchestrators/*.sh";
|
||||
$orchs = [];
|
||||
|
||||
foreach (glob($orchPattern) ?: [] as $path) {
|
||||
$id = 'Orchestrators/' . basename($path);
|
||||
$entry = $schedule[$id] ?? ['enabled' => false, 'cron' => ''];
|
||||
$suggested = vv_script_suggested_cron($path);
|
||||
// Hardcoded array-event entries — always present, trigger via Unraid event scripts
|
||||
$eventDefs = [
|
||||
['id' => 'Orchestrators/array_started.sh', 'cron' => '@array_start', 'label' => 'Array Starting'],
|
||||
['id' => 'Orchestrators/array_stopping.sh', 'cron' => '@array_stop', 'label' => 'Array Stopping'],
|
||||
];
|
||||
$orchs = [];
|
||||
$eventIds = [];
|
||||
foreach ($eventDefs as $ev) {
|
||||
$id = $ev['id'];
|
||||
$path = "$scriptsDir/$id";
|
||||
$entry = $schedule[$id] ?? [];
|
||||
$eventIds[] = $id;
|
||||
$orchs[] = [
|
||||
'id' => $id,
|
||||
'label' => basename($path, '.sh'),
|
||||
'desc' => vv_script_description($path),
|
||||
'type' => 'orchestrator',
|
||||
'enabled' => (bool)($entry['enabled'] ?? false),
|
||||
'cron' => $entry['cron'] ?? '',
|
||||
'log_enabled' => (bool)($entry['log_enabled'] ?? false),
|
||||
'id' => $id,
|
||||
'label' => $ev['label'],
|
||||
'desc' => vv_script_description($path),
|
||||
'type' => 'event',
|
||||
'enabled' => (bool)($entry['enabled'] ?? false),
|
||||
'cron' => $ev['cron'],
|
||||
'log_enabled' => (bool)($entry['log_enabled'] ?? false),
|
||||
'suggested_cron' => '',
|
||||
'suggested_label' => '',
|
||||
'children' => vv_script_children($path, $schedule),
|
||||
];
|
||||
}
|
||||
|
||||
// Cron-scheduled orchestrators — discovered by glob, event entries excluded
|
||||
$orchPattern = "$scriptsDir/Orchestrators/*.sh";
|
||||
foreach (glob($orchPattern) ?: [] as $path) {
|
||||
$id = 'Orchestrators/' . basename($path);
|
||||
if (in_array($id, $eventIds, true)) continue;
|
||||
$entry = $schedule[$id] ?? ['enabled' => false, 'cron' => ''];
|
||||
$suggested = vv_script_suggested_cron($path);
|
||||
$orchs[] = [
|
||||
'id' => $id,
|
||||
'label' => basename($path, '.sh'),
|
||||
'desc' => vv_script_description($path),
|
||||
'type' => 'orchestrator',
|
||||
'enabled' => (bool)($entry['enabled'] ?? false),
|
||||
'cron' => $entry['cron'] ?? '',
|
||||
'log_enabled' => (bool)($entry['log_enabled'] ?? false),
|
||||
'suggested_cron' => $suggested['cron'],
|
||||
'suggested_label' => $suggested['label'],
|
||||
'children' => vv_script_children($path, $schedule),
|
||||
'children' => vv_script_children($path, $schedule),
|
||||
];
|
||||
}
|
||||
return $orchs;
|
||||
|
||||
Reference in New Issue
Block a user