mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Cleanup old log files on Linux
This commit is contained in:
parent
0d9b6134b7
commit
1ebd0afe86
31
lib/logs.js
31
lib/logs.js
@ -12,6 +12,8 @@ var gamesLogFolder = {
|
||||
arma3_x64: 'Arma 3'
|
||||
}
|
||||
|
||||
var numberOfLogsToKeep = 20
|
||||
|
||||
var Logs = function (config) {
|
||||
this.config = config
|
||||
|
||||
@ -29,18 +31,16 @@ Logs.generateLogFileName = function (suffix) {
|
||||
}
|
||||
|
||||
Logs.prototype.delete = function (filename, callback) {
|
||||
callback = callback || function () {}
|
||||
|
||||
this.getLogFile(filename, function (err, logFile) {
|
||||
if (err) {
|
||||
if (callback) {
|
||||
return callback(err)
|
||||
}
|
||||
return callback(err)
|
||||
} else {
|
||||
if (logFile && logFile.path) {
|
||||
fs.unlink(logFile.path, callback)
|
||||
} else {
|
||||
if (callback) {
|
||||
return callback(new Error('File not found'))
|
||||
}
|
||||
return callback(new Error('File not found'))
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -141,6 +141,10 @@ Logs.prototype.logServerProcesses = function (serverProcess, headlessClientProce
|
||||
headlessClientProcesses.forEach(function (headlessClientProcess, idx) {
|
||||
self.logServerProcess(headlessClientProcess, 'hc_' + (idx + 1))
|
||||
})
|
||||
|
||||
if (this.config.type === 'linux') {
|
||||
this.cleanupOldLogFiles()
|
||||
}
|
||||
}
|
||||
|
||||
Logs.prototype.logServerProcess = function (serverProcess, suffix) {
|
||||
@ -178,4 +182,19 @@ Logs.prototype.logServerProcess = function (serverProcess, suffix) {
|
||||
})
|
||||
}
|
||||
|
||||
Logs.prototype.cleanupOldLogFiles = function () {
|
||||
var self = this
|
||||
|
||||
self.logFiles(function (err, files) {
|
||||
if (err) {
|
||||
return
|
||||
}
|
||||
|
||||
var oldLogFiles = files.slice(numberOfLogsToKeep)
|
||||
oldLogFiles.forEach(function (logFile) {
|
||||
self.delete(logFile.name)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = Logs
|
||||
|
Loading…
Reference in New Issue
Block a user