Download dev/tests/web/t_bg.js from mchuca/ServerMonitor: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/mchuca/ServerMonitor/resolve/main/dev/tests/web/t_bg.js
- Command line
-
hf download hf://mchuca/ServerMonitor/dev/tests/web/t_bg.js
-
curl -L -o t_bg.js https://huggingface.co/mchuca/ServerMonitor/resolve/main/dev/tests/web/t_bg.js
1.29 kB
| // The delayed-background pattern of "Reboot" / "Shut down" ((sleep 2; systemctl reboot) >/dev/null 2>&1 &) must survive the end of its | |
| // command and a reconnect, now that children are ended by process group. Uses a harmless marker file instead. node t_bg.js <port> <scratch file> | |
| const fs = require('fs'), { sleep, client, check, done } = require('./lib'), [port, mark] = process.argv.slice(2), { post } = client(port); | |
| (async () => { | |
| for (const f of [mark + '.1', mark + '.2']) fs.existsSync(f) && fs.unlinkSync(f); | |
| let t = Date.now(), r = await post('exec', { id: 'local1', cmd: `(sleep 2; echo ran > '${mark}.1') >/dev/null 2>&1 & echo scheduled`, privileged: true }); | |
| check('the command returns at once', r.code === 0 && r.out === 'scheduled\n' && Date.now() - t < 1000, `${JSON.stringify(r)} after ${Date.now() - t} ms`); | |
| r = await post('exec', { id: 'local1', cmd: `(sleep 2; echo ran > '${mark}.2') >/dev/null 2>&1 & echo scheduled` }); | |
| await post('server/reconnect', { id: 'local1' }); // drops the link right after the command ended | |
| await sleep(3500); | |
| check('the delayed part still runs (also after a reconnect)', fs.existsSync(mark + '.1') && fs.existsSync(mark + '.2'), `${fs.existsSync(mark + '.1')} ${fs.existsSync(mark + '.2')}`); | |
| done(); | |
| })(); | |