-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsafe-restart.js
More file actions
58 lines (53 loc) · 1.94 KB
/
Copy pathsafe-restart.js
File metadata and controls
58 lines (53 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* safe-restart.js — Reinicia o servidor preservando estado do counter e reid
*
* 1. Lê count.json e reid/state.json atuais
* 2. Salva como count-preserved.json e reid-preserved.json
* 3. Mata processos
* 4. cv.js escreve fresh-start (normal)
* 5. counter.py e reid.py verificam preserved → restauram → deletam
*
* Uso: node safe-restart.js
*/
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const CV_OUT = 'C:\\aya-expo-tools\\cv\\output';
const COUNT = path.join(CV_OUT, 'counter', 'count.json');
const COUNT_P = path.join(CV_OUT, 'counter', 'count-preserved.json');
const REID = path.join(CV_OUT, 'reid', 'state.json');
const REID_P = path.join(CV_OUT, 'reid', 'reid-preserved.json');
// 1. Preservar counter
if (fs.existsSync(COUNT)) {
const data = JSON.parse(fs.readFileSync(COUNT, 'utf8'));
fs.writeFileSync(COUNT_P, JSON.stringify(data));
console.log(`Counter preservado: entries=${data.entries} exits=${data.exits} date=${data.date}`);
} else {
console.log('Counter: sem count.json para preservar');
}
// 2. Preservar reid
if (fs.existsSync(REID)) {
const data = JSON.parse(fs.readFileSync(REID, 'utf8'));
fs.writeFileSync(REID_P, JSON.stringify(data));
console.log(`ReID preservado: uniqueVisitors=${data.today?.uniqueVisitors} staffCount=${data.today?.staffCount}`);
} else {
console.log('ReID: sem state.json para preservar');
}
// 3. Matar processos
console.log('Matando processos...');
try {
execSync('taskkill /f /im python.exe 2>nul', { stdio: 'ignore' });
} catch {}
try {
execSync('taskkill /f /im node.exe 2>nul', { stdio: 'ignore' });
} catch {}
console.log('Aguardando 3s...');
setTimeout(() => {
// 4. Iniciar via Task Scheduler
try {
execSync('schtasks /run /tn "AYA Expo Tools"', { stdio: 'inherit' });
console.log('Servidor reiniciado com estado preservado.');
} catch(e) {
console.log('Erro ao iniciar:', e.message);
}
}, 3000);