diff --git a/.gitignore b/.gitignore index 413c0ae..ef7d308 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules package-lock.json sessions.json client_sessions.json +center_sessions.json diff --git a/main.js b/main.js index 15d5a83..b412c14 100644 --- a/main.js +++ b/main.js @@ -345,11 +345,6 @@ class ClientSessionManager { constructor() { this.sessions = {}; - process.on('exit', this.cleanup.bind(this)); - process.on('SIGINT', this.cleanup.bind(this)); - process.on('SIGUSR1', this.cleanup.bind(this)); - process.on('SIGUSR2', this.cleanup.bind(this)); - process.on('uncaughtException', this.cleanup.bind(this)); } createSession(url, username, password) { @@ -392,7 +387,6 @@ class ClientSessionManager { cleanup() { this.logger.log1(`Saving sessions to ${CLIENT_SESSIONS_FILE}...`); fs.writeFileSync(CLIENT_SESSIONS_FILE, JSON.stringify(this.serialize(), null, 4)); - process.exit(0); } startup() { @@ -620,11 +614,6 @@ class CenterSessionManager { constructor() { this.servers = {}; - process.on('exit', this.cleanup.bind(this)); - process.on('SIGINT', this.cleanup.bind(this)); - process.on('SIGUSR1', this.cleanup.bind(this)); - process.on('SIGUSR2', this.cleanup.bind(this)); - process.on('uncaughtException', this.cleanup.bind(this)); } createSession(port, username, password) { @@ -666,7 +655,6 @@ class CenterSessionManager { cleanup() { this.logger.log1(`Saving sessions to ${CENTER_SESSIONS_FILE}...`); fs.writeFileSync(CENTER_SESSIONS_FILE, JSON.stringify(this.serialize(), null, 4)); - process.exit(0); } startup() { @@ -1089,4 +1077,16 @@ let session = clientSessionManager.createSession('smpp://localhost:7001', 'test' session.connect().then(() => session.bind()); new WSServer(); -new HTTPServer(); \ No newline at end of file +new HTTPServer(); + +function cleanup() { + clientSessionManager.cleanup(); + centerSessionManager.cleanup(); + process.exit(0); +} + +process.on('exit', cleanup); +process.on('SIGINT', cleanup); +process.on('SIGUSR1', cleanup); +process.on('SIGUSR2', cleanup); +process.on('uncaughtException', cleanup); \ No newline at end of file