16个版本

0.6.0 2024年3月14日
0.5.2 2022年4月13日
0.5.1 2022年1月6日
0.5.0 2021年12月13日
0.2.0 2018年9月10日

macOS 和 iOS API 中排名 27

Download history 64/week @ 2024-04-22 165/week @ 2024-04-29 89/week @ 2024-05-06 172/week @ 2024-05-13 90/week @ 2024-05-20 26/week @ 2024-05-27 124/week @ 2024-06-03 134/week @ 2024-06-10 306/week @ 2024-06-17 125/week @ 2024-06-24 119/week @ 2024-07-01 122/week @ 2024-07-08 253/week @ 2024-07-15 364/week @ 2024-07-22 417/week @ 2024-07-29 285/week @ 2024-08-05

每月下载量 1,320

MIT/Apache

50KB
1K SLoC

ceviche-rs

Cargo Documentation Build Status Build Status Appveyor

服务/守护进程包装器。支持 Windows 和 macOS。


lib.rs:

ceviche 是一个用于编写服务/守护进程的包装器。

目前只支持 Windows 服务。Service 宏受到了 winservice 仓库的启发。

服务实现了一个服务主函数,通过调用 Service! 宏来生成。事件通过 rx 通道发送到服务。

 enum CustomServiceEvent {}

fn my_service_main(
    rx: mpsc::Receiver<ServiceEvent<CustomServiceEvent>>,
    _tx: mpsc::Sender<ServiceEvent<CustomServiceEvent>>,
    args: Vec<String>,
    standalone_mode: bool) -> u32 {
   loop {
       if let Ok(control_code) = rx.recv() {
           match control_code {
               ServiceEvent::Stop => break,
               _ => (),
           }
       }
   }
   0
}

Service!("Foobar", my_service_main);

Controller 是一个辅助工具,用于在系统上创建、删除、启动或停止服务。ceviche 还支持独立模式,其中服务代码作为常规可执行文件运行,这在开发和调试中可能很有用。

static SERVICE_NAME: &'static str = "foobar";
static DISPLAY_NAME: &'static str = "FooBar Service";
static DESCRIPTION: &'static str = "This is the FooBar service";

fn main() {
    let yaml = load_yaml!("cli.yml");
    let app = App::from_yaml(yaml);
    let matches = app.version(crate_version!()).get_matches();
    let cmd = matches.value_of("cmd").unwrap_or("").to_string();

    let mut controller = Controller::new(SERVICE_NAME, DISPLAY_NAME, DESCRIPTION);

    match cmd.as_str() {
        "create" => controller.create(),
        "delete" => controller.delete(),
        "start" => controller.start(),
        "stop" => controller.stop(),
        "standalone" => {
            let (tx, rx) = mpsc::channel();

            ctrlc::set_handler(move || {
                let _ = tx.send(ServiceEvent::Stop);
            }).expect("Failed to register Ctrl-C handler");

            my_service_main(rx, vec![], true);
        }
        _ => {
            let _result = controller.register(service_main_wrapper);
        }
    }
}

依赖关系

~1.6–9MB
~78K SLoC