forked from Hypfer/Valetudo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
36 lines (30 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const Valetudo = require("./lib/Valetudo");
const process = require("process");
const Logger = require("./lib/Logger");
var valetudo = new Valetudo();
process.on("unhandledRejection", error => {
Logger.error("unhandledRejection", error);
});
async function shutdown() {
try {
await valetudo.shutdown();
// need to exit here because otherwise the process would stay open
process.exit(0);
} catch (err) {
Logger.error("Error occured: ", err.name, " - ", err.message);
Logger.error(err.stack);
process.exit(1);
}
}
// Signal termination handler - used if the process is killed
// (e.g. kill command, service valetudo stop, reboot (via upstart),...)
process.on("SIGTERM", shutdown);
// Signal interrupt handler -
// e.g. if the process is aborted by Ctrl + C (during dev)
process.on("SIGINT", shutdown);
process.on("exit", function(code) {
Logger.info("exiting with code " + code + "...");
if (code !== 0) {
Logger.error("Stacktrace that lead to the process exiting:", new Error().stack);
}
});