{"record":{"id":"e84e885654573d87","repo":"AdguardTeam/AdGuardHome","slug":"initializing-service-w","errorCode":null,"errorMessage":"initializing service: %w","messagePattern":"initializing service: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/home/service.go","lineNumber":116,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"getting current directory: %w\", err)\n\t}\n\n\targs := optsToArgs(opts)\n\tbaseLogger.DebugContext(ctx, \"using\", \"args\", args)\n\n\tsvcConfig := &service.Config{\n\t\tName:             serviceName,\n\t\tDisplayName:      serviceDisplayName,\n\t\tDescription:      serviceDescription,\n\t\tWorkingDirectory: pwd,\n\t\tArguments:        args,\n\t}\n\tossvc.ConfigureServiceOptions(svcConfig, p.clock.Now(), version.Full())\n\n\ts, err := service.New(p, svcConfig)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"initializing service: %w\", err)\n\t}\n\n\treturn s.Run()\n}\n\n// 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{","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/home/service.go#L98-L134","documentation":"handleRun could not create the system service object via service.New (kardianos/service). This validates the service configuration (name, executable path, arguments) and platform service integration before running.","triggerScenarios":"Invoking the 'run' service action when the service Config is invalid for the platform — bad executable path, unsupported service system, or missing permissions to interface with the system service manager.","commonSituations":"Running the binary in an environment without systemd/sysv/launchd (minimal containers), a renamed/moved executable, or restricted environments like some NAS sandboxing.","solutions":["Check the inner error for the platform-specific cause","Run under a real init system or in the foreground (./AdGuardHome) in containers","Ensure the executable path in the service config exists and is executable"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify the executable exists before service.New:\nif _, err := os.Stat(os.Args[0]); err != nil { return err }","typeGuard":null,"tryCatchPattern":"if err := handleRun(...); err != nil {\n    if strings.Contains(err.Error(), \"initializing service\") {\n        // likely unsupported platform or bad exec path; run in foreground instead\n    }\n}","preventionTips":["Register the service on a host with a real init system","Keep the binary at a stable absolute path"],"tags":["go","service","systemd","service-integration"],"backgroundTag":"service-initialization-failed","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}