fix: clean up SmartProxy lifecycle

This commit is contained in:
2026-04-28 21:59:00 +00:00
parent c5d9158078
commit 5cb6895a14
5 changed files with 19 additions and 11 deletions
+3
View File
@@ -435,6 +435,9 @@ export class Onebox {
// Stop proxy log receiver
await this.proxyLogReceiver.stop();
// Stop built-in registry and backing smartstorage server
await this.registry.stop();
// Close backup archive
await this.backupManager.close();
+2 -5
View File
@@ -130,12 +130,9 @@ export class OneboxReverseProxy {
/**
* Remove a route
*/
removeRoute(domain: string): void {
async removeRoute(domain: string): Promise<void> {
if (this.routes.delete(domain)) {
// Remove from SmartProxy (async but we don't wait)
this.smartProxy.removeRoute(domain).catch((error) => {
logger.error(`Failed to remove SmartProxy route for ${domain}: ${getErrorMessage(error)}`);
});
await this.smartProxy.removeRoute(domain);
logger.success(`Removed proxy route: ${domain}`);
} else {
logger.warn(`Route not found: ${domain}`);
+1 -1
View File
@@ -354,7 +354,7 @@ export class OneboxServicesManager {
// Remove reverse proxy route
if (service.domain) {
try {
this.oneboxRef.reverseProxy.removeRoute(service.domain);
await this.oneboxRef.reverseProxy.removeRoute(service.domain);
} catch (error) {
logger.warn(`Failed to remove reverse proxy route: ${getErrorMessage(error)}`);
}
+12 -4
View File
@@ -10,6 +10,7 @@ import { logger } from '../logging.ts';
import { getErrorMessage } from '../utils/error.ts';
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_ADMIN_CONTAINER_PORT = 3000;
const SMARTPROXY_HTTP_CONTAINER_PORT = 80;
@@ -101,6 +102,13 @@ export class SmartProxyManager {
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();
if (existingService) {
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 {
const response = await this.dockerClient!.request('GET', `/services/${SMARTPROXY_SERVICE_NAME}`, {});
const response = await this.dockerClient!.request('GET', `/services/${serviceNameArg}`, {});
if (response.statusCode === 200) {
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 {
await this.dockerClient!.request('DELETE', `/services/${SMARTPROXY_SERVICE_NAME}`, {});
await this.dockerClient!.request('DELETE', `/services/${serviceNameArg}`, {});
} catch {
// Service may not exist.
}