ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
fix(agent): skip post-pair service restart in standalone (non-MSI) mode
Juan Denis28cdf2280fbd
diff --git a/agent/internal/agentui/pairer.go b/agent/internal/agentui/pairer.goindex c50f18dd..483e140e 100644--- a/agent/internal/agentui/pairer.go+++ b/agent/internal/agentui/pairer.go@@ -128,24 +128,32 @@ func (p *pairer) handleStart(w http.ResponseWriter, r *http.Request) {// Earlier versions ignored sc start errors silently which is// why users saw "successfully paired" on a dead service and// had to start it manually from the CLI.- if err := runServiceCmd("stop"); err != nil {- p.log.Info("Service stop reported error (likely already stopped)", "error", err)- }- // sc.exe returns once SCM accepts the stop request, not when the- // service is fully stopped. Issuing sc start while the service is- // still STOP_PENDING fails with 1056 ("instance already running"),- // so wait until SCM reports STOPPED before starting.- if err := waitForServiceStopped(15 * time.Second); err != nil {- p.log.Info("Service did not reach STOPPED before start", "error", err)- }- if err := runServiceCmd("start"); err != nil {- p.log.Error("Failed to start service after pairing", "error", err)- p.mu.Lock()- p.state = "error"- p.errMsg = "Pairing succeeded but the agent service failed to start: " + err.Error() +- "\n\nTry: restart the machine, or open Actions → Restart agent."- p.mu.Unlock()- return+ // Standalone (non-MSI) installs have no ServerKitAgent service+ // to restart — the credentials on disk are all the pairing+ // produces, and the agent runtime starts separately. Skip the+ // restart cleanly in that case instead of surfacing 1060.+ if !isServiceInstalled() {+ p.log.Info("ServerKitAgent service not installed; skipping post-pair restart (standalone mode)")+ } else {+ if err := runServiceCmd("stop"); err != nil {+ p.log.Info("Service stop reported error (likely already stopped)", "error", err)+ }+ // sc.exe returns once SCM accepts the stop request, not when the+ // service is fully stopped. Issuing sc start while the service is+ // still STOP_PENDING fails with 1056 ("instance already running"),+ // so wait until SCM reports STOPPED before starting.+ if err := waitForServiceStopped(15 * time.Second); err != nil {+ p.log.Info("Service did not reach STOPPED before start", "error", err)+ }+ if err := runServiceCmd("start"); err != nil {+ p.log.Error("Failed to start service after pairing", "error", err)+ p.mu.Lock()+ p.state = "error"+ p.errMsg = "Pairing succeeded but the agent service failed to start: " + err.Error() ++ "\n\nTry: restart the machine, or open Actions → Restart agent."+ p.mu.Unlock()+ return+ }}// sc start returns as soon as the SCM accepts the request, not// when the service is actually running. Poll for state=RUNNING@@ -306,9 +314,20 @@ func (p *pairer) runConnectionStringFlow(ctx context.Context, panelURL, token st// Same restart-and-verify dance as the pair-code claim path. Earlier// versions skipped this and left users staring at "successfully// paired" on a service that never actually picked up the new config.+ // Standalone (non-MSI) installs have no service to restart; pairing+ // is still complete because the credentials are on disk.+ if !isServiceInstalled() {+ p.log.Info("ServerKitAgent service not installed; skipping post-pair restart (standalone mode)")+ return+ }if err := runServiceCmd("stop"); err != nil {p.log.Info("Service stop reported error (likely already stopped)", "error", err)}+ // Wait for STOPPED before starting — issuing sc start during+ // STOP_PENDING fails with 1056 ("instance already running").+ if err := waitForServiceStopped(15 * time.Second); err != nil {+ p.log.Info("Service did not reach STOPPED before start", "error", err)+ }if err := runServiceCmd("start"); err != nil {p.log.Error("Failed to start service after pairing", "error", err)p.failConnString("Pairing succeeded but the agent service failed to start: " + err.Error() +diff --git a/agent/internal/agentui/platform_windows.go b/agent/internal/agentui/platform_windows.goindex fa7c1862..9d70152d 100644--- a/agent/internal/agentui/platform_windows.go+++ b/agent/internal/agentui/platform_windows.go@@ -24,6 +24,26 @@ func runServiceCmd(verb string) error {return nil}+// isServiceInstalled reports whether ServerKitAgent is registered with+// Windows SCM. Used to skip the post-pair stop/start dance when the user+// is running the standalone exe without the MSI install — there's no+// service to control, and `sc start` would fail with error 1060+// ("service does not exist") and surface as a fake pairing failure.+func isServiceInstalled() bool {+ cmd := exec.Command("sc.exe", "query", "ServerKitAgent")+ cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}+ out, err := cmd.CombinedOutput()+ if err == nil {+ return true+ }+ // sc.exe sets exit status 1060 (and prints that code) when the+ // service is unknown. Any other error (access denied, SCM down) we+ // optimistically treat as "service exists, just couldn't query it"+ // — the subsequent stop/start will surface the real problem with+ // better context than the query would.+ return !strings.Contains(string(out), "1060")+}+// waitForServiceRunning polls `sc query` until the service reports state// 4 (RUNNING) or the deadline passes. Returns nil when running, or a// descriptive error including the most recent state output. Used to