12 releases (stable)
new 3.0.6 | Feb 12, 2025 |
---|---|
3.0.2 | Feb 11, 2025 |
2.0.0 | Feb 11, 2025 |
1.0.0 | Feb 11, 2025 |
0.1.1 | Feb 11, 2025 |
#503 in Development tools
292 downloads per month
Used in hyperlane-quick-start
14KB
128 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 platforms, it enables background daemon processes, while on non-Unix platforms, it returns an appropriate error message.
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 = "test_pid.pid".to_string();
let _ = fs::remove_file(&pid_file);
let config: ServerManagerConfig = ServerManagerConfig {
pid_file: pid_file.clone(),
stdout_log: "test_stdout.log".to_string(),
stderr_log: "test_stderr.log".to_string(),
};
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