| Crates.io | uni_service_manager |
| lib.rs | uni_service_manager |
| version | 0.1.11 |
| created_at | 2025-11-15 12:02:02.84714+00 |
| updated_at | 2026-01-09 03:17:59.539007+00 |
| description | A crate for for managing cross platform OS services |
| homepage | |
| repository | https://github.com/nu11ptr/uni_service |
| max_upload_size | |
| id | 1934283 |
| size | 65,249 |
A crate for for managing cross platform OS services
cargo add uni_service_manager
uni_serviceDiscover platform capabilities and then install, start, wait, stop and uninstall a service.
use std::{env, io, process};
use std::{io::Write as _, time::Duration};
use uni_service_manager::{ServiceCapabilities, ServiceSpec, UniServiceManager};
const TIMEOUT: Duration = Duration::from_secs(5);
fn main() {
// Windows _user_ services require a new logon before they can be started, so we will use a system service on Windows
let user = !UniServiceManager::capabilities()
.contains(ServiceCapabilities::USER_SERVICES_REQUIRE_NEW_LOGON);
let user_manager = UniServiceManager::new("my_service", "com.example.", user).unwrap();
let spec = ServiceSpec::new("path/to/my/executable")
.arg("my_arg").unwrap()
.display_name("My display name").unwrap()
.description("My awesome service").unwrap()
.set_autostart()
.set_restart_on_failure();
user_manager.install_if_needed_and_start(&spec, TIMEOUT).unwrap();
io::stdout().flush().unwrap();
println!("Press Enter to stop the service...");
let mut buffer = String::new();
io::stdin().read_line(&mut buffer).unwrap();
user_manager.stop_if_needed_and_uninstall(TIMEOUT).unwrap();
}
This is currently beta, however, I am using this myself, so it will become production quality at some point.
Contributions are welcome as long they align with my vision for this crate.