feat: Add container restart functionality from web UI

- Added restart button to settings page
- Created /api/restart endpoint (file-flag based)
- Implemented watch-restart.sh daemon
- Added systemd service for restart watcher
- Updated README with restart setup instructions
- Container automatically restarts when settings changed

Settings flow:
1. User edits settings in web UI
2. Click 'Save Settings' to persist to .env
3. Click 'Restart Bot' to apply changes
4. Watcher detects flag and restarts container
5. New settings loaded automatically
This commit is contained in:
mindesbunister
2025-10-24 15:06:26 +02:00
parent 9e0d9b88f9
commit 26864c10f2
7 changed files with 174 additions and 10 deletions

38
app/api/restart/route.ts Normal file
View File

@@ -0,0 +1,38 @@
/**
* Container Restart API Endpoint
*
* Creates a restart flag file that triggers container restart from the host
*/
import { NextResponse } from 'next/server'
import fs from 'fs'
import path from 'path'
const RESTART_FLAG = path.join(process.cwd(), 'logs', '.restart-requested')
export async function POST() {
try {
// Create logs directory if it doesn't exist
const logsDir = path.dirname(RESTART_FLAG)
if (!fs.existsSync(logsDir)) {
fs.mkdirSync(logsDir, { recursive: true })
}
// Create restart flag file
fs.writeFileSync(RESTART_FLAG, new Date().toISOString(), 'utf-8')
return NextResponse.json({
success: true,
message: 'Restart requested. Container will restart in a few seconds...'
})
} catch (error: any) {
console.error('Failed to create restart flag:', error)
return NextResponse.json(
{
error: 'Failed to request restart',
details: error.message
},
{ status: 500 }
)
}
}