Skip to content

A lightweight REST API server written in Rust that provides HTTP endpoints for managing systemd services. Features include service start/stop/restart, status monitoring, log retrieval, and Swagger UI documentation.

Notifications You must be signed in to change notification settings

vffuunnyy/sysdik

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sysdik

A lightweight HTTP REST API for systemd service management written in Rust.

Overview

sysdik provides a simple and efficient way to manage systemd services through HTTP endpoints. Built with modern Rust technologies, it offers a clean REST API with automatic OpenAPI documentation and Swagger UI integration.

Key Features

  • Service Management: Start, stop, restart, and reload systemd services
  • Status Monitoring: Get detailed service status and information
  • Log Access: Retrieve service logs with filtering options
  • System Control: Reload systemd daemon and send custom signals
  • Unit Listing: Browse all available systemd units
  • API Documentation: Auto-generated OpenAPI specs with Swagger UI
  • Lightweight: Minimal resource usage with async Rust performance

Installation

Quick Install

Install and start the service using the prebuilt binary:

curl -fsSL https://raw.githubusercontent.com/vffuunnyy/sysdik/main/install.sh | sudo bash

This script will:

  • Download the latest release binary
  • Install it to /usr/local/bin/sysdik
  • Create systemd service file at /etc/systemd/system/sysdik.service
  • Enable and start the service

Manual Installation

  1. Download the latest release from GitHub Releases
  2. Extract and copy the binary to /usr/local/bin/
  3. Create a systemd service file (see systemd/sysdik.service example)
  4. Enable and start the service

Building from Source

git clone https://github.com/vffuunnyy/sysdik.git
cd sysdik
cargo build --release
sudo cp target/release/sysdik /usr/local/bin/

Usage

Starting the Server

# Default configuration (0.0.0.0:3000)
sudo sysdik

# Custom host and port
sudo sysdik --host 127.0.0.1 --port 8080

# Using environment variables
export SYSDIK_HOST=127.0.0.1
export SYSDIK_PORT=8080
sudo sysdik

API Endpoints

Once running, the API will be available at http://localhost:3000 (or your configured address).

Service Management

# Get service information
curl http://localhost:3000/service/docker/info

# Start a service
curl -X POST http://localhost:3000/service/docker/start

# Stop a service
curl -X POST http://localhost:3000/service/docker/stop

# Restart a service
curl -X POST http://localhost:3000/service/docker/restart

# Get service status
curl http://localhost:3000/service/docker/status

# Reload service configuration
curl -X POST http://localhost:3000/service/docker/reload

System Operations

# List all units
curl http://localhost:3000/units

# Reload systemd daemon
curl -X POST http://localhost:3000/daemon/reload

# Send signal to service (e.g., SIGTERM = 15)
curl -X POST http://localhost:3000/service/docker/kill/15

Logs

# Get recent logs
curl http://localhost:3000/service/docker/logs

# Get logs with parameters
curl "http://localhost:3000/service/docker/logs?lines=50&since=2024-01-01"

API Documentation

Interactive Swagger UI documentation is available at:

  • Swagger UI: http://localhost:3000/docs
  • OpenAPI JSON: http://localhost:3000/openapi.json
  • OpenAPI YAML: http://localhost:3000/openapi.yaml

Example Response

{
    "name": "docker.service",
    "description": "Docker Application Container Engine",
    "load_state": "loaded",
    "active_state": "active",
    "sub_state": "running"
}

Configuration

Environment Variables

  • SYSDIK_HOST: Bind address (default: 0.0.0.0)
  • SYSDIK_PORT: Port number (default: 3000)

Logging

Configure logging levels using the RUST_LOG environment variable:

export RUST_LOG=info,sysdik=debug

Security Considerations

  • Root Privileges: Requires root privileges to interact with systemd
  • Network Access: Consider firewall rules and access restrictions
  • Authentication: No built-in authentication - use reverse proxy if needed

Requirements

  • Linux system with systemd
  • Root or appropriate sudo permissions
  • Network access to the configured port

Technology Stack

  • Language: Rust (2024 edition)
  • Web Framework: Axum
  • Async Runtime: Tokio
  • Systemd Integration: zbus (D-Bus client)
  • Documentation: utoipa (OpenAPI generation)
  • Logging: tracing + tracing-subscriber

Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.

License

This project is open source. See the LICENSE file for details.

About

A lightweight REST API server written in Rust that provides HTTP endpoints for managing systemd services. Features include service start/stop/restart, status monitoring, log retrieval, and Swagger UI documentation.

Topics

Resources

Stars

Watchers

Forks