Skip to content

crates-dev/server-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

server-manager

Official Documentation

Api Docs

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 server = || async {
    tokio::time::sleep(Duration::from_secs(1)).await;
};
let mut manager: ServerManager = ServerManager::new();
manager
    .set_pid_file(&pid_file)
    .set_start_hook(|| async {
        println!("Before start daemon hook executed");
    })
    .set_server_hook(server)
    .set_stop_hook(|| async {
        println!("Before stop hook executed");
    });
let res: ServerManagerResult = manager.start_daemon().await;
println!("start_daemon {:?}", res);
let res: ServerManagerResult = manager.stop().await;
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 root@ltpp.vip.

About

server-manager is a rust library for managing server processes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages