설정 화면: 서버 재시작 버튼(관리자 전용, 확인 창, 돌아올 때까지 자동 확인)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-20 17:11:41 +09:00
1 parent b9a602a0ad
commit 1c17217473
3 files changed
+38

No files matched your search

@@ -2,6 +2,7 @@ import express from 'express';
import fs from 'fs';
import fsp from 'fs/promises';
import path from 'path';
import { spawn } from 'child_process';
import { getConfig } from '../../config/config';
import { listAllSessions } from '../session';
@@ -26,6 +27,21 @@ export function registerAdminSessionRoutes(
res.json({ sessions: withOnline });
});
// 서버 재시작(설정 화면 버튼). 관리자만. 응답을 먼저 보낸 뒤 별도 임시 유닛에서 재시작해, 재시작이 자기 자신을 죽여도 명령이 끝까지 간다.
app.post('/api/admin/restart-server', (req, res) => {
const session = getSessionUser(req);
if (!session || session.role !== 'admin') return res.status(403).json({ error: 'Admin required' });
console.log(`[admin] server restart requested by ${session.username}`);
res.json({ success: true });
setTimeout(() => {
try {
const c = spawn('systemd-run', ['--user', '--collect', '--no-block', 'systemctl', '--user', 'restart', 'homeclaw'], { detached: true, stdio: 'ignore' });
c.on('error', () => { spawn('systemctl', ['--user', 'restart', 'homeclaw'], { detached: true, stdio: 'ignore' }).unref(); });
c.unref();
} catch (err: any) { console.warn('[admin] restart failed:', err?.message || err); }
}, 600);
});
app.get('/api/admin/banned-ips', async (req, res) => {
const session = getSessionUser(req);
if (!session || session.role !== 'admin') return res.status(403).json({ error: 'Admin required' });
+1
View File
@@ -1888,6 +1888,7 @@
<span id="ve-speed-val" style="display:inline-block;min-width:42px">1.15배</span></label>
<button class="btn btn-sm" onclick="saveVoiceEngine()">저장</button>
<button class="btn btn-sm" id="ve-reroll" onclick="rerollVoiceRef()" style="display:none">목소리 다시 뽑기</button>
<button class="btn btn-sm" onclick="restartServer()" title="서버를 다시 시작합니다(통화·진행 중인 응답이 끊김)">서버 재시작</button>
<span id="ve-status" style="font-size:12px;color:var(--muted)"></span>
</div>
<div style="font-size:11px;color:var(--muted);margin-top:8px;line-height:1.6">저장한 뒤 <b>서버를 재시작</b>하면 적용됩니다. 속도는 0.8~1.4배(1.5배 이상은 숫자·단위가 빠지는 것을 확인했습니다). 기본 외의 목소리는 처음 한 번 만든 기준 음성을 저장해 계속 같은 음색으로 읽습니다. 마음에 안 들면 "목소리 다시 뽑기" 후 재시작하세요.</div>
+21
View File
@@ -1307,6 +1307,27 @@ async function saveSttModel() {
} catch (e) { if (st) st.textContent = '저장 실패: ' + e.message; }
}
async function restartServer() {
const st = document.getElementById('ve-status');
if (!confirm('서버를 재시작합니다. 통화와 진행 중인 응답이 끊기고 약 20~40초 걸립니다. 계속할까요?')) return;
try {
await api('/api/admin/restart-server', { method: 'POST', body: '{}' });
} catch (e) { if (st) st.textContent = '재시작 요청 실패: ' + e.message; return; }
if (st) st.textContent = '재시작 중… 서버가 돌아오면 자동으로 알려 드립니다';
const t0 = Date.now();
let wentDown = false;
const poll = async () => {
try {
const r = await fetch('/api/auth/status', { cache: 'no-store' });
if (r.status >= 500) wentDown = true;
else if (wentDown) { if (st) st.textContent = '재시작 완료 — 통화는 다시 연결하세요'; loadVoiceEngine(); return; }
} catch { wentDown = true; }
if (Date.now() - t0 > 120000) { if (st) st.textContent = '응답이 없습니다. 잠시 뒤 새로고침해 보세요'; return; }
setTimeout(poll, 2500);
};
setTimeout(poll, 2000);
}
async function saveVoiceEngine() {
const st = document.getElementById('ve-status');
const sel = document.getElementById('ve-voice').value;