12 stable releases (3 major)
new 3.0.9 | Feb 13, 2025 |
---|---|
3.0.8 | Feb 12, 2025 |
2.0.0 | Feb 11, 2025 |
1.0.0 | Feb 11, 2025 |
0.1.1 | Feb 11, 2025 |
#369 in Development tools
1,517 downloads per month
Used in hyperlane-quick-start
16KB
192 lines
server-manager
server-manager
is a Rust library for managing server processes. It encapsulates service startup, shutdown, and background daemon mode. Users can specify the PID file, log file paths, and other configurations through custom settings, while also passing in their own asynchronous server function for execution. The library supports both synchronous and asynchronous operations. On Unix and Windows platforms, it enables background daemon processes.
Installation
To use this crate, you can run cmd:
cargo add server-manager
Use
use server_manager::*;
use std::fs;
use std::time::Duration;
let pid_file: String = "./process/test_pid.pid".to_string();
let _ = fs::remove_file(&pid_file);
let config: ServerManagerConfig = ServerManagerConfig {
pid_file: pid_file.clone(),
};
let dummy_server = || async {
tokio::time::sleep(Duration::from_secs(1)).await;
};
let manager = ServerManager::new(config, dummy_server);
let res: Result<(), Box<dyn std::error::Error>> = manager.start_daemon();
println!("start_daemon {:?}", res);
let res: Result<(), Box<dyn std::error::Error>> = manager.stop();
println!("stop {:?}", res);
manager.start().await;
let _ = fs::remove_file(&pid_file);
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
Contact
For any inquiries, please reach out to the author at ltpp-universe root@ltpp.vip.
Dependencies
~2.3–8MB
~58K SLoC