fix: simplify HMS update to only git pull and add timeout protection
Update improvements: - Renamed button from "Update System" to "Update HMS" - Changed update to run only 'git pull' (removed database migrations) - Added 60-second timeout to prevent system hangup - Better error messages for timeouts and failures - Logs update status (running/success/failed/timeout) to history - Confirmation dialog now says "Pull latest HMS code from repository?" This ensures quick updates without long-running migrations that could hang the admin interface. Database migrations can be run separately as needed.
This commit is contained in:
parent
3720da9b16
commit
f9c0fd1a72
|
|
@ -46,49 +46,61 @@ class SystemOperations
|
||||||
$repoPath = ROOTPATH;
|
$repoPath = ROOTPATH;
|
||||||
$logFile = WRITEPATH . 'system_update.log';
|
$logFile = WRITEPATH . 'system_update.log';
|
||||||
$startedAt = date('Y-m-d H:i:s');
|
$startedAt = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
$entry = [
|
$entry = [
|
||||||
'timestamp' => $startedAt,
|
'timestamp' => $startedAt,
|
||||||
'type' => 'update',
|
'type' => 'update',
|
||||||
'status' => 'running',
|
'status' => 'running',
|
||||||
'message' => 'Update started',
|
'message' => 'HMS update started (git pull)',
|
||||||
];
|
];
|
||||||
$this->appendHistory($entry);
|
$this->appendHistory($entry);
|
||||||
|
|
||||||
$commands = [
|
// Run git pull with timeout protection
|
||||||
'cd ' . escapeshellarg($repoPath) . ' && git pull origin main 2>&1',
|
$command = 'cd ' . escapeshellarg($repoPath) . ' && timeout 60 git pull origin main 2>&1';
|
||||||
'cd ' . escapeshellarg($repoPath) . ' && php spark migrate --namespace App 2>&1',
|
$result = $this->runCommand($command);
|
||||||
];
|
$output = $result['output'];
|
||||||
|
|
||||||
$output = [];
|
// Check for timeout
|
||||||
foreach ($commands as $command) {
|
if (str_contains($output, 'Terminated') || $result['exit_code'] === 124) {
|
||||||
$result = $this->runCommand($command);
|
$entry = [
|
||||||
$output[] = $result['output'];
|
'timestamp' => date('Y-m-d H:i:s'),
|
||||||
if ($result['exit_code'] !== 0) {
|
'type' => 'update',
|
||||||
$entry = [
|
'status' => 'timeout',
|
||||||
'timestamp' => date('Y-m-d H:i:s'),
|
'message' => 'HMS update timed out (60 seconds)',
|
||||||
'type' => 'update',
|
'detail' => 'The git pull operation took too long. Check network connectivity and try again.',
|
||||||
'status' => 'failed',
|
];
|
||||||
'message' => 'Update failed',
|
$this->appendHistory($entry);
|
||||||
'detail' => trim(implode("\n", $output)),
|
file_put_contents($logFile, 'TIMEOUT: ' . $output . PHP_EOL, FILE_APPEND);
|
||||||
];
|
|
||||||
$this->appendHistory($entry);
|
|
||||||
file_put_contents($logFile, trim(implode("\n", $output)) . PHP_EOL, FILE_APPEND);
|
|
||||||
|
|
||||||
return ['ok' => false, 'message' => 'Update failed', 'output' => trim(implode("\n", $output))];
|
return ['ok' => false, 'message' => 'Update timed out after 60 seconds. Please check network and try again.', 'output' => $output];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($result['exit_code'] !== 0) {
|
||||||
|
$entry = [
|
||||||
|
'timestamp' => date('Y-m-d H:i:s'),
|
||||||
|
'type' => 'update',
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'HMS update failed',
|
||||||
|
'detail' => $output,
|
||||||
|
];
|
||||||
|
$this->appendHistory($entry);
|
||||||
|
file_put_contents($logFile, 'FAILED: ' . $output . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
|
return ['ok' => false, 'message' => 'Update failed. Check logs for details.', 'output' => $output];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Success
|
||||||
$entry = [
|
$entry = [
|
||||||
'timestamp' => date('Y-m-d H:i:s'),
|
'timestamp' => date('Y-m-d H:i:s'),
|
||||||
'type' => 'update',
|
'type' => 'update',
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'message' => 'Update completed',
|
'message' => 'HMS update completed',
|
||||||
'detail' => trim(implode("\n", $output)),
|
'detail' => $output,
|
||||||
];
|
];
|
||||||
$this->appendHistory($entry);
|
$this->appendHistory($entry);
|
||||||
file_put_contents($logFile, trim(implode("\n", $output)) . PHP_EOL, FILE_APPEND);
|
file_put_contents($logFile, 'SUCCESS: ' . $output . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
return ['ok' => true, 'message' => 'Update completed successfully', 'output' => trim(implode("\n", $output))];
|
return ['ok' => true, 'message' => 'HMS update completed successfully', 'output' => $output];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function runServerAction(string $action): array
|
public function runServerAction(string $action): array
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
<h5 class="mb-0">Maintenance Actions</h5>
|
<h5 class="mb-0">Maintenance Actions</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body d-grid gap-2">
|
<div class="card-body d-grid gap-2">
|
||||||
<button class="btn btn-primary" id="btnUpdateSystem">Update System</button>
|
<button class="btn btn-primary" id="btnUpdateSystem">Update HMS</button>
|
||||||
<button class="btn btn-outline-warning" id="btnRestartWeb">Restart Web Server</button>
|
<button class="btn btn-outline-warning" id="btnRestartWeb">Restart Web Server</button>
|
||||||
<button class="btn btn-outline-info" id="btnRestartPhp">Restart PHP-FPM</button>
|
<button class="btn btn-outline-info" id="btnRestartPhp">Restart PHP-FPM</button>
|
||||||
<button class="btn btn-outline-danger" id="btnShutdown">Shutdown Server</button>
|
<button class="btn btn-outline-danger" id="btnShutdown">Shutdown Server</button>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user