2022-09-25 01:31:59 -04:00
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
class Server {
|
|
|
|
constructor(dir) {
|
|
|
|
this.rootDir = dir;
|
|
|
|
this.name = dir.split('/').at(-1);
|
|
|
|
this.pidFilePath = this.rootDir + '/pid.txt';
|
|
|
|
|
|
|
|
// read version file
|
|
|
|
var versionFilePath = this.rootDir + '/current_version.txt';
|
2022-10-05 00:12:50 -04:00
|
|
|
if (fs.existsSync(versionFilePath)) {
|
|
|
|
this.version = fs.readFileSync(versionFilePath, {encoding:'utf8', flag:'r'});
|
|
|
|
}
|
2022-09-25 01:31:59 -04:00
|
|
|
|
|
|
|
// set server state
|
|
|
|
if (fs.existsSync(this.pidFilePath)) {
|
|
|
|
this.state = true;
|
|
|
|
} else {
|
|
|
|
this.state = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
console.log('Starting server...');
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
console.log('Stopping server...');
|
|
|
|
}
|
|
|
|
|
|
|
|
getPid() {
|
|
|
|
if (fs.existsSync(this.pidFilePath)) {
|
|
|
|
return fs.readFileSync(this.pidFilePath, {encoding:'utf8', flag:'r'})
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.Server = Server;
|