{"record":{"id":"80aa01616367e44c","repo":"shadow1ng/fscan","slug":"service-operation-error-s","errorCode":null,"errorMessage":"service_operation_error: %s","messagePattern":"service_operation_error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/local/systemdservice.go","lineNumber":302,"sourceCode":"\tvar errors []string\n\n\tfor _, serviceName := range serviceFiles {\n\t\t// 重新加载systemd配置\n\t\t_ = exec.Command(\"systemctl\", \"daemon-reload\").Run()\n\n\t\t// 启用服务\n\t\tif err := exec.Command(\"systemctl\", \"enable\", serviceName).Run(); err != nil {\n\t\t\terrors = append(errors, fmt.Sprintf(\"enable %s: %v\", serviceName, err))\n\t\t}\n\n\t\t// 启动服务\n\t\tif err := exec.Command(\"systemctl\", \"start\", serviceName).Run(); err != nil {\n\t\t\terrors = append(errors, fmt.Sprintf(\"start %s: %v\", serviceName, err))\n\t\t}\n\t}\n\n\tif len(errors) > 0 {\n\t\treturn fmt.Errorf(i18n.GetText(\"service_operation_error\")+\": %s\", strings.Join(errors, \"; \"))\n\t}\n\n\treturn nil\n}\n\n// createUserServices 创建用户级服务\nfunc (p *SystemdServicePlugin) createUserServices(execPath string) ([]string, error) {\n\tuserDir := filepath.Join(os.Getenv(\"HOME\"), \".config\", \"systemd\", \"user\")\n\tif userDir == \"/.config/systemd/user\" { // HOME为空的情况\n\t\tuserDir = \"/tmp/.config/systemd/user\"\n\t}\n\n\tif err := os.MkdirAll(userDir, 0755); err != nil {\n\t\treturn nil, err\n\t}\n\n\tuserServices := []string{\n\t\t\"user-service.service\",","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/local/systemdservice.go#L284-L320","documentation":"Aggregating guard in enableAndStartServices: at least one 'systemctl enable' or 'systemctl start' invocation failed for the created service files; the joined per-service error strings (service name plus underlying error) are returned as a single error listing every failed operation.","triggerScenarios":"systemctl start (or the preceding enable/reload) returns non-zero: unit file invalid, systemctl absent, systemd not running (e.g. container), or service crashes at start.","commonSituations":"Running inside a Docker container without systemd; systemctl not installed; malformed unit file (bad ExecStart path); executable not present or not executable at the copied path.","solutions":["Read the per-service messages after \"service_operation_error: \" — each is \"start <name>: <reason>\" — and fix the specific unit","Verify systemd is the running init (ps -p 1) and systemctl exists; do not use this plugin in non-systemd containers","Validate the unit file: systemd-analyze verify <unit>; confirm ExecStart target exists and is executable (chmod +x)","Run journalctl -xe for the failing service for the underlying start failure"],"exampleFix":"// ensure executable bit and correct path before enabling\nchmod +x /usr/local/bin/myservice\nsystemd-analyze verify /etc/systemd/system/myservice.service\nsystemctl --no-pager status myservice","handlingStrategy":"try-catch","validationCode":"if _, err := exec.LookPath(\"systemctl\"); err != nil {\n    return errors.New(\"systemctl not available; systemd required\")\n}\nif fi, err := os.Stat(\"/run/systemd/system\"); err != nil || !fi.IsDir() {\n    return errors.New(\"systemd is not the running init\")\n}","typeGuard":null,"tryCatchPattern":"if err := enableAndStartServices(...); err != nil {\n    for _, part := range strings.Split(strings.TrimPrefix(err.Error(), \"service_operation_error: \"), \"; \") {\n        log.Printf(\"service op failed: %s\", part)\n    }\n}","preventionTips":["Confirm the host runs systemd (PID 1) before using this plugin","Validate unit files with systemd-analyze verify","Ensure the service executable exists and is executable","Check journalctl for per-service start failures"],"tags":["systemd","systemctl","linux","service"],"backgroundTag":"command-not-found","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}