From 1f5cdc025dbfbe311f47b4edfd9b050cd5517004 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Fri, 13 Dec 2019 20:42:53 +0100 Subject: [PATCH] Fix #139 #134 --- src/main.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2b6ab0d..5d59a2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -402,9 +402,24 @@ fn start_daemon(config_set: ConfigSet) { #[cfg(target_os = "linux")] fn start_daemon(config_set: ConfigSet) { - if config_set.default.use_system_agent { - use std::process::Command; + use std::process::{Command, Stdio}; + // Check if Systemd is available in the system + let status = Command::new("systemctl") + .args(&["--version"]) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .status(); + + // If Systemd is not available in the system, espanso should default to unmanaged mode + // See issue https://github.com/federico-terzi/espanso/issues/139 + let force_unmanaged = if let Err(status) = status { + true + } else { + false + }; + + if config_set.default.use_system_agent && !force_unmanaged { // Make sure espanso is currently registered in systemd let res = Command::new("systemctl") .args(&["--user", "is-enabled", "espanso.service"]) @@ -442,6 +457,10 @@ fn start_daemon(config_set: ConfigSet) { eprintln!("Error starting systemd daemon: {}", res.unwrap_err()); } }else{ + if force_unmanaged { + eprintln!("Systemd is not available in this system, switching to unmanaged mode."); + } + fork_daemon(config_set); } }