uni_service

Crates.iouni_service
lib.rsuni_service
version0.3.8
created_at2025-11-15 12:01:51.816001+00
updated_at2026-01-09 03:26:37.88586+00
descriptionUniversal service crate for building cross platform OS services
homepage
repositoryhttps://github.com/nu11ptr/uni_service
max_upload_size
id1934282
size43,488
Scott Meeuwsen (nu11ptr)

documentation

https://docs.rs/uni_service

README

uni_service

Crate Docs Build codecov

A crate for for building cross platform OS services

Install

cargo add uni_service
# or
cargo add uni_service -F tokio

Features

  • Portable cross platform services (Windows, macOS, Linux and other UNIX-like systems)
  • A single user supplied function is all that is required
  • Synchronous and asynchronous services (see axum example)
  • Any service can be run interactively from the CLI or in service mode
  • Works with the regular OS service manager, and pairs well with uni_service_manager
  • Minimal dependencies
  • No unsafe

Example

The hello_service function below is the service, the rest is just boilerplate.

use std::sync::mpsc::Receiver;

use uni_service::{BaseService, run_service};

fn hello_service(shutdown: Receiver<()>, is_service: bool) -> uni_service::Result<()> {
    if is_service {
        println!("Hello, World! (service mode)");
    } else {
        println!("Hello, World! (interactive mode)");
    }
    shutdown.recv()?;
    println!("Shutdown signal received. Shutting down...");
    Ok(())
}

fn run() -> uni_service::Result<()> {
    let service_mode = matches!(std::env::args().nth(1).as_deref(), Some("service"));
    let service = BaseService::new_sync("hello_world", hello_service, service_mode);

    run_service(service, service_mode)?;
    Ok(())
}

fn main() {
    if let Err(e) = run() {
        eprintln!("Error: {}", e);
        std::process::exit(1);
    }
}

Status

This is currently beta, however, I am using this myself, so it will become production quality at some point.

Contributions

Contributions are welcome as long they align with my vision for this crate.

Commit count: 102

cargo fmt