changes
This commit is contained in:
@@ -8,7 +8,6 @@ class DeploySiteAction
|
|||||||
{
|
{
|
||||||
private string $deployScript = '/var/www/_deploy/deploy.sh';
|
private string $deployScript = '/var/www/_deploy/deploy.sh';
|
||||||
private string $logFile = '/var/www/_deploy/deploy.log';
|
private string $logFile = '/var/www/_deploy/deploy.log';
|
||||||
private string $pidFile = '/var/www/_deploy/deploy.pid';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Запускает deploy.sh напрямую
|
* Запускает deploy.sh напрямую
|
||||||
@@ -33,39 +32,35 @@ class DeploySiteAction
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Запускаем deploy.sh в фоне через proc_open
|
// Очищаем старый лог
|
||||||
|
if (file_exists($this->logFile)) {
|
||||||
|
unlink($this->logFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем deploy.sh в фоне
|
||||||
$command = sprintf(
|
$command = sprintf(
|
||||||
'nohup bash %s > %s 2>&1 & echo $!',
|
'nohup bash %s > %s 2>&1 &',
|
||||||
escapeshellarg($this->deployScript),
|
escapeshellarg($this->deployScript),
|
||||||
escapeshellarg($this->logFile)
|
escapeshellarg($this->logFile)
|
||||||
);
|
);
|
||||||
|
|
||||||
$descriptors = [
|
shell_exec($command);
|
||||||
1 => ['pipe', 'w'], // stdout
|
|
||||||
2 => ['pipe', 'w'], // stderr
|
|
||||||
];
|
|
||||||
|
|
||||||
$process = proc_open($command, $descriptors, $pipes);
|
// Даём процессу время на запуск
|
||||||
|
usleep(500000); // 0.5 сек
|
||||||
|
|
||||||
|
if (!$this->isDeployRunning()) {
|
||||||
|
// Процесс не запустился — читаем лог
|
||||||
|
$error = file_exists($this->logFile) ? file_get_contents($this->logFile) : 'Нет лога';
|
||||||
|
Log::error('Deploy script failed to start', ['log' => $error]);
|
||||||
|
|
||||||
if (!is_resource($process)) {
|
|
||||||
Log::error('Deploy script failed to start — proc_open unavailable');
|
|
||||||
return [
|
return [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'message' => 'Ошибка при запуске скрипта деплоя (proc_open недоступен)',
|
'message' => 'Скрипт деплоя не запустился. Проверьте лог.',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Читаем PID процесса
|
Log::info('Deploy triggered', ['user_id' => auth()->id()]);
|
||||||
$pid = trim(stream_get_contents($pipes[1]));
|
|
||||||
fclose($pipes[1]);
|
|
||||||
fclose($pipes[2]);
|
|
||||||
proc_close($process);
|
|
||||||
|
|
||||||
if (!empty($pid) && is_numeric($pid)) {
|
|
||||||
file_put_contents($this->pidFile, $pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::info('Deploy triggered', ['user_id' => auth()->id(), 'pid' => $pid]);
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
@@ -144,9 +139,6 @@ class DeploySiteAction
|
|||||||
if (file_exists($this->logFile)) {
|
if (file_exists($this->logFile)) {
|
||||||
unlink($this->logFile);
|
unlink($this->logFile);
|
||||||
}
|
}
|
||||||
if (file_exists($this->pidFile)) {
|
|
||||||
unlink($this->pidFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,18 +146,8 @@ class DeploySiteAction
|
|||||||
*/
|
*/
|
||||||
private function isDeployRunning(): bool
|
private function isDeployRunning(): bool
|
||||||
{
|
{
|
||||||
if (!file_exists($this->pidFile)) {
|
$output = shell_exec('pgrep -f "deploy\\.sh"');
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pid = trim(file_get_contents($this->pidFile));
|
return !empty(trim($output ?? ''));
|
||||||
if (empty($pid)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Проверяем существование процесса
|
|
||||||
exec(sprintf('kill -0 %s 2>/dev/null', escapeshellarg($pid)), $output, $exitCode);
|
|
||||||
|
|
||||||
return $exitCode === 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user