43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* ambre-pw-trigger.php · AMBRE · launch Playwright test in background
|
|
* GET ?script=X · launches v76-scripts/X.sh with nohup, returns immediately
|
|
*/
|
|
header("Content-Type: application/json; charset=utf-8");
|
|
|
|
$script = preg_replace("/[^a-z0-9-]/i", "", $_GET["script"] ?? "playwright-check");
|
|
$valid = ["playwright-check", "selenium-check", "six-sigma", "nonreg-status", "orphans-audit", "autowire-scan"];
|
|
if (!in_array($script, $valid)) {
|
|
echo json_encode(["ok"=>false, "error"=>"script not allowed", "valid"=>$valid]);
|
|
exit;
|
|
}
|
|
|
|
$path = "/var/www/html/api/v76-scripts/$script.sh";
|
|
if (!file_exists($path)) {
|
|
echo json_encode(["ok"=>false, "error"=>"not found", "path"=>$path]);
|
|
exit;
|
|
}
|
|
|
|
$ts = date("Ymd-His");
|
|
$log = "/tmp/ambre-pw-$script-$ts.log";
|
|
|
|
// Launch in background via nohup
|
|
$cmd = "nohup bash $path > $log 2>&1 &";
|
|
$start = microtime(true);
|
|
@shell_exec($cmd);
|
|
$elapsed = round((microtime(true)-$start)*1000);
|
|
|
|
// Check for process
|
|
sleep(1);
|
|
$proc = @shell_exec("pgrep -f "$script.sh" | head -1");
|
|
|
|
echo json_encode([
|
|
"ok" => true,
|
|
"script" => $script,
|
|
"launched_at" => date("c"),
|
|
"log" => $log,
|
|
"elapsed_ms" => $elapsed,
|
|
"process_pid" => trim($proc ?: "not detected"),
|
|
"message" => "Script running in background. Check log file: $log",
|
|
], JSON_PRETTY_PRINT);
|