From 5d0ff1386a9b27f9bd366f8d4db6c50d16d6aa46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 14 Oct 2012 17:58:13 +0200 Subject: [PATCH] Cleanup before shutdown --- .../be.bastelstu.wcf.chat.nodePush/lib/server.coffee | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/file/acp/be.bastelstu.wcf.chat.nodePush/lib/server.coffee b/file/acp/be.bastelstu.wcf.chat.nodePush/lib/server.coffee index 29554c0..6dfdb43 100644 --- a/file/acp/be.bastelstu.wcf.chat.nodePush/lib/server.coffee +++ b/file/acp/be.bastelstu.wcf.chat.nodePush/lib/server.coffee @@ -30,6 +30,11 @@ class Server @initUnixSocket() @initSocketIO() + process.on 'exit', @shutdown.bind @ + process.on 'uncaughtException', @shutdown.bind @ + process.on 'SIGINT', @shutdown.bind @ + process.on 'SIGTERM', @shutdown.bind @ + setInterval (() -> @socket.sockets.emit 'newMessage' ).bind(@), 60e3 @@ -58,5 +63,11 @@ class Server socket.listen process.cwd() + '/../data.sock' fs.chmod process.cwd() + '/../data.sock', '777' + shutdown: () -> + return unless fs.existsSync process.cwd() + '/../data.sock' + + log 'Shutting down' + fs.unlinkSync process.cwd() + '/../data.sock' + process.exit() new Server() \ No newline at end of file