lasthourcloud/app/Actions/Proxy/CheckProxySettingsInSync.php

36 lines
1.1 KiB
PHP
Raw Normal View History

2023-05-12 18:42:39 +00:00
<?php
namespace App\Actions\Proxy;
use App\Enums\ActivityTypes;
use App\Enums\ProxyTypes;
use App\Models\Server;
use Spatie\Activitylog\Models\Activity;
use Symfony\Component\Yaml\Yaml;
class CheckProxySettingsInSync
{
public function __invoke(Server $server)
{
// @TODO What is the mechanism to make sure setting in sync?
$folder_name = match ($server->extra_attributes->proxy) {
ProxyTypes::TRAEFIK_V2->value => 'proxy',
};
2023-05-12 18:51:07 +00:00
$container_name = 'coolify-proxy';
$output = instantRemoteProcess([
2023-05-12 19:06:13 +00:00
// Folder exists, in ~/projects/<folder-name>
2023-05-12 18:42:39 +00:00
'if [ -d "projects/'.$folder_name.'" ]; then echo "true"; else echo "false"; fi',
2023-05-12 19:06:13 +00:00
// Container of name <container-name> is running
2023-05-12 18:51:07 +00:00
<<<EOT
[[ "$(docker inspect -f '{{.State.Running}}' $container_name 2>/dev/null)" == "true" ]] && echo "true" || echo "false"
EOT,
2023-05-12 18:42:39 +00:00
], $server);
2023-05-12 18:51:07 +00:00
return collect(
explode(PHP_EOL, $output)
)->every(fn($output) => $output === 'true');
2023-05-12 18:42:39 +00:00
}
}