{"record":{"id":"75a4500bcf0326cc","repo":"AdguardTeam/AdGuardHome","slug":"restarting-service-w","errorCode":null,"errorMessage":"restarting service: %w","messagePattern":"restarting service: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/home/service.go","lineNumber":140,"sourceCode":"// restartService restarts the service.  It returns error if the service is not\n// running.  l must not be nil.\nfunc restartService(ctx context.Context, baseLogger *slog.Logger) (err error) {\n\tsvcMgr, err := ossvc.NewManager(ctx, &ossvc.ManagerConfig{\n\t\tClock:              timeutil.SystemClock{},\n\t\tLogger:             baseLogger.With(slogutil.KeyPrefix, svcLogPrefix),\n\t\tCommandConstructor: executil.SystemCommandConstructor{},\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"initializing service manager: %w\", err)\n\t}\n\n\tact := &ossvc.ActionRestart{\n\t\tServiceName: serviceName,\n\t}\n\n\terr = svcMgr.Perform(ctx, act)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"restarting service: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// handleServiceControlAction one of the possible control actions:\n//\n//   - install:  Installs a service/daemon.\n//   - uninstall:  Uninstalls it.\n//   - status:  Prints the service status.\n//   - start:  Starts the previously installed service.\n//   - stop:  Stops the previously installed service.\n//   - restart:  Restarts the previously installed service.\n//   - run:  This is a special command that is not supposed to be used directly\n//     it is specified when we register a service, and it indicates to the app\n//     that it is being run as a service/daemon.\nfunc handleServiceControlAction(\n\tctx context.Context,","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/home/service.go#L122-L158","documentation":"The service manager was created, but performing the Restart action on the AdGuard Home service failed. svcMgr.Perform wraps platform-specific errors from systemd/svc control commands.","triggerScenarios":"cmdlineUpdate → restartService → svcMgr.Perform(ActionRestart) failing due to the service being stopped already, insufficient privileges (not root), or the service manager timing out.","commonSituations":"Running 'AdGuardHome --update' as a non-root user, D-Bus/systemd unavailable in containers, or the unit file having been removed manually.","solutions":["Run the update/restart as root or with sudo","Verify the service exists and is running: systemctl status AdGuardHome","In containers, skip service-based restart; restart the container instead"],"exampleFix":"# before\n./AdGuardHome --update\n\n# after\nsudo ./AdGuardHome --update","handlingStrategy":"try-catch","validationCode":"// Check service state before restart:\nif st, _ := svcMgr.Status(ctx, name); st != svc.StatusRunning { /* handle */ }","typeGuard":null,"tryCatchPattern":"if err := svcMgr.Perform(ctx, act); err != nil {\n    return fmt.Errorf(\"restarting service: %w\", err) // distinguish EPERM vs not-found in logs\n}","preventionTips":["Run updates with sudo/root","Keep systemd unit files managed by the installer, not hand-edited"],"tags":["go","service","restart","privileges","systemd"],"backgroundTag":"service-restart-failed","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}