win-service-rs

RustFS Manager & win-service-rs

English|中文

Project Overview

rustfs-manager is a Windows service management tool developed in Rust, built on top of the win-service-rs library, designed to provide functionality similar to Linux’s systemctl. It manages the lifecycle of rustfs.exe or similar services, supporting operations such as installation, starting, stopping, status querying, and uninstallation. win-service-rs is a standalone Rust crate that encapsulates the Windows Service Control Manager (SCM) APIs, offering a safe and user-friendly interface for any Windows service management needs.

This project leverages Rust’s memory safety and the robust capabilities of windows-rs to deliver an efficient and reliable service management solution. Whether for enterprise applications or automation scripts, rustfs-manager and win-service-rs provide flexible support.

Features

Installation

  1. Install Rust: Ensure the Rust toolchain is installed and updated to the latest stable version:
    rustup update stable
    
  2. Clone the Project:
    git clone https://github.com/houseme/win-service-rs.git
    cd win-service-rs/examples/rustfs_manager
    
  3. Install Dependencies: Dependencies are specified in Cargo.toml. Build the project with:
    cargo build --release
    
  4. Configure Environment: Edit config/config.toml to update parameters like exe_path, ensuring the rustfs.exe path is valid.

Usage

rustfs-manager provides a command-line interface (CLI) with the following commands:

Run cargo run -- --help to see the full list of commands.

Deployment Guide

  1. Build Production Binary:
    cargo build --release
    
  2. Copy Files: Copy target/release/rustfs-manager.exe and config/config.toml to the target server.

  3. Run Deployment Script: Use the provided PowerShell script for automated deployment:
    .\scripts\deploy.ps1
    
  4. Verify Deployment: Check service status:
    sc query RustFSManager
    

win-service-rs Usage

win-service-rs is a standalone Rust crate that encapsulates Windows SCM APIs, providing a safe and user-friendly interface for service management. Here’s how to use it:

  1. Add Dependency: Add to your Cargo.toml:
    [dependencies]
    win-service-rs = { version = "0.1.0", features = ["async"] }
    
  2. Example Code:
    use win_service_rs::{ServiceConfig, ServiceManager, StartType};
    
    #[tokio::main]
    async fn main() -> Result<(), win_service_rs::Error> {
        let mut manager = ServiceManager::new("RustFS")?;
        let config = ServiceConfig::new(
            "C:\\path\\to\\rustfs.exe".to_string(),
            "RustFS Service".to_string(),
        )
        .with_description("RustFS File System Service".to_string())
        .with_start_type(StartType::Demand);
    
        manager.install(&config)?;
        manager.async_start().await?;
        let status = manager.async_status().await?;
        println!("Service status: {:?}", status);
        manager.async_stop().await?;
        manager.uninstall()?;
        Ok(())
    }
    
  3. Asynchronous Support: With the async feature enabled, use async_start, async_stop, and async_status methods for high-concurrency scenarios.

  4. Error Handling: The crate provides a custom Error type to handle SCM errors (e.g., access denied, service not found).

Notes

References

  1. windows-rs Resources:
  2. Windows API Documentation:
  3. Rust Ecosystem:

License

This project is licensed under the MIT ,Apache License. See the LICENSE-APACHE,LICENSE-MIT file for details.