Skip to content

Commit

Permalink
auto restart on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed May 30, 2019
1 parent 71a7793 commit dd95438
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ One of the problems I noticed with the servers out there is that the "bases" are
- OneSync Support (more than 32 slots server)
- Linux Support
- Live Console
- Auto Restart on failure detection
- Auto Restart on schedule


## Installation
Expand All @@ -29,10 +31,11 @@ $ git clone https://github.com/tabarra/fivem-fxadmin
$ cd fivem-fxadmin
$ npm i
```
Copy your `server-template.json` to `server.json` and modify it according to your preferences.
- `buildPath` is the folder containing the files `run.cmd`, `fxserver.exe` and a bunch of DLLs in case of Windows, and only `run.sh` in case of Linux.
- `basePath` is the folder that **contains** the `resources` folder, usually it's here that you put your `server.cfg`.
- `cfgPath` is the absolute or relative path of your `server.cfg`.
Copy your `server-template.json` to `server.json` and modify it according to your preferences. The most important settings:
- `monitor.restarter.schedule` is the restart schedule. The time MUST be in the 24-hour format with two digits for hours as well as minutes (`HH:MM`). Leave the array empty or set it to false to disable the feature.
- `fxRunner.buildPath` is the folder containing the files `run.cmd`, `fxserver.exe` and a bunch of DLLs in case of Windows, and only `run.sh` in case of Linux.
- `fxRunner.basePath` is the folder that **contains** the `resources` folder, usually it's here that you put your `server.cfg`.
- `fxRunner.cfgPath` is the absolute or relative path of your `server.cfg`.

Do the same thing to your `admins-template.json`. To generate the hashed password, you can use tools like [this](https://www.browserling.com/tools/bcrypt) and [this](https://bcrypt-generator.com) or even [this one](https://passwordhashing.com/BCrypt).

Expand Down Expand Up @@ -72,7 +75,7 @@ $ npm i
- [x] Write some documentation
- [x] **Automatically check for updates (MUST)**
- [ ] Add hitch detection
- [ ] Auto restart on schedule (for the unstable servers out there)
- [x] Auto restart on schedule (for the unstable servers out there)
- [x] Auto restart if the monitor fails X times in the last Y seconds
- [x] Better error handling for the discord module

Expand Down
2 changes: 1 addition & 1 deletion src/components/authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = class Authenticator {
this.admins = [];
this.refreshAdmins();

//Função Cron
//Cron Function
setInterval(() => {
this.refreshAdmins();
}, this.config.refreshInterval);
Expand Down
16 changes: 12 additions & 4 deletions src/components/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ module.exports = class Monitor {
players: []
}

//Função Cron
//Cron functions
setInterval(() => {
this.refreshServerStatus();
this.refreshProcessStatus();
// logError("Data:\n"+JSON.stringify(this.getStatus(), null, 2));
}, this.config.interval);
if(Array.isArray(this.config.restarter.schedule)){
setInterval(() => {
this.checkRestartSchedule();
}, 1*1000);
}
}


Expand All @@ -33,7 +37,11 @@ module.exports = class Monitor {
* Check the restart schedule
*/
checkRestartSchedule(){

let now = new Date;
let currTime = now.getHours().toString().padStart(2, '0') + ':' + now.getMinutes().toString().padStart(2, '0');
if(this.config.restarter.schedule.includes(currTime)){
this.restartFXServer(`Scheduled restart at ${currTime}`);
}
}


Expand Down Expand Up @@ -113,7 +121,7 @@ module.exports = class Monitor {
} catch (error) {
this.failCounter++;
logWarn(`(Counter: ${this.failCounter}/${this.config.restarter.failures}) HealthCheck request error: ${error.message}`, context);
if(this.failCounter >= this.config.restarter.failures) this.restartFXServer('Failure Count Above Limit');
if(this.config.restarter !== false && this.failCounter >= this.config.restarter.failures) this.restartFXServer('Failure Count Above Limit');
this.statusServer = {
online: false,
ping: false,
Expand Down
5 changes: 0 additions & 5 deletions src/components/webConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ module.exports = class webConsole {
constructor(config) {
logOk('::Awaiting', context);
this.io = null;

//debug only
setInterval(() => {
//this.broadcast(Math.random().toString().repeat(Math.random()*3));
}, 700);
}


Expand Down
4 changes: 2 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "0.6.6",
"changelog": "Small verbosity fix and renamed configuration property. You will need to change fxServer to fxRunner in your server.json"
"version": "0.8.0",
"changelog": "Schedule/Failure Auto Restarter. You will need to copy server-template.json again. Modified the start command."
}

0 comments on commit dd95438

Please sign in to comment.