puppyperpetual 1.2.7 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ConfigManager.js +4 -2
- package/src/ProcessManager.js +52 -5
package/package.json
CHANGED
package/src/ConfigManager.js
CHANGED
|
@@ -12,7 +12,7 @@ export class ConfigManager {
|
|
|
12
12
|
const __dirname = path.dirname(__filename);
|
|
13
13
|
|
|
14
14
|
this.defaultConfigPath = path.join(__dirname, 'defaultconfig.yaml');
|
|
15
|
-
this.configPath = path.join(
|
|
15
|
+
this.configPath = path.join(perpConfigLocation);
|
|
16
16
|
|
|
17
17
|
if (!noYAML) {
|
|
18
18
|
this.ensureConfigExists();
|
|
@@ -41,6 +41,7 @@ export class ConfigManager {
|
|
|
41
41
|
if (cdMatch) {
|
|
42
42
|
console.log("Detected 'cd' command in process_cmd:", cdMatch[1]);
|
|
43
43
|
passed.dir = cdMatch[1];
|
|
44
|
+
// passed.process_cmd = cdMatch[2];
|
|
44
45
|
};
|
|
45
46
|
};
|
|
46
47
|
}
|
|
@@ -56,7 +57,7 @@ export class ConfigManager {
|
|
|
56
57
|
dailyrestart_quickpull: passed.dailyrestart_quickpull,
|
|
57
58
|
//file logging
|
|
58
59
|
logfile_enable: passed.logfile_enable,
|
|
59
|
-
logfile_location: passed.logfile_location || path.join(
|
|
60
|
+
logfile_location: passed.logfile_location || path.join("store", "logs", this.serverName), //no editing kek
|
|
60
61
|
//webhook logging
|
|
61
62
|
webhook_url: passed.webhook_url || "", //false or empty is disabled
|
|
62
63
|
webhook_username: passed.webhook_username || "Webhook", //eg "LegacyShell: Client Server"
|
|
@@ -65,6 +66,7 @@ export class ConfigManager {
|
|
|
65
66
|
webhook_ping_role: passed.webhook_ping_role || false, //this might flood EVERYONE'S shit
|
|
66
67
|
//pulling
|
|
67
68
|
is_puller: this.config.pullers?.includes(this.serverName) || false,
|
|
69
|
+
restart_on_update: passed.restart_on_update ?? true,
|
|
68
70
|
};
|
|
69
71
|
|
|
70
72
|
if (passed.process_cmd_prefix) passed.process_cmd = `${passed.process_cmd_prefix}${passed.process_cmd}`;
|
package/src/ProcessManager.js
CHANGED
|
@@ -13,6 +13,7 @@ export class ProcessManager {
|
|
|
13
13
|
this.runningProcess = null;
|
|
14
14
|
this.restartScheduled = false;
|
|
15
15
|
this.autoRestart();
|
|
16
|
+
this.pullerSetup();
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
async startProcess(purposefulStop = false) {
|
|
@@ -114,13 +115,20 @@ export class ProcessManager {
|
|
|
114
115
|
|
|
115
116
|
} else {
|
|
116
117
|
let bash = 'bash';
|
|
117
|
-
let options = ['-c', 'export FORCE_COLOR=3;
|
|
118
|
+
let options = ['-c', 'export FORCE_COLOR=3;' + this.options.process_cmd];
|
|
118
119
|
if (process.platform === 'win32') {
|
|
119
|
-
bash = this.options.winBashPath || 'C:\\Program Files\\Git\\bin\\bash.exe';
|
|
120
|
+
// bash = this.options.winBashPath || 'C:\\Program Files\\Git\\bin\\bash.exe';
|
|
120
121
|
if (isNodeScript) {
|
|
121
122
|
bash = 'node';
|
|
122
123
|
options = scriptPath.replace(/^node\s+/, '').trim().split(' ');
|
|
123
124
|
// options.push("FORCE_COLOR=3");
|
|
125
|
+
} else {
|
|
126
|
+
//check if bash exists at the specified path
|
|
127
|
+
bash = this.options.winBashPath || 'C:\\Program Files\\Git\\bin\\bash.exe';
|
|
128
|
+
if (!fs.existsSync(bash)) {
|
|
129
|
+
bash = 'cmd.exe';
|
|
130
|
+
options = ['/c', this.options.process_cmd];
|
|
131
|
+
}
|
|
124
132
|
}
|
|
125
133
|
}
|
|
126
134
|
this.runningProcess = spawn(bash, options, {
|
|
@@ -166,7 +174,32 @@ export class ProcessManager {
|
|
|
166
174
|
}
|
|
167
175
|
}
|
|
168
176
|
|
|
169
|
-
|
|
177
|
+
async gitPull() {
|
|
178
|
+
this.logger.logSend("Performing git pull...");
|
|
179
|
+
this.executeCommand('git', ['pull'], 'ignore');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async getGitHash() {
|
|
183
|
+
return new Promise((resolve) => {
|
|
184
|
+
const gitProcess = spawn('git', ['rev-parse', 'HEAD'], { cwd: this.options.dir || process.cwd() });
|
|
185
|
+
let hash = '';
|
|
186
|
+
|
|
187
|
+
gitProcess.stdout.on('data', (data) => {
|
|
188
|
+
hash += data.toString();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
gitProcess.on('close', (code) => {
|
|
192
|
+
if (code === 0) {
|
|
193
|
+
resolve(hash.trim());
|
|
194
|
+
} else {
|
|
195
|
+
this.logger.logSend(`git rev-parse exited with code ${code}`);
|
|
196
|
+
resolve(null);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async autoRestart() {
|
|
170
203
|
if (!this.options.dailyrestart_enable) return;
|
|
171
204
|
if (this.restartScheduled) {
|
|
172
205
|
this.logger.logSend("Restart already scheduled.");
|
|
@@ -194,8 +227,7 @@ export class ProcessManager {
|
|
|
194
227
|
|
|
195
228
|
setTimeout(async () => {
|
|
196
229
|
if (this.options.dailyrestart_quickpull) {
|
|
197
|
-
this.
|
|
198
|
-
this.executeCommand('git', ['pull'], 'ignore');
|
|
230
|
+
await this.gitPull();
|
|
199
231
|
}
|
|
200
232
|
this.logger.logSend("Auto-restarting process.");
|
|
201
233
|
await this.startProcess();
|
|
@@ -204,6 +236,21 @@ export class ProcessManager {
|
|
|
204
236
|
}, timeUntilRestart);
|
|
205
237
|
}
|
|
206
238
|
|
|
239
|
+
async pullerSetup() {
|
|
240
|
+
this.currentHash = await this.getGitHash();
|
|
241
|
+
setInterval(async () => {
|
|
242
|
+
if (this.options.is_puller) {
|
|
243
|
+
await this.gitPull();
|
|
244
|
+
}
|
|
245
|
+
const newHash = await this.getGitHash();
|
|
246
|
+
if (newHash && newHash !== this.currentHash && this.options.restart_on_update) {
|
|
247
|
+
this.logger.logSend(`Git hash changed from ${this.currentHash} to ${newHash}. Restarting process.`);
|
|
248
|
+
this.currentHash = newHash;
|
|
249
|
+
await this.startProcess();
|
|
250
|
+
}
|
|
251
|
+
}, 60e3);
|
|
252
|
+
}
|
|
253
|
+
|
|
207
254
|
executeCommand(command, args, stdio = "inherit") {
|
|
208
255
|
let dir = this.options.dir || "";
|
|
209
256
|
|