Added some rudimentary server info
This commit is contained in:
parent
c4286373e3
commit
13e730df7b
38
app/MinecraftServer.js
Normal file
38
app/MinecraftServer.js
Normal file
@ -0,0 +1,38 @@
|
||||
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';
|
||||
this.version = fs.readFileSync(versionFilePath, {encoding:'utf8', flag:'r'});
|
||||
|
||||
// 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;
|
@ -1,5 +1,8 @@
|
||||
const minecraft = require('../app/MinecraftServer');
|
||||
|
||||
exports.getIndex = function(req, res) {
|
||||
var server = new minecraft.Server('/opt/minecraft/bg_w3');
|
||||
res.render('index', {
|
||||
servers: [],
|
||||
servers: [server],
|
||||
});
|
||||
};
|
||||
|
@ -22,9 +22,9 @@ block content
|
||||
tbody
|
||||
each m in servers
|
||||
tr.serverItem
|
||||
td.serverName m.name
|
||||
td.serverVersion m.version
|
||||
td.serverState m.state
|
||||
td.serverName= m.name
|
||||
td.serverVersion= m.version
|
||||
td.serverState= m.state
|
||||
td
|
||||
a(href="/server/#{server.name}/start") Start
|
||||
a(href="/server/#{server.name}/stop") Stop
|
||||
a(href='/server/' + m.name + '/start') Start
|
||||
a(href='/server/' + m.name + '/stop') Stop
|
||||
|
Loading…
Reference in New Issue
Block a user