fix: clean up SmartProxy lifecycle
This commit is contained in:
@@ -435,6 +435,9 @@ export class Onebox {
|
|||||||
// Stop proxy log receiver
|
// Stop proxy log receiver
|
||||||
await this.proxyLogReceiver.stop();
|
await this.proxyLogReceiver.stop();
|
||||||
|
|
||||||
|
// Stop built-in registry and backing smartstorage server
|
||||||
|
await this.registry.stop();
|
||||||
|
|
||||||
// Close backup archive
|
// Close backup archive
|
||||||
await this.backupManager.close();
|
await this.backupManager.close();
|
||||||
|
|
||||||
|
|||||||
@@ -130,12 +130,9 @@ export class OneboxReverseProxy {
|
|||||||
/**
|
/**
|
||||||
* Remove a route
|
* Remove a route
|
||||||
*/
|
*/
|
||||||
removeRoute(domain: string): void {
|
async removeRoute(domain: string): Promise<void> {
|
||||||
if (this.routes.delete(domain)) {
|
if (this.routes.delete(domain)) {
|
||||||
// Remove from SmartProxy (async but we don't wait)
|
await this.smartProxy.removeRoute(domain);
|
||||||
this.smartProxy.removeRoute(domain).catch((error) => {
|
|
||||||
logger.error(`Failed to remove SmartProxy route for ${domain}: ${getErrorMessage(error)}`);
|
|
||||||
});
|
|
||||||
logger.success(`Removed proxy route: ${domain}`);
|
logger.success(`Removed proxy route: ${domain}`);
|
||||||
} else {
|
} else {
|
||||||
logger.warn(`Route not found: ${domain}`);
|
logger.warn(`Route not found: ${domain}`);
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ export class OneboxServicesManager {
|
|||||||
// Remove reverse proxy route
|
// Remove reverse proxy route
|
||||||
if (service.domain) {
|
if (service.domain) {
|
||||||
try {
|
try {
|
||||||
this.oneboxRef.reverseProxy.removeRoute(service.domain);
|
await this.oneboxRef.reverseProxy.removeRoute(service.domain);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn(`Failed to remove reverse proxy route: ${getErrorMessage(error)}`);
|
logger.warn(`Failed to remove reverse proxy route: ${getErrorMessage(error)}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { logger } from '../logging.ts';
|
|||||||
import { getErrorMessage } from '../utils/error.ts';
|
import { getErrorMessage } from '../utils/error.ts';
|
||||||
|
|
||||||
const SMARTPROXY_SERVICE_NAME = 'onebox-smartproxy';
|
const SMARTPROXY_SERVICE_NAME = 'onebox-smartproxy';
|
||||||
|
const LEGACY_CADDY_SERVICE_NAME = 'onebox-caddy';
|
||||||
const SMARTPROXY_IMAGE = 'code.foss.global/host.today/ht-docker-smartproxy:latest';
|
const SMARTPROXY_IMAGE = 'code.foss.global/host.today/ht-docker-smartproxy:latest';
|
||||||
const SMARTPROXY_ADMIN_CONTAINER_PORT = 3000;
|
const SMARTPROXY_ADMIN_CONTAINER_PORT = 3000;
|
||||||
const SMARTPROXY_HTTP_CONTAINER_PORT = 80;
|
const SMARTPROXY_HTTP_CONTAINER_PORT = 80;
|
||||||
@@ -101,6 +102,13 @@ export class SmartProxyManager {
|
|||||||
|
|
||||||
logger.info('Starting SmartProxy Docker service...');
|
logger.info('Starting SmartProxy Docker service...');
|
||||||
|
|
||||||
|
const legacyService = await this.getExistingService(LEGACY_CADDY_SERVICE_NAME);
|
||||||
|
if (legacyService) {
|
||||||
|
logger.info('Legacy Caddy service exists, removing it before SmartProxy startup...');
|
||||||
|
await this.removeService(LEGACY_CADDY_SERVICE_NAME);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||||
|
}
|
||||||
|
|
||||||
const existingService = await this.getExistingService();
|
const existingService = await this.getExistingService();
|
||||||
if (existingService) {
|
if (existingService) {
|
||||||
logger.info('SmartProxy service exists, removing old service...');
|
logger.info('SmartProxy service exists, removing old service...');
|
||||||
@@ -180,9 +188,9 @@ export class SmartProxyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getExistingService(): Promise<any | null> {
|
private async getExistingService(serviceNameArg = SMARTPROXY_SERVICE_NAME): Promise<any | null> {
|
||||||
try {
|
try {
|
||||||
const response = await this.dockerClient!.request('GET', `/services/${SMARTPROXY_SERVICE_NAME}`, {});
|
const response = await this.dockerClient!.request('GET', `/services/${serviceNameArg}`, {});
|
||||||
if (response.statusCode === 200) {
|
if (response.statusCode === 200) {
|
||||||
return response.body;
|
return response.body;
|
||||||
}
|
}
|
||||||
@@ -192,9 +200,9 @@ export class SmartProxyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async removeService(): Promise<void> {
|
private async removeService(serviceNameArg = SMARTPROXY_SERVICE_NAME): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await this.dockerClient!.request('DELETE', `/services/${SMARTPROXY_SERVICE_NAME}`, {});
|
await this.dockerClient!.request('DELETE', `/services/${serviceNameArg}`, {});
|
||||||
} catch {
|
} catch {
|
||||||
// Service may not exist.
|
// Service may not exist.
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user