58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
/**
|
|
* Daemon Manager
|
|
* Manages the background mailer service
|
|
*/
|
|
|
|
import { SmtpServer } from '../mail/delivery/placeholder.ts';
|
|
import { ApiServer } from '../api/api-server.ts';
|
|
import { ConfigManager } from '../config/config-manager.ts';
|
|
|
|
export class DaemonManager {
|
|
private smtpServer: SmtpServer | null = null;
|
|
private apiServer: ApiServer | null = null;
|
|
private configManager: ConfigManager;
|
|
|
|
constructor() {
|
|
this.configManager = new ConfigManager();
|
|
}
|
|
|
|
/**
|
|
* Start the daemon
|
|
*/
|
|
async start(): Promise<void> {
|
|
console.log('[Daemon] Starting mailer daemon...');
|
|
|
|
// Load configuration
|
|
const config = await this.configManager.load();
|
|
|
|
// Start SMTP server
|
|
this.smtpServer = new SmtpServer({ port: config.smtpPort, hostname: config.hostname });
|
|
await this.smtpServer.start();
|
|
|
|
// Start API server
|
|
this.apiServer = new ApiServer({ port: config.apiPort, apiKeys: config.apiKeys });
|
|
await this.apiServer.start();
|
|
|
|
console.log('[Daemon] Mailer daemon started successfully');
|
|
console.log(`[Daemon] SMTP server: ${config.hostname}:${config.smtpPort}`);
|
|
console.log(`[Daemon] API server: http://${config.hostname}:${config.apiPort}`);
|
|
}
|
|
|
|
/**
|
|
* Stop the daemon
|
|
*/
|
|
async stop(): Promise<void> {
|
|
console.log('[Daemon] Stopping mailer daemon...');
|
|
|
|
if (this.smtpServer) {
|
|
await this.smtpServer.stop();
|
|
}
|
|
|
|
if (this.apiServer) {
|
|
await this.apiServer.stop();
|
|
}
|
|
|
|
console.log('[Daemon] Mailer daemon stopped');
|
|
}
|
|
}
|