This commit is contained in:
Federico Terzi 2019-12-13 20:42:53 +01:00
parent 2789fd93ad
commit 1f5cdc025d

View File

@ -402,9 +402,24 @@ fn start_daemon(config_set: ConfigSet) {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn start_daemon(config_set: ConfigSet) { fn start_daemon(config_set: ConfigSet) {
if config_set.default.use_system_agent { use std::process::{Command, Stdio};
use std::process::Command;
// 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 // Make sure espanso is currently registered in systemd
let res = Command::new("systemctl") let res = Command::new("systemctl")
.args(&["--user", "is-enabled", "espanso.service"]) .args(&["--user", "is-enabled", "espanso.service"])
@ -442,6 +457,10 @@ fn start_daemon(config_set: ConfigSet) {
eprintln!("Error starting systemd daemon: {}", res.unwrap_err()); eprintln!("Error starting systemd daemon: {}", res.unwrap_err());
} }
}else{ }else{
if force_unmanaged {
eprintln!("Systemd is not available in this system, switching to unmanaged mode.");
}
fork_daemon(config_set); fork_daemon(config_set);
} }
} }