diff --git a/src/gateway/routes/routes-admin-sessions.ts b/src/gateway/routes/routes-admin-sessions.ts index c4d2622..3b7eec9 100644 --- a/src/gateway/routes/routes-admin-sessions.ts +++ b/src/gateway/routes/routes-admin-sessions.ts @@ -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' }); diff --git a/web-ui/html/index.html b/web-ui/html/index.html index cafea9a..a2cf31a 100644 --- a/web-ui/html/index.html +++ b/web-ui/html/index.html @@ -1888,6 +1888,7 @@ 1.15배 +