{"record":{"id":"6b60d61a448214e2","repo":"zeroclaw-labs/zeroclaw","slug":"journalctl-exited-with-non-zero-status","errorCode":null,"errorMessage":"journalctl exited with non-zero status","messagePattern":"journalctl exited with non-zero status","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-runtime/src/service/mod.rs","lineNumber":1012,"sourceCode":"            .status()\n            .context(\"Failed to run tail\")?;\n        if !status.success() {\n            bail!(\"tail exited with non-zero status\");\n        }\n    }\n    Ok(())\n}\n\nfn logs_linux(config: &Config, init_system: InitSystem, lines: usize, follow: bool) -> Result<()> {\n    match init_system {\n        InitSystem::Systemd => {\n            let args = linux_journalctl_args(config, lines, follow);\n            let status = Command::new(\"journalctl\")\n                .args(&args)\n                .status()\n                .context(\"Failed to run journalctl\")?;\n            if !status.success() {\n                bail!(\"journalctl exited with non-zero status\");\n            }\n        }\n        InitSystem::Openrc => {\n            // OpenRC logs go to /var/log/<service>/error.log (as configured in the init script).\n            let log_dir = linux_openrc_log_dir(config);\n            let log_file = log_dir.join(\"error.log\");\n            if !log_file.exists() {\n                // Fall back to access log\n                let access_log = log_dir.join(\"access.log\");\n                if !access_log.exists() {\n                    bail!(\n                        \"No log files found at {}. Is the service installed?\",\n                        log_dir.display()\n                    );\n                }\n                return tail_file(&access_log, lines, follow);\n            }\n            tail_file(&log_file, lines, follow)?;","sourceCodeStart":994,"sourceCodeEnd":1030,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-runtime/src/service/mod.rs#L994-L1030","documentation":"For systemd installs, logs_linux builds journalctl arguments via linux_journalctl_args (unit filter, line count, follow) and runs journalctl. journalctl's non-zero exit is propagated verbatim; the underlying reason is only visible by running the same journalctl command by hand. Typical causes: no persistent journal for the user unit, permission on journal files, or the unit not existing yet.","triggerScenarios":"'zeroclaw service logs' with systemd on hosts where /var/log/journal is absent (volatile-only journal), inside containers, or when the zeroclaw user unit has never written a journal record.","commonSituations":"Minimal VMs/containers without persistent journald; user services without lingering enabled so logs land nowhere; journal files readable only by members of the systemd-journal group.","solutions":["Run the equivalent manually to see journalctl's own error: journalctl --user -u zeroclaw.service -n 50","Enable persistent journal storage (Storage=persistent in /etc/systemd/journald.conf) and restart systemd-journald","Enable lingering for the service user (loginctl enable-linger $USER) and add it to the systemd-journal group if needed"],"exampleFix":"# before\nzeroclaw service logs\n# after: surface the real journalctl failure\njournalctl --user -u zeroclaw.service -n 50 --no-pager","handlingStrategy":"try-catch","validationCode":"// cheap preflight: is there any persistent journal for user units?\nif !std::path::Path::new(\"/var/log/journal\").exists() {\n    // journalctl will likely fail; enable persistent storage or read files directly\n}","typeGuard":null,"tryCatchPattern":"match service::logs(&config, InitSystem::Systemd, lines, follow) {\n    Err(err) if err.to_string().contains(\"journalctl exited with non-zero status\") => {\n        // re-run the equivalent journalctl by hand to capture its stderr for diagnosis\n        let _ = Command::new(\"journalctl\").args([\"--user\", \"-u\", \"zeroclaw.service\", \"-n\", \"50\"]).status();\n        return Err(err);\n    }\n    result => result?,\n}","preventionTips":["Enable persistent journald storage (Storage=persistent) on hosts you will read logs from","Run 'loginctl enable-linger' for headless user services so logs reach the journal","Smoke-test 'journalctl --user -u zeroclaw.service -n 1' during provisioning"],"tags":["linux","systemd","journalctl","logs","subprocess"],"backgroundTag":"subprocess-nonzero-exit","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}