Skip to content

Commit

Permalink
Added partial crash detection and fixed interval
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Sep 1, 2019
1 parent ff3b0bf commit 436f78c
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 36 deletions.
3 changes: 3 additions & 0 deletions locale/cs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$label": "Czech",
"restarter": {
"crash_detected": "pád detekován",
"partial_crash_warn": "Due to a partial crash, this server will restart in 1 minute. Please disconnect now.",
"partial_crash_warn_discord": "Due to a partial crash, **%{servername}** will restart in 1 minute.",
"schedule_reason": "plánovaný restart v %{time}",
"schedule_warn": "Tento server má naplánovaný restart za %{smart_count} minutu. Prosím odpojte se nyní. |||| Tento server má naplánovaný restart za %{smart_count} minut.",
"schedule_warn_discord": "**%{servername}** má naplánovabý restart za %{smart_count} minutu. |||| **%{servername}** má naplánovaný restart za %{smart_count} minut."
Expand Down
3 changes: 3 additions & 0 deletions locale/da.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$label": "Danish",
"restarter": {
"crash_detected": "crash opdaget",
"partial_crash_warn": "Due to a partial crash, this server will restart in 1 minute. Please disconnect now.",
"partial_crash_warn_discord": "Due to a partial crash, **%{servername}** will restart in 1 minute.",
"schedule_reason": "planlagt genstart %{time}",
"schedule_warn": "Serveren genstarter om %{smart_count} minut. Vær venlig at disconnecte nu. |||| Serveren genstarter om %{smart_count} minutter.",
"schedule_warn_discord": "**%{servername}** genstarter om %{smart_count} minut. |||| **%{servername}** genstarter om %{smart_count} minutter."
Expand Down
3 changes: 3 additions & 0 deletions locale/de.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$label": "German",
"restarter": {
"crash_detected": "Absturz erkannt",
"partial_crash_warn": "Due to a partial crash, this server will restart in 1 minute. Please disconnect now.",
"partial_crash_warn_discord": "Due to a partial crash, **%{servername}** will restart in 1 minute.",
"schedule_reason": "Geplanter Neustart um %{time}",
"schedule_warn": "Der Server wird in %{smart_count} Minute neugestartet. Bitte trenne die Verbindung jetzt. |||| Der Server wird in %{smart_count} Minuten neu gestartet.",
"schedule_warn_discord": "**%{servername}** wird in %{smart_count} neugestartet. |||| **%{servername}** wird in %{smart_count} Minuten neu gestartet."
Expand Down
3 changes: 3 additions & 0 deletions locale/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$label": "English",
"restarter": {
"crash_detected": "crash detected",
"partial_crash_warn": "Due to a partial crash, this server will restart in 1 minute. Please disconnect now.",
"partial_crash_warn_discord": "Due to a partial crash, **%{servername}** will restart in 1 minute.",
"schedule_reason": "scheduled restart at %{time}",
"schedule_warn": "This server is scheduled to restart in %{smart_count} minute. Please disconnect now. |||| This server is scheduled to restart in %{smart_count} minutes.",
"schedule_warn_discord": "**%{servername}** is scheduled to restart in %{smart_count} minute. |||| **%{servername}** is scheduled to restart in %{smart_count} minutes."
Expand Down
3 changes: 3 additions & 0 deletions locale/es.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$label": "Spanish",
"restarter": {
"crash_detected": "Crash detectado",
"partial_crash_warn": "Due to a partial crash, this server will restart in 1 minute. Please disconnect now.",
"partial_crash_warn_discord": "Due to a partial crash, **%{servername}** will restart in 1 minute.",
"schedule_reason": "Reinicio programado a las %{time}",
"schedule_warn": "El servidor se va a reiniciar en %{smart_count} minuto. Porfavor desconectate. |||| El servidor se va a reiniciar en %{smart_count} minutos.",
"schedule_warn_discord": "**%{servername}** El servidor se va a reiniciar en %{smart_count} minuto. |||| **%{servername}** El servidor se va a reiniciar en %{smart_count} minutos."
Expand Down
3 changes: 3 additions & 0 deletions locale/fr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$label": "French",
"restarter": {
"crash_detected": "le serveur a planté",
"partial_crash_warn": "Due to a partial crash, this server will restart in 1 minute. Please disconnect now.",
"partial_crash_warn_discord": "Due to a partial crash, **%{servername}** will restart in 1 minute.",
"schedule_reason": "redémarage prévu à %{time}",
"schedule_warn": "Le serveur redémarrera dans %{smart_count} minute. Merci de vous déconnecter. |||| Le serveur redémarrera dans %{smart_count} minutes.",
"schedule_warn_discord": "**%{servername}** redémarrera dans %{smart_count} minute. |||| **%{servername}** redémarrera dans %{smart_count} minutes."
Expand Down
3 changes: 3 additions & 0 deletions locale/hu.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$label": "Hungarian",
"restarter": {
"crash_detected": "crash észlelve",
"partial_crash_warn": "Due to a partial crash, this server will restart in 1 minute. Please disconnect now.",
"partial_crash_warn_discord": "Due to a partial crash, **%{servername}** will restart in 1 minute.",
"schedule_reason": "ütemezett újraindítás %{time}",
"schedule_warn": "A szerver ütemezett újrainditása lesz %{smart_count} perc múlva. Lépjetek le. |||| A szerver ütemezett újrainditása lesz %{smart_count} perc múlva.",
"schedule_warn_discord": "**%{servername}** szerver ütemezett újrainditása lesz %{smart_count} perc múlva. |||| **%{servername}** szerver ütemezett újrainditása lesz %{smart_count} perc múlva."
Expand Down
3 changes: 3 additions & 0 deletions locale/nl.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$label": "Dutch",
"restarter": {
"crash_detected": "Crash geconstateerd",
"partial_crash_warn": "Due to a partial crash, this server will restart in 1 minute. Please disconnect now.",
"partial_crash_warn_discord": "Due to a partial crash, **%{servername}** will restart in 1 minute.",
"schedule_reason": "Geplande restart om %{time}",
"schedule_warn": "De server staat gepland om over %{smart_count} minuut te herstarten. Verlaat de server. |||| De server staat gepland voor een restart over %{smart_count} minuten.",
"schedule_warn_discord": "**%{servername}** staat gepland om over %{smart_count} minuut te herstarten. |||| **%{servername}** staat gepland voor een restart over %{smart_count} minuten."
Expand Down
3 changes: 3 additions & 0 deletions locale/pl.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$label": "Polish",
"restarter": {
"crash_detected": "Wykryty Crash",
"partial_crash_warn": "Due to a partial crash, this server will restart in 1 minute. Please disconnect now.",
"partial_crash_warn_discord": "Due to a partial crash, **%{servername}** will restart in 1 minute.",
"schedule_reason": "Planowany restart o %{time}",
"schedule_warn": "Ten serwer ma zaplanowany restart w ciągu %{smart_count} minuty. Proszę opuścić serwer. |||| Ten serwer ma zaplanowany restart w ciągu %{smart_count} minut.",
"schedule_warn_discord": "**%{servername}** ma zaplanowany restart w ciągu %{smart_count} minuty. |||| **%{servername}** ma zaplanowany restart w ciągu %{smart_count} minut."
Expand Down
3 changes: 3 additions & 0 deletions locale/pt_BR.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$label": "Portuguese (Brazil)",
"restarter": {
"crash_detected": "crash detectado",
"partial_crash_warn": "Devido a um crash parcial, este servidor será reiniciado em 1 minuto. Por favor se disconecte agora.",
"partial_crash_warn_discord": "Devido a um crash parcial, **%{servername}** será reiniciado em 1 minuto.",
"schedule_reason": "agendado para %{time}",
"schedule_warn": "Este servidor está agendado para reiniciar em %{smart_count} minuto. Por favor se disconecte agora. |||| Este servidor está agendado para reiniciar em %{smart_count} minutos.",
"schedule_warn_discord": "**%{servername}** está agendado para reiniciar em %{smart_count} minuto. |||| **%{servername}** está agendado para reiniciar em %{smart_count} minutos."
Expand Down
3 changes: 3 additions & 0 deletions locale/ro.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$label": "Romanian",
"restarter": {
"crash_detected": "crash detectat",
"partial_crash_warn": "Due to a partial crash, this server will restart in 1 minute. Please disconnect now.",
"partial_crash_warn_discord": "Due to a partial crash, **%{servername}** will restart in 1 minute.",
"schedule_reason": "restartare programata la %{time}",
"schedule_warn": "Acest server este programat sa se restarteze in %{smart_count} minut. Va rugam sa va deconctati. |||| Acest server este programat sa se restarteze in %{smart_count} minute.",
"schedule_warn_discord": "**%{servername}** este programat sa se restarteze in %{smart_count} minut. |||| **%{servername}** este programat sa se restarteze in %{smart_count} minute."
Expand Down
3 changes: 3 additions & 0 deletions locale/zh.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$label": "Chinese",
"restarter": {
"crash_detected": "伺服器被檢測到已癱瘓",
"partial_crash_warn": "Due to a partial crash, this server will restart in 1 minute. Please disconnect now.",
"partial_crash_warn_discord": "Due to a partial crash, **%{servername}** will restart in 1 minute.",
"schedule_reason": "預定 %{time}重啟",
"schedule_warn": "此伺服器計劃 %{smart_count} 分鐘後重新啟動, 請立即斷開連接。 |||| 此伺服器計劃 %{smart_count} 分鐘後重新啟動。",
"schedule_warn_discord": "**%{servername}** 計劃 %{smart_count} 分鐘後重新啟動。 |||| **%{servername}** 計劃 %{smart_count} 分鐘後重新啟動。"
Expand Down
2 changes: 0 additions & 2 deletions src/components/configVault.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ module.exports = class ConfigVault {
logPath: toDefault(cfg.logger.logPath, null), //not in template
};
out.monitor = {
interval: toDefault(cfg.monitor.interval, null), //not in template
timeout: toDefault(cfg.monitor.timeout, null),
restarter: {
cooldown: toDefault(cfg.monitor.restarter.cooldown, null), //not in template
Expand Down Expand Up @@ -181,7 +180,6 @@ module.exports = class ConfigVault {
cfg.logger.logPath = cfg.logger.logPath || `${this.serverProfilePath}/logs/admin.log`; //not in template

//Monitor
cfg.monitor.interval = parseInt(cfg.monitor.interval) || 1000; //not in template
cfg.monitor.timeout = parseInt(cfg.monitor.timeout) || 1000;
cfg.monitor.restarter.cooldown = parseInt(cfg.monitor.restarter.cooldown) || 60; //not in template
cfg.monitor.restarter.failures = parseInt(cfg.monitor.restarter.failures) || 30;
Expand Down
5 changes: 3 additions & 2 deletions src/components/fxRunner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ module.exports = class FXRunner {
//Sending header to the console buffer
this.consoleBuffer.writeHeader();

//Resseting hitch counter
globals.monitor.clearFXServerHitches();

//Announcing
if(announce === 'true' | announce === true){
let discordMessage = globals.translator.t('server_actions.spawning_discord', {servername: globals.config.serverName});
Expand Down Expand Up @@ -167,7 +170,6 @@ module.exports = class FXRunner {
this.fxChild.stderr.on('error', (data) => {});
this.fxChild.stderr.on('data', this.consoleBuffer.writeError.bind(this.consoleBuffer));


//Setting up process priority
setTimeout(() => {
this.setProcPriority();
Expand Down Expand Up @@ -286,7 +288,6 @@ module.exports = class FXRunner {
this.killServer();
await sleep(750);
this.spawnServer();
globals.monitor.clearFXServerHitches()
} catch (error) {
logError("Couldn't restart the server.", context);
if(globals.config.verbose) dir(error);
Expand Down
34 changes: 16 additions & 18 deletions src/components/monitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ module.exports = class Monitor {
logError('The monitor.restarter.cooldown setting must be 15 seconds or more.', context);
process.exit();
}
if(this.config.interval < 1000){
logError('The monitor.interval setting must be 1000 milliseconds or more.', context);
process.exit();
}
if(
this.config.restarter.failures !== -1 &&
this.config.restarter.failures * this.config.interval < 15000
){
if(this.config.restarter.failures < 15){
logError('The monitor.restarter.failures setting must be 15 seconds or more.', context);
process.exit();
}
Expand All @@ -47,9 +40,9 @@ module.exports = class Monitor {
this.buildSchedule();

//Cron functions
this.cronFunc = setInterval(() => {
setInterval(() => {
this.refreshServerStatus();
}, this.config.interval);
}, 1000);
setInterval(() => {
this.checkRestartSchedule();
}, 60*1000);
Expand All @@ -63,12 +56,6 @@ module.exports = class Monitor {
refreshConfig(){
this.config = globals.configVault.getScoped('monitor');
this.buildSchedule();

//Reset Cron functions
clearInterval(this.cronFunc);
this.cronFunc = setInterval(() => {
this.refreshServerStatus();
}, this.config.interval);
}//Final refreshConfig()


Expand Down Expand Up @@ -226,8 +213,19 @@ module.exports = class Monitor {
'crash detected',
globals.translator.t('restarter.crash_detected')
);
}else if(this.failCounter === 60*2){ //after 4 minutes
let tOptions = {
servername: globals.config.serverName
}
globals.discordBot.sendAnnouncement(globals.translator.t('restarter.partial_crash_warn_discord', tOptions));
let chatMsg = globals.translator.t('restarter.partial_crash_warn')
globals.fxRunner.srvCmd(`txaBroadcast "${chatMsg}"`);
}else if(this.failCounter === 60*3){ //after 5 minutes
this.restartFXServer(
'partial crash detected',
globals.translator.t('restarter.crash_detected')
);
}else{
//TODO: restart anyway after 10 minutes?
if(globals.config.verbose) logWarn(`Above restarter limit for HealthCheck failures. Skipping restart since last HeartBeat was less than 30s ago.`);
}
}
Expand Down Expand Up @@ -284,7 +282,7 @@ module.exports = class Monitor {
try {
const res = await axios(requestOptions);
players = res.data;
if(!Array.isArray(players)) throw new Error("FXServer's players endpoint didnt return a JSON array.")
if(!Array.isArray(players)) throw new Error("FXServer's players endpoint didnt return a JSON array.");
} catch (error) {
this.handleFailure(error.message);
this.statusServer = {
Expand Down
24 changes: 12 additions & 12 deletions src/components/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ module.exports = class Translator {
//NOTE: this "protection" is to incentivize users to modify the git-untracked `locale/custom.json` file.
// since modifying any other file will result in the user not being able to update txAdmin just by typing `git pull`.
let langHashes = {
en: '1b514b088a5ee7015b0f0d0ae0319b7b2a6aff0d', //english
zh: '11857d2ba76952c488c3920d646f1e2ebd9d3537', //chinese
cs: 'b7e867715b628815e23d9dc0761e90301eb74d41', //czech
da: '98a2dad93e3cf19ab52f5b0aa17a9ea1c3c1cbcd', //danish
nl: 'ec074d2281f059b1280984776c0fe57cf480d0d4', //dutch
fr: 'eaa6f1250a483b03d0c9c698ea2700d113e81896', //french
de: 'dc2266978063b4e81632086049c633ae63fffcaa', //german
hu: 'c28b5a084cbcad7be0a60c87c8f5b24b999752e2', //hungarian
pl: '522cc363a86fc089d04972f1194abed3926ffd98', //polish
pt_BR: 'a55fd4cf965097108502860204f5f5abc2ed6e7f', //portuguese
ro: '77c2a2b46af30859cdc8113df8917a607dbe7f35', //romanian
es: '73db20da35fc2b38f931dff57b2a9e8d47435b1a', //spanish
cs: 'bb9e29c2f813df128d2526aa4f3b41c509778b9a', //Czech
da: 'f4ed0196724d77e2b3e02a7f5fc5064e174939ff', //Danish
de: '0afd698733c22dbd78793c861f09faf7bde393b6', //German
en: '22aa51b1157b6f6fa7f712ddac5a78587084f43c', //English
es: '6703e2293338888fd485325e03c979325328d461', //Spanish
fr: '87e710bfc0cca31f7159a736b4c74d49c9c1f6f9', //French
hu: '0cc944270bc6ea924faa4900dccde33d2651bb7f', //Hungarian
nl: '4b3269c8b8644dad0f17ac3b5f1a8986590358c2', //Dutch
pl: '7b54962c37b3f8befc7dcfab10c5a5c93b9e505f', //Polish
pt_BR: '39136e5996e6ff4b6090c4e0a5759f21dc3c56d2', //Portuguese (Brazil)
ro: '7cb38638a83349485bb0c2389f35adc7ec168b24', //Romanian
zh: 'dd93a6fe7bfbbcdf99c2d239fc9be25b409a5a83', //Chinese
}
let hash = null;
try {
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/config-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const bytes = require('bytes');
const { dir, log, logOk, logWarn, logError, cleanTerminal } = require('../extras/console');
cleanTerminal()
const printDivider = () =>{log('='.repeat(64))};
const context = 'ConfigTester';
const context = 'ConfigTesterScript';

//Print usage info
printDivider();
Expand Down
33 changes: 33 additions & 0 deletions src/scripts/hash-locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//Requires
const fs = require('fs-extra');
const crypto = require('crypto');
const { dir, log, logOk, logWarn, logError, cleanTerminal } = require('../extras/console');
cleanTerminal()
const context = 'HashLocale';


(async()=>{
let localeFolder = './locale/';
var langFiles = await fs.readdir(localeFolder);
let out = [];
langFiles.forEach((fileName)=>{
let lang = fileName.replace(/\.json/g, '');
if(lang === 'custom') return;
let hash;
let label;
try {
let raw = fs.readFileSync(`${localeFolder}/${lang}.json`, 'utf8');
let langData = JSON.parse(raw);
let toHash = JSON.stringify(langData);
hash = crypto.createHash('SHA1').update(toHash).digest("hex");
label = (typeof langData['$label'] !== 'undefined')? langData['$label'] : fileName;
out.push(`${lang}: '${hash}', //${label}`);
} catch (error) {
logError(`Couldn't hash file ${fileName}`, context);
dir(error)
}
});

log('Locale hashes:');
console.log(out.join("\n"));
})();
2 changes: 1 addition & 1 deletion src/scripts/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const ac = require('ansi-colors');
ac.enabled = require('color-support').hasBasic;
const { dir, log, logOk, logWarn, logError, cleanTerminal } = require('../extras/console');
cleanTerminal()
const context = 'Setup';
const context = 'SetupScript';
const printDivider = () => { log('='.repeat(64), context) };


Expand Down

0 comments on commit 436f78c

Please sign in to comment.