cross-platform-service

Crates.iocross-platform-service
lib.rscross-platform-service
version0.1.0
sourcesrc
created_at2021-11-02 06:57:49.158504
updated_at2021-11-02 06:57:49.158504
descriptionProvides facilities to create and manage cross platform service
homepage
repository
max_upload_size
id475604
size138,755
Hamed J.I (hamed-ji)

documentation

README

cross-platform-service

The "cross-platform-service" crate lets you developing cross-platform services and service managers for Windows, Linux, and macOS. It supports install, delete, start and stop.

On Windows, API is called by using the microsoft/windows-rs crate, And it is also possible to call the Windows API directory if the service has special needs for Windows.

On Linux, D-Bus used for communication with systemd. The default behavior is defining a systemd service unit, in "/etc/systemd/system" path.

Getting started


use std::fs::OpenOptions;
use std::io::Write;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;

use service_manager_rs::service::start_service;

const SERVICE_NAME: &str = "MyCrPlSVC";

fn main() {
    start_service(SERVICE_NAME, service_main);
}

fn service_main(running: Arc<AtomicBool>) {
    // The following code will run service for a minute and check if service stopped every
    // 100 milli-seconds
    // Return from this function will stop service
    for _ in 0..600 {
        if !running.load(Ordering::Relaxed) {
            // Write stopping service codes here
            // In linux SIGTERM signal set running to false and in Windows service stop command
            // will do the same

            return;
        }

        std::thread::sleep(Duration::from_millis(100));
    }
}

To compile the project on Linux, D-Bus developing libraries are required, which is may be installed with the following command:

apt install libdbus-1-dev

Examples

cross-platform

Install a cross-platform Service

Delete a cross-platform service

Start a cross-platform service

Stop a cross-platform service

Windows Services

Install Windows service

Commit count: 0

cargo fmt