Skip to content

Running as a systemd Service (Linux)

This guide explains how to run TinyMonitor as a background service on Linux using systemd.

Quick Setup

The easiest way to install TinyMonitor as a service:

sudo tinymonitor service install

This will:

  1. Create /etc/tinymonitor/ directory (if needed)
  2. Create the systemd service file
  3. Enable the service to start on boot
  4. Start the service

With Custom Configuration

sudo tinymonitor service install -c /path/to/your/config.toml

Manual Setup

If you prefer manual control over the service configuration:

1. Create the service file

sudo nano /etc/systemd/system/tinymonitor.service
[Unit]
Description=TinyMonitor - Lightweight System Monitoring
Documentation=https://github.com/Gu1llaum-3/tinymonitor
After=network.target

[Service]
Type=simple
User=nobody
Group=nogroup
ExecStart=/usr/local/bin/tinymonitor -c /etc/tinymonitor/config.toml
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal

# Security hardening
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=read-only
PrivateTmp=true
ReadOnlyPaths=/

[Install]
WantedBy=multi-user.target

2. Reload systemd

sudo systemctl daemon-reload

3. Enable and start the service

sudo systemctl enable tinymonitor
sudo systemctl start tinymonitor

Management Commands

Check status

sudo systemctl status tinymonitor

Or use the built-in command:

tinymonitor service status

View logs

# Live logs
sudo journalctl -u tinymonitor -f

# Last 100 lines
sudo journalctl -u tinymonitor -n 100

# Logs since last boot
sudo journalctl -u tinymonitor -b

# Logs from specific time
sudo journalctl -u tinymonitor --since "1 hour ago"

Restart service

After changing the configuration:

sudo systemctl restart tinymonitor

Stop service

sudo systemctl stop tinymonitor

Disable service

Prevent from starting on boot:

sudo systemctl disable tinymonitor

Service User

By default, the service runs as the nobody user for security. If you need to monitor paths that require specific permissions, you can change the user in the service file:

[Service]
User=root
Group=root

Then reload:

sudo systemctl daemon-reload
sudo systemctl restart tinymonitor

Uninstall Service

sudo tinymonitor service uninstall

This removes the service but preserves your configuration files.

Troubleshooting

Service fails to start

Check the logs:

sudo journalctl -u tinymonitor -n 50 --no-pager

Common issues:

  • Configuration error: Run tinymonitor validate -c /etc/tinymonitor/config.toml
  • Permission denied: Check file permissions on config file
  • Binary not found: Verify which tinymonitor returns /usr/local/bin/tinymonitor

Service starts but stops immediately

The configuration might be invalid. Test manually:

tinymonitor -c /etc/tinymonitor/config.toml

See Also