Fix container status handling and notifications
This commit is contained in:
		@@ -35,17 +35,13 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
 | 
				
			|||||||
        return $this->server->id;
 | 
					        return $this->server->id;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function handle(): void
 | 
					    public function handle()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // ray("checking container statuses for {$this->server->id}");
 | 
					        // ray("checking container statuses for {$this->server->id}");
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            if (!$this->server->isServerReady()) {
 | 
					            if (!$this->server->isServerReady()) {
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
            $containers = instant_remote_process(["docker container ls -q"], $this->server);
 | 
					 | 
				
			||||||
            if (!$containers) {
 | 
					 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            $containers = instant_remote_process(["docker container inspect $(docker container ls -q) --format '{{json .}}'"], $this->server);
 | 
					            $containers = instant_remote_process(["docker container inspect $(docker container ls -q) --format '{{json .}}'"], $this->server);
 | 
				
			||||||
            $containers = format_docker_command_output_to_json($containers);
 | 
					            $containers = format_docker_command_output_to_json($containers);
 | 
				
			||||||
            $applications = $this->server->applications();
 | 
					            $applications = $this->server->applications();
 | 
				
			||||||
@@ -167,7 +163,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
 | 
				
			|||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    $url = null;
 | 
					                    $url = null;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                $this->server->team->notify(new ContainerStopped($containerName, $this->server, $url));
 | 
					                $this->server->team?->notify(new ContainerStopped($containerName, $this->server, $url));
 | 
				
			||||||
                $exitedService->update(['status' => 'exited']);
 | 
					                $exitedService->update(['status' => 'exited']);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -194,7 +190,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
 | 
				
			|||||||
                    $url = null;
 | 
					                    $url = null;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $this->server->team->notify(new ContainerStopped($containerName, $this->server, $url));
 | 
					                $this->server->team?->notify(new ContainerStopped($containerName, $this->server, $url));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            $notRunningApplicationPreviews = $previews->pluck('id')->diff($foundApplicationPreviews);
 | 
					            $notRunningApplicationPreviews = $previews->pluck('id')->diff($foundApplicationPreviews);
 | 
				
			||||||
            foreach ($notRunningApplicationPreviews as $previewId) {
 | 
					            foreach ($notRunningApplicationPreviews as $previewId) {
 | 
				
			||||||
@@ -219,7 +215,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
 | 
				
			|||||||
                    $url = null;
 | 
					                    $url = null;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $this->server->team->notify(new ContainerStopped($containerName, $this->server, $url));
 | 
					                $this->server->team?->notify(new ContainerStopped($containerName, $this->server, $url));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            $notRunningDatabases = $databases->pluck('id')->diff($foundDatabases);
 | 
					            $notRunningDatabases = $databases->pluck('id')->diff($foundDatabases);
 | 
				
			||||||
            foreach ($notRunningDatabases as $database) {
 | 
					            foreach ($notRunningDatabases as $database) {
 | 
				
			||||||
@@ -243,7 +239,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
 | 
				
			|||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    $url = null;
 | 
					                    $url = null;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                $this->server->team->notify(new ContainerStopped($containerName, $this->server, $url));
 | 
					                $this->server->team?->notify(new ContainerStopped($containerName, $this->server, $url));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Check if proxy is running
 | 
					            // Check if proxy is running
 | 
				
			||||||
@@ -256,7 +252,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
 | 
				
			|||||||
                    $shouldStart = CheckProxy::run($this->server);
 | 
					                    $shouldStart = CheckProxy::run($this->server);
 | 
				
			||||||
                    if ($shouldStart) {
 | 
					                    if ($shouldStart) {
 | 
				
			||||||
                        StartProxy::run($this->server, false);
 | 
					                        StartProxy::run($this->server, false);
 | 
				
			||||||
                        $this->server->team->notify(new ContainerRestarted('coolify-proxy', $this->server));
 | 
					                        $this->server->team?->notify(new ContainerRestarted('coolify-proxy', $this->server));
 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
                        ray('Proxy could not be started.');
 | 
					                        ray('Proxy could not be started.');
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@@ -272,7 +268,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
 | 
				
			|||||||
        } catch (\Throwable $e) {
 | 
					        } catch (\Throwable $e) {
 | 
				
			||||||
            send_internal_notification("ContainerStatusJob failed on ({$this->server->id}) with: " . $e->getMessage());
 | 
					            send_internal_notification("ContainerStatusJob failed on ({$this->server->id}) with: " . $e->getMessage());
 | 
				
			||||||
            ray($e->getMessage());
 | 
					            ray($e->getMessage());
 | 
				
			||||||
            handleError($e);
 | 
					            return handleError($e);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -281,7 +281,7 @@ function send_internal_notification(string $message): void
 | 
				
			|||||||
    try {
 | 
					    try {
 | 
				
			||||||
        $baseUrl = config('app.name');
 | 
					        $baseUrl = config('app.name');
 | 
				
			||||||
        $team = Team::find(0);
 | 
					        $team = Team::find(0);
 | 
				
			||||||
        $team->notify(new GeneralNotification("👀 {$baseUrl}: " . $message));
 | 
					        $team?->notify(new GeneralNotification("👀 {$baseUrl}: " . $message));
 | 
				
			||||||
        ray("👀 {$baseUrl}: " . $message);
 | 
					        ray("👀 {$baseUrl}: " . $message);
 | 
				
			||||||
    } catch (\Throwable $e) {
 | 
					    } catch (\Throwable $e) {
 | 
				
			||||||
        ray($e->getMessage());
 | 
					        ray($e->getMessage());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,7 @@ return [
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // The release version of your application
 | 
					    // The release version of your application
 | 
				
			||||||
    // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
 | 
					    // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
 | 
				
			||||||
    'release' => '4.0.0-beta.146',
 | 
					    'release' => '4.0.0-beta.147',
 | 
				
			||||||
    // When left empty or `null` the Laravel environment will be used
 | 
					    // When left empty or `null` the Laravel environment will be used
 | 
				
			||||||
    'environment' => config('app.env'),
 | 
					    'environment' => config('app.env'),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,3 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
return '4.0.0-beta.146';
 | 
					return '4.0.0-beta.147';
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,7 @@
 | 
				
			|||||||
            "version": "3.12.36"
 | 
					            "version": "3.12.36"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        "v4": {
 | 
					        "v4": {
 | 
				
			||||||
            "version": "4.0.0-beta.146"
 | 
					            "version": "4.0.0-beta.147"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user