wip
This commit is contained in:
parent
00d9983655
commit
da2deb85c4
@ -7,6 +7,7 @@
|
|||||||
use App\Models\CoolifyInstanceSettings;
|
use App\Models\CoolifyInstanceSettings;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Process;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
use Visus\Cuid2\Cuid2;
|
use Visus\Cuid2\Cuid2;
|
||||||
@ -249,7 +250,20 @@ public function stop()
|
|||||||
remoteProcess($command, $destination->server, null, $application);
|
remoteProcess($command, $destination->server, null, $application);
|
||||||
}
|
}
|
||||||
public function checkStatus() {
|
public function checkStatus() {
|
||||||
ContainerStatusJob::dispatch();
|
$application = Application::where('uuid', $this->application_uuid)->first();
|
||||||
|
$destination = $application->destination->getMorphClass()::where('id', $application->destination->id)->first();
|
||||||
|
$private_key_location = savePrivateKey($destination->server);
|
||||||
|
$ssh_command = generateSshCommand($private_key_location, $destination->server->ip, $destination->server->user, $destination->server->port, "docker ps -a --format '{{.State}}' --filter 'name={$application->uuid}'");
|
||||||
|
$process = Process::run($ssh_command);
|
||||||
|
$output = trim($process->output());
|
||||||
|
if ($output == '') {
|
||||||
|
$application->status = 'exited';
|
||||||
|
$application->save();
|
||||||
|
} else {
|
||||||
|
$application->status = $output;
|
||||||
|
$application->save();
|
||||||
|
}
|
||||||
|
// ContainerStatusJob::dispatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Process;
|
use Illuminate\Support\Facades\Process;
|
||||||
use Tests\Support\Output;
|
use Tests\Support\Output;
|
||||||
@ -26,16 +27,17 @@ public function __construct()
|
|||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$server = Server::all()->where('settings->is_build_server', '=', false)->first();
|
$servers = Server::all()->reject(fn (Server $server) => $server->settings->is_build_server);
|
||||||
$applications = Application::all();
|
$applications = Application::all();
|
||||||
$not_found_applications = $applications;
|
$not_found_applications = $applications;
|
||||||
$containers = [];
|
$containers = collect();
|
||||||
// foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
$private_key_location = savePrivateKey($server);
|
$private_key_location = savePrivateKey($server);
|
||||||
$ssh_command = generateSshCommand($private_key_location, $server->ip, $server->user, $server->port, 'docker ps -a -q --format \'{{json .}}\'');
|
$ssh_command = generateSshCommand($private_key_location, $server->ip, $server->user, $server->port, 'docker ps -a -q --format \'{{json .}}\'');
|
||||||
$process = Process::run($ssh_command);
|
$process = Process::run($ssh_command);
|
||||||
$output = trim($process->output());
|
$output = trim($process->output());
|
||||||
$containers = formatDockerCmdOutputToJson($output);
|
$containers = $containers->concat(formatDockerCmdOutputToJson($output));
|
||||||
|
}
|
||||||
foreach ($containers as $container) {
|
foreach ($containers as $container) {
|
||||||
$found_application = $applications->filter(function ($value, $key) use ($container) {
|
$found_application = $applications->filter(function ($value, $key) use ($container) {
|
||||||
return $value->uuid == $container['Names'];
|
return $value->uuid == $container['Names'];
|
||||||
@ -46,13 +48,13 @@ public function handle(): void
|
|||||||
});
|
});
|
||||||
$found_application->status = $container['State'];
|
$found_application->status = $container['State'];
|
||||||
$found_application->save();
|
$found_application->save();
|
||||||
// Log::info('Found application: ' . $found_application->uuid . ' settings status to: ' . $found_application->status);
|
Log::info('Found application: ' . $found_application->uuid . '.Set status to: ' . $found_application->status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($not_found_applications as $not_found_application) {
|
foreach ($not_found_applications as $not_found_application) {
|
||||||
$not_found_application->status = 'exited';
|
$not_found_application->status = 'exited';
|
||||||
$not_found_application->save();
|
$not_found_application->save();
|
||||||
// Log::info('Not found application: ' . $not_found_application->uuid . ' settings status to: ' . $not_found_application->status);
|
Log::info('Not found application: ' . $not_found_application->uuid . '.Set status to: ' . $not_found_application->status);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
class Project extends BaseModel
|
class Project extends BaseModel
|
||||||
{
|
{
|
||||||
protected $with = ['settings', 'environments'];
|
|
||||||
protected static function booted()
|
protected static function booted()
|
||||||
{
|
{
|
||||||
static::created(function ($project) {
|
static::created(function ($project) {
|
||||||
|
@ -52,7 +52,7 @@ public function up(): void
|
|||||||
$table->integer('health_check_retries')->default(10);
|
$table->integer('health_check_retries')->default(10);
|
||||||
$table->integer('health_check_start_period')->default(5);
|
$table->integer('health_check_start_period')->default(5);
|
||||||
|
|
||||||
$table->string('status')->default('killed');
|
$table->string('status')->default('exited');
|
||||||
|
|
||||||
$table->morphs('destination');
|
$table->morphs('destination');
|
||||||
$table->morphs('source');
|
$table->morphs('source');
|
||||||
|
@ -14,6 +14,7 @@ public function run(): void
|
|||||||
TeamSeeder::class,
|
TeamSeeder::class,
|
||||||
PrivateKeySeeder::class,
|
PrivateKeySeeder::class,
|
||||||
ServerSeeder::class,
|
ServerSeeder::class,
|
||||||
|
ServerSettingSeeder::class,
|
||||||
ProjectSeeder::class,
|
ProjectSeeder::class,
|
||||||
ProjectSettingSeeder::class,
|
ProjectSettingSeeder::class,
|
||||||
EnvironmentSeeder::class,
|
EnvironmentSeeder::class,
|
||||||
|
25
database/seeders/ServerSettingSeeder.php
Normal file
25
database/seeders/ServerSettingSeeder.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Models\Team;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class ServerSettingSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
$server_1 = Server::find(1)->load(['settings']);
|
||||||
|
$server_1->settings->is_build_server = true;
|
||||||
|
$server_1->settings->save();
|
||||||
|
|
||||||
|
$server_2 = Server::find(2)->load(['settings']);
|
||||||
|
$server_2->settings->is_build_server = true;
|
||||||
|
$server_2->settings->save();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -34,7 +34,7 @@ autostart=true
|
|||||||
autorestart=true
|
autorestart=true
|
||||||
stopasgroup=true
|
stopasgroup=true
|
||||||
killasgroup=true
|
killasgroup=true
|
||||||
numprocs=8
|
numprocs=1
|
||||||
redirect_stderr=true
|
redirect_stderr=true
|
||||||
stdout_logfile=/var/www/html/storage/logs/worker.log
|
stdout_logfile=/var/www/html/storage/logs/worker.log
|
||||||
stopwaitsecs=3600
|
stopwaitsecs=3600
|
||||||
|
Loading…
Reference in New Issue
Block a user