sentinel updates
This commit is contained in:
@@ -10,32 +10,48 @@ class StartSentinel
|
|||||||
{
|
{
|
||||||
use AsAction;
|
use AsAction;
|
||||||
|
|
||||||
public function handle(Server $server, $version = 'latest', bool $restart = false)
|
public function handle(Server $server, $version = 'next', bool $restart = false)
|
||||||
{
|
{
|
||||||
if ($restart) {
|
if ($restart) {
|
||||||
StopSentinel::run($server);
|
StopSentinel::run($server);
|
||||||
}
|
}
|
||||||
$metrics_history = $server->settings->metrics_history_days;
|
$metrics_history = $server->settings->sentinel_metrics_history_days;
|
||||||
$refresh_rate = $server->settings->metrics_refresh_rate_seconds;
|
$refresh_rate = $server->settings->sentinel_metrics_refresh_rate_seconds;
|
||||||
$token = $server->settings->sentinel_token;
|
$token = $server->settings->sentinel_token;
|
||||||
$fqdn = InstanceSettings::get()->fqdn;
|
$endpoint = InstanceSettings::get()->fqdn;
|
||||||
if (str($fqdn)->startsWith('http')) {
|
if (isDev()) {
|
||||||
|
$endpoint = 'http://host.docker.internal:8000';
|
||||||
|
} else {
|
||||||
|
if (str($endpoint)->startsWith('http')) {
|
||||||
throw new \Exception('You should use https to run Sentinel.');
|
throw new \Exception('You should use https to run Sentinel.');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (! $endpoint) {
|
||||||
|
throw new \Exception('You should set FQDN in Instance Settings.');
|
||||||
|
}
|
||||||
$environments = [
|
$environments = [
|
||||||
'TOKEN' => $token,
|
'TOKEN' => $token,
|
||||||
'ENDPOINT' => InstanceSettings::get()->fqdn,
|
'ENDPOINT' => $endpoint,
|
||||||
'COLLECTOR_ENABLED' => 'true',
|
'COLLECTOR_ENABLED' => 'true',
|
||||||
'COLLECTOR_REFRESH_RATE_SECONDS' => $refresh_rate,
|
'COLLECTOR_REFRESH_RATE_SECONDS' => $refresh_rate,
|
||||||
'COLLECTOR_RETENTION_PERIOD_DAYS' => $metrics_history
|
'COLLECTOR_RETENTION_PERIOD_DAYS' => $metrics_history,
|
||||||
];
|
];
|
||||||
$docker_environments = "-e \"" . implode("\" -e \"", array_map(fn($key, $value) => "$key=$value", array_keys($environments), $environments)) . "\"";
|
if (isDev()) {
|
||||||
ray($docker_environments);
|
data_set($environments, 'GIN_MODE', 'debug');
|
||||||
return true;
|
}
|
||||||
// instant_remote_process([
|
$mount_dir = '/data/coolify/sentinel';
|
||||||
// "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",
|
if (isDev()) {
|
||||||
// 'chown -R 9999:root /data/coolify/sentinel',
|
$mount_dir = '/var/lib/docker/volumes/coolify_dev_coolify_data/_data/sentinel';
|
||||||
// 'chmod -R 700 /data/coolify/sentinel',
|
}
|
||||||
// ], $server, true);
|
$docker_environments = '-e "'.implode('" -e "', array_map(fn ($key, $value) => "$key=$value", array_keys($environments), $environments)).'"';
|
||||||
|
$docker_command = "docker run --pull always --rm -d $docker_environments --name coolify-sentinel -v /var/run/docker.sock:/var/run/docker.sock -v $mount_dir:/app/db --pid host --health-cmd \"curl --fail http://127.0.0.1:8888/api/health || exit 1\" --health-interval 10s --health-retries 3 --add-host=host.docker.internal:host-gateway ghcr.io/coollabsio/sentinel:$version";
|
||||||
|
|
||||||
|
return instant_remote_process([
|
||||||
|
'docker rm -f coolify-sentinel || true',
|
||||||
|
"mkdir -p $mount_dir",
|
||||||
|
$docker_command,
|
||||||
|
"chown -R 9999:root $mount_dir",
|
||||||
|
"chmod -R 700 $mount_dir",
|
||||||
|
], $server, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -101,7 +101,9 @@ class Form extends Component
|
|||||||
$this->server->settings->delete_unused_volumes = $server->settings->delete_unused_volumes;
|
$this->server->settings->delete_unused_volumes = $server->settings->delete_unused_volumes;
|
||||||
$this->server->settings->delete_unused_networks = $server->settings->delete_unused_networks;
|
$this->server->settings->delete_unused_networks = $server->settings->delete_unused_networks;
|
||||||
}
|
}
|
||||||
public function regenerateSentinelToken() {
|
|
||||||
|
public function regenerateSentinelToken()
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
$this->server->generateSentinelToken();
|
$this->server->generateSentinelToken();
|
||||||
$this->server->settings->refresh();
|
$this->server->settings->refresh();
|
||||||
@@ -110,6 +112,7 @@ class Form extends Component
|
|||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updated($field)
|
public function updated($field)
|
||||||
{
|
{
|
||||||
if ($field === 'server.settings.docker_cleanup_frequency') {
|
if ($field === 'server.settings.docker_cleanup_frequency') {
|
||||||
@@ -186,25 +189,26 @@ class Form extends Component
|
|||||||
public function getPushData()
|
public function getPushData()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (!isDev()) {
|
if (! isDev()) {
|
||||||
throw new \Exception('This feature is only available in dev mode.');
|
throw new \Exception('This feature is only available in dev mode.');
|
||||||
}
|
}
|
||||||
$response = Http::withHeaders([
|
$response = Http::withHeaders([
|
||||||
'Authorization' => 'Bearer ' . $this->server->settings->sentinel_token,
|
'Authorization' => 'Bearer '.$this->server->settings->sentinel_token,
|
||||||
])->post('http://host.docker.internal:8888/api/push', [
|
])->post('http://host.docker.internal:8888/api/push', [
|
||||||
'data' => 'test',
|
'data' => 'test',
|
||||||
]);
|
]);
|
||||||
if ($response->successful()) {
|
if ($response->successful()) {
|
||||||
$this->dispatch('success', 'Push data sent.');
|
$this->dispatch('success', 'Push data sent.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$error = data_get($response->json(), 'error');
|
$error = data_get($response->json(), 'error');
|
||||||
throw new \Exception($error);
|
throw new \Exception($error);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
} catch(\Throwable $e) {
|
|
||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function restartSentinel()
|
public function restartSentinel()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -285,6 +289,7 @@ class Form extends Component
|
|||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function manualCleanup()
|
public function manualCleanup()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -302,4 +307,10 @@ class Form extends Component
|
|||||||
$this->server->refresh();
|
$this->server->refresh();
|
||||||
$this->dispatch('success', 'Cloudflare Tunnels enabled.');
|
$this->dispatch('success', 'Cloudflare Tunnels enabled.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function startSentinel()
|
||||||
|
{
|
||||||
|
StartSentinel::run($this->server);
|
||||||
|
$this->dispatch('success', 'Sentinel started.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -282,11 +282,10 @@
|
|||||||
{{-- @endif --}}
|
{{-- @endif --}}
|
||||||
</div>
|
</div>
|
||||||
@if (isDev())
|
@if (isDev())
|
||||||
<x-forms.button wire:click="getPushData"> Push Test </x-forms.button>
|
<div class="w-64">
|
||||||
{{-- <div class="w-64">
|
|
||||||
<x-forms.checkbox instantSave id="server.settings.is_metrics_enabled" label="Enable Metrics" />
|
<x-forms.checkbox instantSave id="server.settings.is_metrics_enabled" label="Enable Metrics" />
|
||||||
<x-forms.button>Start Sentinel</x-forms.button>
|
<x-forms.button wire:click="startSentinel">Start Sentinel</x-forms.button>
|
||||||
</div> --}}
|
</div>
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<div class="flex flex-wrap gap-2 sm:flex-nowrap items-end">
|
<div class="flex flex-wrap gap-2 sm:flex-nowrap items-end">
|
||||||
<x-forms.input type="password" id="server.settings.sentinel_token" label="Metrics token"
|
<x-forms.input type="password" id="server.settings.sentinel_token" label="Metrics token"
|
||||||
|
Reference in New Issue
Block a user