diff --git a/config.json b/config.json new file mode 100644 index 0000000..9baadb0 --- /dev/null +++ b/config.json @@ -0,0 +1,11 @@ +{ + "applications":[{ + "path":"D:/shared/Builds/Fortis_UnStable_64/WindowsNoEditor/FORTIS_Taktika.exe", + "args":[ + "-maxfps=41", + "-PixelStreamingIP=127.0.0.1", + "-PixelStreamingPort=8888", + "-ResX 1920 -ResY 1080" + ] + }] +} \ No newline at end of file diff --git a/lib/logger.js b/lib/logger.js new file mode 100644 index 0000000..de7b5b0 --- /dev/null +++ b/lib/logger.js @@ -0,0 +1,34 @@ +const fs = require('fs') +const path = require('path') +const node_time = require('node-datetime') +const util = require('util') + +module.exports = class logger { + constructor(filepath) { + this.#filepath = filepath + this.#filename = path.basename(filepath) + var dirname = path.dirname(filepath) + + if (!fs.existsSync(dirname)) + fs.mkdirSync(dirname, {recursive:true}) + } + error(...arg) { + this.#log('error', arg) + } + log(...arg) { + this.#log('', arg) + } + + #log(message = '', ...arg) { + var args = '' + arg.forEach(value => { + args += util.format(value) + ' ' + }) + args = (node_time.create().format('Y-m-d H:M:S')).toString() + ((message != '') ? ': ' + message : '') + ': ' + args + console.log(this.#filename + ': ' + args) + fs.appendFileSync(this.#filepath, args + '\n') + } + + #filepath + #filename +} \ No newline at end of file diff --git a/restart_application.js b/restart_application.js new file mode 100644 index 0000000..f78c9e0 --- /dev/null +++ b/restart_application.js @@ -0,0 +1,26 @@ +const config = require('./config.json') +const logger = require('./lib/logger') +const { spawn } = require('node:child_process') + +const logger_runtime = new logger('./logs/runtime.log') +logger_runtime.log('start application') + +function start_proc(path, args) { + // start app_proc + const app_proc = spawn(path, args, { + detached: true + }) + app_proc.on('error', function(err) { + logger_runtime.error(err) + start_proc(path, args) + return + }) + app_proc.on('close', (code) => { + logger_runtime.error('code: ', code) + start_proc(path, args) + return + }) +} +config.applications.forEach(app => { + start_proc(app.path, app.args) +})