feat: auto-restart server when listen addr or admin path changes
Build and Push to GHCR / build-and-push (push) Has been cancelled
Build and Push to GHCR / build-and-push (push) Has been cancelled
When admin config is updated with a new listen_addr or admin_path, the server now automatically performs a graceful restart instead of requiring the user to manually restart the service. - cmd/main.go: refactor into a loop that supports graceful shutdown and restart via http.Server.Shutdown - internal/admin/handlers.go: add SetOnRestart callback, triggered after config save when restart is required - web/static/index.html: remove manual restart alert; auto-redirect to new admin path or show toast if port changed via [HAPI](https://hapi.run) Co-Authored-By: HAPI <[email protected]>
This commit is contained in:
+13
-4
@@ -650,12 +650,21 @@
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
currentConfig = data;
|
||||
showToast('保存成功');
|
||||
closeSettingsModal();
|
||||
if (data.restart_required) {
|
||||
showToast('配置已保存,服务正在应用新配置');
|
||||
closeSettingsModal();
|
||||
setTimeout(() => {
|
||||
alert('配置已保存,由于修改了监听地址或管理后台路径,需要重启服务才能生效。');
|
||||
}, 300);
|
||||
const newPort = data.listen_addr.includes(':') ? data.listen_addr.split(':').pop() : '';
|
||||
const currentPort = window.location.port || (window.location.protocol === 'https:' ? '443' : '80');
|
||||
if (newPort && newPort !== currentPort) {
|
||||
showToast('服务已在新端口启动,请使用新地址访问', 'warning');
|
||||
} else {
|
||||
window.location.href = data.admin_path + '/';
|
||||
}
|
||||
}, 1500);
|
||||
} else {
|
||||
showToast('保存成功');
|
||||
closeSettingsModal();
|
||||
}
|
||||
} else {
|
||||
showToast('保存失败', 'error');
|
||||
|
||||
Reference in New Issue
Block a user