Zinit Client
A Rust client library for interacting with the Zinit service manager.
Features
- Complete API coverage for all Zinit operations
- Robust error handling with custom error types
- Automatic reconnection on socket errors
- Retry mechanisms for transient failures
- Async/await support using Tokio
- Strongly typed service states and responses
- Efficient log streaming
Installation
Add this to your Cargo.toml:
[]
= "0.2.0"
Building
To build the library, you need Rust and Cargo installed. Then run:
# Build the library
# Build with optimizations
# Build the examples
Usage
use ;
async
Configuration
You can customize the client behavior using ClientConfig:
use ;
use Duration;
let config = ClientConfig ;
let client = with_config;
Examples
See the examples directory for more usage examples:
Running Examples
To run the examples, you need a running Zinit instance. The examples will try to connect to Zinit at the default socket path (/var/run/zinit.sock).
# Basic usage example (requires Zinit)
# Service management example (interactive, requires Zinit)
# Log streaming example (interactive, requires Zinit)
# Mock server demo (doesn't require Zinit)
If you want to use a different socket path, you'll need to modify the examples. Open the example file and change the socket path in the ZinitClient::new() call:
// Change this line
let client = new;
// To use a custom socket path
let client = new;
Running Without Zinit
If you don't have Zinit running, you can still test the client by using the mock server provided in the tests directory. The mock server simulates a Zinit instance for testing purposes.
Here's how to use it:
use PathBuf;
use tempdir;
use ZinitClient;
use MockZinitServer;
async
Note: The examples assume Zinit is running and listening on the default socket path (/var/run/zinit.sock). If your Zinit instance is using a different socket path, you'll need to modify the examples accordingly.
Testing
The library includes both integration tests and a mock server for testing without requiring a real Zinit instance.
Running Tests
# Run all tests
# Run a specific test
All tests use the mock server, so they can be run without requiring a real Zinit instance. The mock server simulates a Zinit instance for testing purposes, allowing for reliable and reproducible tests.
CI/CD
This project uses GitHub Actions for continuous integration and delivery:
- Rust CI: Builds the project, runs tests, and checks code formatting and linting
- Rust Examples: Builds and runs all examples to ensure they work correctly
- Code Coverage: Generates code coverage reports and uploads them to Codecov
- Security Scan: Performs security audits on dependencies using cargo-audit and cargo-deny
- Publish: Automatically publishes the crate to crates.io when a new release is created
All workflows run on every push to any branch and on all pull requests.
License
See LICENSE file for details.