37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { UdpServer } from "../network/udp/udp_server";
|
|
import { TcpServer } from "../network/tcp/tcp_server";
|
|
|
|
let udpServer: UdpServer | null
|
|
let tcpServer: TcpServer | null
|
|
|
|
// Retrieve data from environment variables
|
|
const USER_UDP_PORT = parseInt(process.env.USER_UDP_PORT || '0', 10);
|
|
const USER_TCP_PORT = parseInt(process.env.USER_TCP_PORT || '0', 10);
|
|
const HOST = process.env.HOST || '';
|
|
|
|
// Initialize and start the servers
|
|
udpServer = new UdpServer(HOST, USER_UDP_PORT);
|
|
udpServer.start();
|
|
|
|
tcpServer = new TcpServer(HOST, USER_TCP_PORT);
|
|
tcpServer.start();
|
|
|
|
process.on('SIGTERM', async () => {
|
|
console.log('Received SIGTERM. Cleaning up...');
|
|
await cleanupAndExit();
|
|
});
|
|
|
|
process.on('SIGINT', async () => {
|
|
console.log('Received SIGINT. Cleaning up...');
|
|
await cleanupAndExit();
|
|
});
|
|
|
|
async function cleanupAndExit() {
|
|
// Perform any cleanup, such as closing connections, saving data, etc.
|
|
// Example: if you have a server instance running, you may want to close it:
|
|
// await server.close();
|
|
|
|
console.log('Cleanup complete. Exiting.');
|
|
process.exit(0); // Exit with code 0 to indicate a clean exit
|
|
}
|