use std::fs;
use std::path::PathBuf;
#[cfg(target_os = "macos")]
mod launchd;
#[cfg(target_os = "macos")]
#[allow(unused_imports)]
pub use launchd::{install, label, load, pid, restart, status, uninstall, unload};
#[cfg(target_os = "linux")]
mod systemd;
#[cfg(target_os = "linux")]
#[allow(unused_imports)]
pub use systemd::{install, label, load, pid, restart, status, uninstall, unload};
#[cfg(target_os = "linux")]
pub use systemd::{enable_linger, linger_enabled, user_bus_ok};
pub struct ServiceSpec {
pub service: String,
pub program: PathBuf,
pub args: Vec<String>,
pub log: PathBuf,
pub keep_alive: bool,
pub run_at_load: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Status {
Running,
Stopped,
Error,
}
impl Status {
pub fn as_str(&self) -> &'static str {
match self {
Status::Running => "running",
Status::Stopped => "stopped",
Status::Error => "error",
}
}
}
pub fn socket_alive(path: &std::path::Path) -> bool {
use std::os::unix::fs::FileTypeExt;
fs::metadata(path)
.map(|m| m.file_type().is_socket())
.unwrap_or(false)
}