#signal #daemon #unix

rs-svc

Rust service wrapper that run on Linux

2 releases

0.1.1 Jun 5, 2024
0.1.0 Jun 5, 2024

#569 in Unix APIs

MIT license

5KB
54 lines

rs-svc

Rust service wrapper that run on Linux

Examples

See examples

use rs_svc::svc::service::Service;

struct MyService;

impl Service for MyService {
    fn init(&self) -> anyhow::Result<()> {
        println!("init");
        Ok(())
    }

    // must be non-blocking
    fn start(&self) -> anyhow::Result<()> {
        std::thread::spawn(move || {
            println!("start")
        });
        Ok(())
    }

    fn stop(&self) -> anyhow::Result<()> {
        print!("stop");
        Ok(())
    }
}


fn main() {
    let my_svc = MyService;
    rs_svc::svc::service::run(&my_svc).unwrap()
}

lib.rs:

Library for rust service wrapper that run on Linux

Examples

use rs_svc::svc::service::Service;

struct MyService;

impl Service for MyService {
    fn init(&self) -> anyhow::Result<()> {
        println!("init");
        Ok(())
    }

    // must be non-blocking
    fn start(&self) -> anyhow::Result<()> {
        std::thread::spawn(move || {
            println!("start")
        });
        Ok(())
    }

    fn stop(&self) -> anyhow::Result<()> {
        print!("stop");
        Ok(())
    }
}


fn main() {
    let my_svc = MyService;
    rs_svc::svc::service::run(&my_svc).unwrap()
}

Dependencies

~335KB