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:
38
app/api/restart/route.ts
Normal file
38
app/api/restart/route.ts
Normal 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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user