coolify/app/Actions/Server/StartSentinel.php

42 lines
1.7 KiB
PHP
Raw Normal View History

2024-05-08 12:22:35 +00:00
<?php
namespace App\Actions\Server;
2024-10-14 10:07:37 +00:00
use App\Models\InstanceSettings;
2024-05-08 12:22:35 +00:00
use App\Models\Server;
2024-06-10 20:43:34 +00:00
use Lorisleiva\Actions\Concerns\AsAction;
2024-05-08 12:22:35 +00:00
class StartSentinel
{
use AsAction;
2024-06-10 20:43:34 +00:00
public function handle(Server $server, $version = 'latest', bool $restart = false)
2024-05-08 12:22:35 +00:00
{
if ($restart) {
2024-06-18 14:42:42 +00:00
StopSentinel::run($server);
}
2024-06-18 14:42:42 +00:00
$metrics_history = $server->settings->metrics_history_days;
$refresh_rate = $server->settings->metrics_refresh_rate_seconds;
2024-10-14 10:07:37 +00:00
$token = $server->settings->sentinel_token;
$fqdn = InstanceSettings::get()->fqdn;
if (str($fqdn)->startsWith('http')) {
throw new \Exception('You should use https to run Sentinel.');
}
$environments = [
'TOKEN' => $token,
'ENDPOINT' => InstanceSettings::get()->fqdn,
'COLLECTOR_ENABLED' => 'true',
'COLLECTOR_REFRESH_RATE_SECONDS' => $refresh_rate,
'COLLECTOR_RETENTION_PERIOD_DAYS' => $metrics_history
];
$docker_environments = "-e \"" . implode("\" -e \"", array_map(fn($key, $value) => "$key=$value", array_keys($environments), $environments)) . "\"";
ray($docker_environments);
return true;
// instant_remote_process([
// "docker run --rm --pull always -d $docker_environments --name coolify-sentinel -v /var/run/docker.sock:/var/run/docker.sock -v /data/coolify/sentinel:/app/sentinel --pid host --health-cmd \"curl --fail http://127.0.0.1:8888/api/health || exit 1\" --health-interval 10s --health-retries 3 ghcr.io/coollabsio/sentinel:$version",
// 'chown -R 9999:root /data/coolify/sentinel',
// 'chmod -R 700 /data/coolify/sentinel',
// ], $server, true);
2024-05-08 12:22:35 +00:00
}
}