Date string update, midnight timer update, other stuff

This commit is contained in:
MrFry 2020-04-07 15:00:39 +02:00
parent c764c4f402
commit dbb23a6724
6 changed files with 92 additions and 61 deletions

View file

@ -61,6 +61,7 @@ process.on('SIGTERM', () => exit('SIGTERM'))
process.on('SIGTERM', () => exit('SIGTERM'))
function exit (reason) {
console.log()
logger.Log(`Exiting, reason: ${reason}`)
Object.keys(modules).forEach((k, i) => {
const x = modules[k]
@ -134,25 +135,24 @@ if (startHTTPS && utils.FileExists(privkeyFile) && utils.FileExists(fullchainFil
}
}
setLogTimer()
function setLogTimer () {
const d = new Date()
const h = new Date(
d.getFullYear(),
d.getMonth(),
d.getDate() + 1,
0,
0,
0,
0
const now = new Date()
const night = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate() + 1, // the next day, ...
0, 0, 0 // ...at 00:00:00 hours
)
const e = h - d
const msToMidnight = night.getTime() - now.getTime()
if (e > 100) {
setTimeout(setLogTimer, e)
} else {
logger.Log('Log timer malfunction :/', logger.GetColor('redbg'))
}
setTimeout(function () {
LogTimerAction()
setLogTimer()
}, msToMidnight)
}
function LogTimerAction () {
Object.keys(modules).forEach((k, i) => {
const x = modules[k]
if (x.dailyAction) {
@ -171,8 +171,6 @@ function setLogTimer () {
utils.AppendToFile(line, allLogFile)
}
setLogTimer()
logger.Log('Node version: ' + process.version)
logger.Log('Current working directory: ' + process.cwd())
logger.Log('Listening on port: ' + port)