Skip to content

Commit a8e2c5c

Browse files
committed
tweak: renamed discord "guild" to "server"
Because apparently Discord Corp can't decide on what they wanna call "guild".
1 parent f9fd732 commit a8e2c5c

29 files changed

Lines changed: 659 additions & 82 deletions

core/index-copy.ts

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
import fs from 'node:fs';
2+
import os from 'node:os';
3+
4+
5+
//Constants
6+
const signalTestTarget = os.platform() === 'win32'
7+
? 'E:/TMP/signal-test-windows.txt'
8+
: '/root/server/signal-test-docker.txt';
9+
10+
const writeStdout = (message: string) => {
11+
process.stdout.write(message + '\n');
12+
}
13+
const writePadding = () => {
14+
process.stdout.write('.\n'.repeat(10));
15+
}
16+
17+
18+
//Proof of life
19+
writeStdout('Starting...');
20+
let counter = 0;
21+
let isAwaitingShutdown = false;
22+
setInterval(() => {
23+
counter++;
24+
const icon = isAwaitingShutdown ? '⏳' : '✅';
25+
writeStdout(icon + ' tick: ' + counter);
26+
}, 250);
27+
28+
29+
//Signal management
30+
// const listeners: NodeJS.SignalsListener[] = [];
31+
// const addSignalListener = (signal: string, listener: NodeJS.SignalsListener) => {
32+
// process.on(signal, listener);
33+
// listeners.push(listener);
34+
// }
35+
// const removeSignalListeners = () => {
36+
// for (const listener of listeners) {
37+
// process.removeListener('SIGINT', listener);
38+
// process.removeListener('SIGTERM', listener);
39+
// process.removeListener('SIGHUP', listener);
40+
// }
41+
// }
42+
43+
44+
//Graceful shutdown
45+
const immediateButGracefulShutdown: NodeJS.SignalsListener = (signal: string) => {
46+
if (isAwaitingShutdown) {
47+
writeStdout(`\n⚠️ got '${signal}' but already shutting down.\n`);
48+
return;
49+
}
50+
51+
isAwaitingShutdown = true;
52+
const msg = [
53+
'-'.repeat(20),
54+
'Signal received: ' + signal,
55+
'Time: ' + new Date().toISOString(),
56+
'Rand: ' + Math.random().toString(36).substring(2, 15),
57+
'Counter: ' + counter,
58+
'-'.repeat(20),
59+
].join('\n');
60+
writeStdout(msg);
61+
62+
//Trying to write a file
63+
try {
64+
fs.writeFileSync(signalTestTarget, msg + '\n');
65+
} catch (error) {
66+
writeStdout('Error writing file: ' + (error as any).message);
67+
}
68+
69+
//Delaying the shutdown
70+
writeStdout('Delaying...');
71+
setTimeout(() => {
72+
writeStdout('time to die');
73+
process.removeAllListeners(signal);
74+
// writeStdout('sending SIGKILL.');
75+
// process.kill(process.pid, 'SIGKILL');
76+
writePadding();
77+
process.exit(0);
78+
}, 1500);
79+
// setTimeout(() => {
80+
// writeStdout('Done.');
81+
// writePadding();
82+
// process.exit(0);
83+
// }, 1500);
84+
}
85+
86+
87+
//Listening to signals
88+
try {
89+
process.on('SIGINT', immediateButGracefulShutdown);
90+
process.on('SIGTERM', immediateButGracefulShutdown);
91+
process.on('SIGHUP', immediateButGracefulShutdown);
92+
} catch (error) {
93+
writeStdout('Error listening to signals: ' + (error as any).message);
94+
}
95+
96+
97+
98+
99+
//Setting up command handler
100+
process.stdin.on('data', (data) => {
101+
const cmd = data.toString().toLowerCase().trim();
102+
if (data.toString() === '\n') {
103+
console.log('='.repeat(20));
104+
} else if (cmd === 'k') {
105+
writeStdout('killed!');
106+
process.exit(0);
107+
} else if (cmd === 'c') {
108+
throw new Error('crashed!');
109+
} else if (cmd === 't') {
110+
process.emit('SIGKILL', 'SIGKILL');
111+
}
112+
});
113+
process.stdin.resume();
114+
115+
//yay
116+
writeStdout('All ready: ' + process.pid);
117+
118+
// console.dir(os.networkInterfaces());
119+
// console.dir(os.userInfo());
120+
121+
// console.log('Starting...x');
122+
// setInterval(() => {
123+
// console.log('Alive');
124+
// }, 250);
125+
// setTimeout(() => {
126+
// console.log('Exiting...');
127+
// process.exitCode = 3;
128+
// }, 2000);
129+
// setImmediate(() => {
130+
// console.log('Running...');
131+
// });
132+
133+
// process.on('beforeExit', (code) => {
134+
// console.log('beforeExit', code);
135+
// });
136+
137+
/*
138+
139+
ctrl+c -> SIGINT
140+
taskkill -f -pid 122636 -> nothing
141+
closing window -> SIGHUP
142+
143+
144+
145+
146+
./scripts/test_build.sh $TXDEV_FXSERVER_PATH
147+
148+
149+
150+
node alpine/opt/cfx-server/citizen/system_resources/monitor/core/index.js
151+
152+
153+
154+
TARGET_PATH=/c/Users/tabarra/Desktop/PROGRAMMING/fxserver-container/server/alpine/opt/cfx-server/citizen/system_resources/monitor
155+
rm -rf "${TARGET_PATH}/core"
156+
mkdir -p $TARGET_PATH
157+
cp -r ../dist/core $TARGET_PATH
158+
ls -la "${TARGET_PATH}/core"
159+
*/

core/index-copy2.ts

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
import fs from 'node:fs';
2+
import os from 'node:os';
3+
4+
5+
//Constants
6+
const signalTestTarget = os.platform() === 'win32'
7+
? 'E:/TMP/signal-test-windows.txt'
8+
: '/root/server/signal-test-docker.txt';
9+
10+
const writeStdout = (message: string) => {
11+
process.stdout.write(message + '\n');
12+
}
13+
const writePadding = () => {
14+
process.stdout.write('.\n'.repeat(10));
15+
}
16+
17+
18+
//Proof of life
19+
console.log('NodeJS:', process.version);
20+
writeStdout('Starting...');
21+
let counter = 0;
22+
let isAwaitingShutdown = false;
23+
setInterval(() => {
24+
counter++;
25+
const icon = isAwaitingShutdown ? '⏳' : '✅';
26+
writeStdout(icon + ' tick: ' + counter);
27+
}, 250);
28+
29+
30+
//Signal management
31+
// const listeners: NodeJS.SignalsListener[] = [];
32+
// const addSignalListener = (signal: string, listener: NodeJS.SignalsListener) => {
33+
// process.on(signal, listener);
34+
// listeners.push(listener);
35+
// }
36+
// const removeSignalListeners = () => {
37+
// for (const listener of listeners) {
38+
// process.removeListener('SIGINT', listener);
39+
// process.removeListener('SIGTERM', listener);
40+
// process.removeListener('SIGHUP', listener);
41+
// }
42+
// }
43+
44+
45+
46+
//Graceful shutdown
47+
const immediateButGracefulShutdown: NodeJS.SignalsListener = (signal: string) => {
48+
if (isAwaitingShutdown) {
49+
writeStdout(`\n⚠️ got '${signal}' but already shutting down.\n`);
50+
return;
51+
}
52+
53+
isAwaitingShutdown = true;
54+
const randId = Math.random().toString(36).substring(2, 15);
55+
const msg = [
56+
'-'.repeat(20),
57+
'Signal received: ' + signal,
58+
'Time: ' + new Date().toISOString(),
59+
'Rand: ' + randId,
60+
'Counter: ' + counter,
61+
'-'.repeat(20),
62+
].join('\n');
63+
writeStdout(msg);
64+
65+
//Trying to write a file
66+
try {
67+
fs.writeFileSync(signalTestTarget, msg + '\n');
68+
} catch (error) {
69+
writeStdout('Error writing file: ' + (error as any).message);
70+
}
71+
72+
//Delaying the shutdown
73+
writeStdout('Delaying...');
74+
setTimeout(() => {
75+
writeStdout('time to die');
76+
//Trying to write a file
77+
try {
78+
fs.appendFileSync(signalTestTarget, `Dead: ${randId}\n`);
79+
} catch (error) {
80+
writeStdout('Error writing file: ' + (error as any).message);
81+
}
82+
// process.removeAllListeners(signal);
83+
// writeStdout('sending SIGKILL.');
84+
// process.kill(process.pid, 'SIGKILL');
85+
writePadding();
86+
console.log('count', process.listenerCount('SIGINT'));
87+
process.removeListener('SIGINT', immediateButGracefulShutdown);
88+
process.removeListener('SIGTERM', immediateButGracefulShutdown);
89+
process.removeListener('SIGHUP', immediateButGracefulShutdown);
90+
console.log('count', process.listenerCount('SIGINT'));
91+
process.exit(0);
92+
}, 1500);
93+
}
94+
95+
96+
97+
98+
//Listening to signals
99+
try {
100+
process.on('SIGINT', immediateButGracefulShutdown);
101+
process.on('SIGTERM', immediateButGracefulShutdown);
102+
process.on('SIGHUP', immediateButGracefulShutdown);
103+
} catch (error) {
104+
writeStdout('Error listening to signals: ' + (error as any).message);
105+
}
106+
107+
108+
109+
// setTimeout(() => {
110+
// console.log('dying');
111+
// process.exit(0);
112+
// }, 5000);
113+
114+
115+
116+
117+
// //Setting up command handler
118+
// process.stdin.on('data', (data) => {
119+
// const cmd = data.toString().toLowerCase().trim();
120+
// if (data.toString() === '\n') {
121+
// console.log('='.repeat(20));
122+
// } else if (cmd === 'k') {
123+
// writeStdout('killed!');
124+
// process.exit(0);
125+
// } else if (cmd === 'c') {
126+
// throw new Error('crashed!');
127+
// } else if (cmd === 't') {
128+
// process.emit('SIGKILL', 'SIGKILL');
129+
// }
130+
// });
131+
// process.stdin.resume();
132+
133+
//yay
134+
writeStdout('All ready: ' + process.pid);
135+
136+
// console.dir(os.networkInterfaces());
137+
// console.dir(os.userInfo());
138+
139+
// console.log('Starting...x');
140+
// setInterval(() => {
141+
// console.log('Alive');
142+
// }, 250);
143+
// setTimeout(() => {
144+
// console.log('Exiting...');
145+
// process.exitCode = 3;
146+
// }, 2000);
147+
// setImmediate(() => {
148+
// console.log('Running...');
149+
// });
150+
151+
// process.on('beforeExit', (code) => {
152+
// console.log('beforeExit', code);
153+
// });
154+
155+
/*
156+
157+
ctrl+c -> SIGINT
158+
taskkill -f -pid 122636 -> nothing
159+
closing window -> SIGHUP
160+
161+
162+
163+
164+
./scripts/test_build.sh $TXDEV_FXSERVER_PATH
165+
166+
167+
168+
node alpine/opt/cfx-server/citizen/system_resources/monitor/core/index.js
169+
170+
171+
172+
TARGET_PATH=/c/Users/tabarra/Desktop/PROGRAMMING/fxserver-container/server/alpine/opt/cfx-server/citizen/system_resources/monitor
173+
rm -rf "${TARGET_PATH}/core"
174+
mkdir -p $TARGET_PATH
175+
cp -r ../dist/core $TARGET_PATH
176+
ls -la "${TARGET_PATH}/core"
177+
*/

0 commit comments

Comments
 (0)