mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 08:23:12 +09:00
Fixed getMac spam in VMs, added log rotation
This commit is contained in:
1 parent
857a6824fc
commit
07b9d0a0f5
3 files changed
+27
-18
No files matched your search
@@ -52,4 +52,7 @@ sharedPlugins/*
|
|||||||
!sharedPlugins/globalChat/
|
!sharedPlugins/globalChat/
|
||||||
!sharedPlugins/clusterioMod/
|
!sharedPlugins/clusterioMod/
|
||||||
|
|
||||||
|
# File used for marking plugins as disabled
|
||||||
|
sharedPlugins/*/DISABLED
|
||||||
|
|
||||||
\.cache-require-paths\.json
|
\.cache-require-paths\.json
|
||||||
@@ -392,7 +392,7 @@ write-data=${ path.resolve(config.instanceDirectory, instance) }\r\n
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (command == "start" && typeof instance == "string" && instance != "/" && fs.existsSync(instancedirectory)){
|
} else if (command == "start" && typeof instance == "string" && instance != "/" && fs.existsSync(instancedirectory)){(async () => {
|
||||||
// Exit if no instance specified (it should be, just a safeguard);
|
// Exit if no instance specified (it should be, just a safeguard);
|
||||||
if(instancedirectory != config.instanceDirectory+"/undefined"){
|
if(instancedirectory != config.instanceDirectory+"/undefined"){
|
||||||
var instanceconfig = require(path.resolve(instancedirectory,'config'));
|
var instanceconfig = require(path.resolve(instancedirectory,'config'));
|
||||||
@@ -413,18 +413,21 @@ write-data=${ path.resolve(config.instanceDirectory, instance) }\r\n
|
|||||||
fs.unlinkSync(path.resolve(instancedirectory, "saves", savefiles[i]));
|
fs.unlinkSync(path.resolve(instancedirectory, "saves", savefiles[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("Deleting logs");
|
console.log("Clusterio | Rotating old logs...");
|
||||||
// clean old log file to avoid crash
|
// clean old log file to avoid crash
|
||||||
// file exists, delete so we don't get in trouble
|
try{
|
||||||
try {
|
let logPath = path.join(instancedirectory,'factorio-current.log');
|
||||||
fs.unlinkSync(path.join(instancedirectory,'factorio-current.log'));
|
let stat = await fs.stat(logPath);
|
||||||
} catch (err){
|
console.log(stat)
|
||||||
if(err){
|
console.log(stat.isFile())
|
||||||
console.error(err);
|
if(stat.isFile()){
|
||||||
} else {
|
let logFilename = `factorio-${Math.floor(Date.parse(stat.mtime)/1000)}.log`;
|
||||||
console.log("Clusterio | Deleting old logs...");
|
await fs.rename(logPath, path.join(instancedirectory, logFilename));
|
||||||
|
console.log(`Log rotated as ${logFilename}`);
|
||||||
}
|
}
|
||||||
}
|
}catch(e){}
|
||||||
|
// Math.floor(Date.now()/1000)
|
||||||
|
// (new Date).toGMTString()
|
||||||
|
|
||||||
// move mods from ./sharedMods to the instances mod directory
|
// move mods from ./sharedMods to the instances mod directory
|
||||||
try{fs.mkdirSync(path.join(instancedirectory, "instanceMods"));}catch(e){}
|
try{fs.mkdirSync(path.join(instancedirectory, "instanceMods"));}catch(e){}
|
||||||
@@ -508,7 +511,7 @@ write-data=${ path.resolve(config.instanceDirectory, instance) }\r\n
|
|||||||
|
|
||||||
client.onDidAuthenticate(() => {
|
client.onDidAuthenticate(() => {
|
||||||
console.log('Clusterio | RCON Authenticated!');
|
console.log('Clusterio | RCON Authenticated!');
|
||||||
instanceManagement(); // start using rcons
|
instanceManagement(instanceconfig); // start using rcons
|
||||||
});
|
});
|
||||||
client.onDidConnect(() => {
|
client.onDidConnect(() => {
|
||||||
console.log('Clusterio | RCON Connected!');
|
console.log('Clusterio | RCON Connected!');
|
||||||
@@ -522,13 +525,15 @@ write-data=${ path.resolve(config.instanceDirectory, instance) }\r\n
|
|||||||
console.log("Caught interrupt signal, disconnecting RCON");
|
console.log("Caught interrupt signal, disconnecting RCON");
|
||||||
client.disconnect().then(()=>{
|
client.disconnect().then(()=>{
|
||||||
console.log("Rcon disconnected, Sending ^C");
|
console.log("Rcon disconnected, Sending ^C");
|
||||||
// We don't actually do this, because ctrl+c in windows CMD sends it to all subprocesses as well. Doing it twice will abort factorios save.
|
// We don't actually do this on windows, because ctrl+c in windows CMD sends it to all subprocesses as well. Doing it twice will abort factorios save.
|
||||||
// serverprocess.kill("SIGINT");
|
if(process.platform == "linux"){
|
||||||
|
serverprocess.kill("SIGINT");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else if(process.platform == "linux"){
|
} else if(process.platform == "linux"){
|
||||||
// don't open an RCON connection and just use stdio instead, does not work on windows.
|
// don't open an RCON connection and just use stdio instead, does not work on windows.
|
||||||
instanceManagement();
|
instanceManagement(instanceconfig);
|
||||||
process.on('SIGINT', function () {
|
process.on('SIGINT', function () {
|
||||||
console.log("Caught interrupt signal, sending ^C");
|
console.log("Caught interrupt signal, sending ^C");
|
||||||
serverprocess.kill("SIGINT");
|
serverprocess.kill("SIGINT");
|
||||||
@@ -539,14 +544,14 @@ write-data=${ path.resolve(config.instanceDirectory, instance) }\r\n
|
|||||||
confirmedOrders = [];
|
confirmedOrders = [];
|
||||||
lastSignalCheck = Date.now();
|
lastSignalCheck = Date.now();
|
||||||
});
|
});
|
||||||
} else {
|
})()} else {
|
||||||
console.error("Invalid arguments, quitting.");
|
console.error("Invalid arguments, quitting.");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure instancemanagement only ever runs once
|
// ensure instancemanagement only ever runs once
|
||||||
_.once(instanceManagement);
|
_.once(instanceManagement);
|
||||||
async function instanceManagement() {
|
async function instanceManagement(instanceconfig) {
|
||||||
console.log("Started instanceManagement();");
|
console.log("Started instanceManagement();");
|
||||||
|
|
||||||
/* Open websocket connection to master */
|
/* Open websocket connection to master */
|
||||||
@@ -666,6 +671,7 @@ async function instanceManagement() {
|
|||||||
mac = "unknown";
|
mac = "unknown";
|
||||||
console.log("##### getMac crashed, but we don't really give a shit because we are probably closing down #####");
|
console.log("##### getMac crashed, but we don't really give a shit because we are probably closing down #####");
|
||||||
}
|
}
|
||||||
|
global.mac = mac;
|
||||||
payload.mac = mac;
|
payload.mac = mac;
|
||||||
// console.log("Registered our presence with master "+config.masterIP+" at " + payload.time);
|
// console.log("Registered our presence with master "+config.masterIP+" at " + payload.time);
|
||||||
needle.post(config.masterIP + ":" + config.masterPort + '/api/getID', payload, needleOptionsWithTokenAuthHeader, function (err, response, body) {
|
needle.post(config.masterIP + ":" + config.masterPort + '/api/getID', payload, needleOptionsWithTokenAuthHeader, function (err, response, body) {
|
||||||
|
|||||||
@@ -1078,7 +1078,7 @@ io.on('connection', function (socket) {
|
|||||||
if(terminatedConnections > 0) console.log("SOCKET | There are currently "+currentConnections+" websocket connections, deleting "+terminatedConnections+" on timeout");
|
if(terminatedConnections > 0) console.log("SOCKET | There are currently "+currentConnections+" websocket connections, deleting "+terminatedConnections+" on timeout");
|
||||||
|
|
||||||
// tell our friend that we are listening
|
// tell our friend that we are listening
|
||||||
setTimeout(()=>socket.emit('hello', { hello: 'world' }), 1000);
|
setTimeout(()=>socket.emit('hello', { hello: 'world' }), 5000);
|
||||||
|
|
||||||
/* initial processing for remoteMap */
|
/* initial processing for remoteMap */
|
||||||
socket.on('registerSlaveMapper', function (data) {
|
socket.on('registerSlaveMapper', function (data) {
|
||||||
|
|||||||
Reference in new issue
Block a user