feat(nodes): add remote Xray and panel restart actions (#6970)

An operator running a master with sub-nodes could probe or update a node from the Nodes page but had to log in to the node, or SSH into it, to restart Xray or the panel (#6937).

Add Restart Xray and Restart panel to the node actions, behind a confirmation. Xray restarts through the node runtime; the panel restart is a new Remote call that the node accepts with node-admin credentials, the authority that already covers updatePanel. Both are refused for a disabled node.
This commit is contained in:
Hamed
2026-11-24 16:55:08 +03:30
committed by GitHub
parent a07ed97aa1
commit e409ed7244
40 changed files with 941 additions and 4 deletions
+34
View File
@@ -2,6 +2,7 @@ package web
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
@@ -173,6 +174,9 @@ func TestMasterNodeContract(t *testing.T) {
node := startContractNode(t)
master := node.masterWithToken(t, scope)
ctx := context.Background()
restarts := make(chan struct{}, 1)
global.SetRestartHook(func() { restarts <- struct{}{} })
t.Cleanup(func() { global.SetRestartHook(func() {}) })
cells := []struct {
name string
@@ -311,6 +315,36 @@ func TestMasterNodeContract(t *testing.T) {
}
return nil
}, nil},
{"RestartPanel respects enrollment authority and schedules a restart", []string{"RestartPanel"}, func() error {
err := master.RestartPanel(ctx)
if scope == model.ApiScopeNodeSync {
if err == nil {
return fmt.Errorf("node-sync unexpectedly restarted the panel")
}
if !strings.Contains(err.Error(), "HTTP 403") {
return fmt.Errorf("node-sync restart should return HTTP 403: %w", err)
}
refused := node.takeRefused()
if len(refused) != 1 || refused[0] != "POST /panel/api/setting/restartPanel -> 403" {
return fmt.Errorf("refused requests = %v", refused)
}
return nil
}
if err != nil {
return err
}
select {
case <-restarts:
return fmt.Errorf("panel restarted before the response")
default:
}
select {
case <-restarts:
return nil
case <-time.After(6 * time.Second):
return fmt.Errorf("panel restart was not scheduled")
}
}, nil},
{"DeleteUser detaches the client from the inbound", []string{"DeleteUser"}, func() error {
return master.DeleteUser(ctx, masterInbound("updated", false), "c3")
}, func(t *testing.T) {