Clear storage folder after successful start and graceful exit

This commit is contained in:
Pavel Djundik 2017-12-18 16:58:43 +02:00
parent ada870e959
commit c06fb9a275
2 changed files with 13 additions and 0 deletions

View file

@ -9,7 +9,9 @@ const helper = require("../helper");
class Storage {
constructor() {
this.references = new Map();
}
emptyDir() {
// Ensures that a directory is empty.
// Deletes directory contents if the directory is not empty.
// If the directory does not exist, it is created.

View file

@ -146,6 +146,12 @@ module.exports = function() {
return;
}
if (Helper.config.prefetchStorage) {
log.info("Clearing prefetch storage folder, this might take a while...");
require("./plugins/storage").emptyDir();
}
// Forcefully exit after 3 seconds
suicideTimeout = setTimeout(() => process.exit(1), 3000);
@ -163,6 +169,11 @@ module.exports = function() {
process.on("SIGINT", exitGracefully);
process.on("SIGTERM", exitGracefully);
// Clear storage folder after server starts successfully
if (Helper.config.prefetchStorage) {
require("./plugins/storage").emptyDir();
}
});
return server;