Skip to content

Systemd Services

This guide covers configuring License Monitor to run as a systemd service on Linux systems.

  • Linux system with systemd (Ubuntu 16.04+, RHEL/CentOS 7+, Debian 9+)
  • Root or sudo access
  • License Monitor binary installed
  1. Download and install the binary

    Terminal window
    # Download latest release
    curl -L -o /tmp/license_monitor \
    "https://github.com/keithce/license_monitor/releases/latest/download/license_monitor-linux-x86_64"
    # Install to /usr/local/bin
    sudo install -m 755 /tmp/license_monitor /usr/local/bin/license_monitor
    # Verify installation
    /usr/local/bin/license_monitor --version
  2. Create service user

    Terminal window
    # Create system user (no home directory, no login shell)
    sudo useradd -r -s /sbin/nologin license-monitor
  3. Create directories

    Terminal window
    # Configuration directory
    sudo mkdir -p /etc/license-monitor
    # Log directory
    sudo mkdir -p /var/log/license-monitor
    sudo chown license-monitor:license-monitor /var/log/license-monitor
    # Runtime directory (optional, for PID file)
    sudo mkdir -p /run/license-monitor
    sudo chown license-monitor:license-monitor /run/license-monitor
  4. Create configuration file

    Terminal window
    sudo tee /etc/license-monitor/config.toml << 'EOF'
    # License Monitor Configuration
    [command_mode]
    command = "lmstat -a"
    interval_seconds = 300
    [api]
    enabled = true
    bind_address = "127.0.0.1"
    bind_port = 8080
    allow_public_bind = false
    rate_limit_requests = 100
    rate_limit_window_seconds = 60
    [daemon]
    log_file = "/var/log/license-monitor/license_monitor.log"
    log_level = "warn"
    [update]
    channel = "stable"
    auto_check = false
    EOF
    # Set ownership
    sudo chown -R license-monitor:license-monitor /etc/license-monitor
  5. Create systemd service file

    Terminal window
    sudo tee /etc/systemd/system/license-monitor.service << 'EOF'
    [Unit]
    Description=License Monitor Service
    Documentation=https://github.com/keithce/license_monitor
    After=network-online.target
    Wants=network-online.target
    [Service]
    Type=simple
    User=license-monitor
    Group=license-monitor
    # Environment
    Environment="RUST_BACKTRACE=1"
    # Working directory
    WorkingDirectory=/etc/license-monitor
    # Command
    ExecStart=/usr/local/bin/license_monitor \
    --config /etc/license-monitor/config.toml \
    --mode command \
    --daemon
    # Restart configuration
    Restart=on-failure
    RestartSec=10
    StartLimitBurst=5
    StartLimitIntervalSec=60
    # Resource limits
    LimitNOFILE=65536
    LimitNPROC=4096
    # Security hardening
    NoNewPrivileges=yes
    ProtectSystem=strict
    ProtectHome=yes
    PrivateTmp=yes
    PrivateDevices=yes
    ProtectKernelTunables=yes
    ProtectKernelModules=yes
    ProtectControlGroups=yes
    # Allow writing to log directory
    ReadWritePaths=/var/log/license-monitor
    # Logging
    StandardOutput=journal
    StandardError=journal
    SyslogIdentifier=license-monitor
    [Install]
    WantedBy=multi-user.target
    EOF
  6. Enable and start the service

    Terminal window
    # Reload systemd
    sudo systemctl daemon-reload
    # Enable service to start on boot
    sudo systemctl enable license-monitor
    # Start the service
    sudo systemctl start license-monitor
    # Check status
    sudo systemctl status license-monitor
CommandDescription
systemctl start license-monitorStart the service
systemctl stop license-monitorStop the service
systemctl restart license-monitorRestart the service
systemctl reload license-monitorReload configuration
systemctl status license-monitorCheck service status
systemctl enable license-monitorEnable start on boot
systemctl disable license-monitorDisable start on boot
Terminal window
# View recent logs
journalctl -u license-monitor -n 50
# Follow logs in real-time
journalctl -u license-monitor -f
# View logs since last boot
journalctl -u license-monitor -b
# View logs from specific time
journalctl -u license-monitor --since "2024-01-01 00:00:00"
# View logs with full output
journalctl -u license-monitor -o verbose
[Service]
ExecStart=/usr/local/bin/license_monitor \
--config /etc/license-monitor/config.toml \
--mode command \
--daemon
[Service]
ExecStart=/usr/local/bin/license_monitor \
--config /etc/license-monitor/config.toml \
--mode tail \
--file /var/log/flexlm/lmstat.log \
--daemon
[Service]
ExecStart=/usr/local/bin/license_monitor \
--config /etc/license-monitor/config.toml \
--mode api \
--api-host 0.0.0.0 \
--api-port 8080 \
--daemon
[Service]
ExecStart=/usr/local/bin/license_monitor \
--config /etc/license-monitor/config.toml \
--mode both \
--daemon

To run multiple License Monitor instances (e.g., for different license servers):

  1. Create instance-specific configuration

    Terminal window
    sudo mkdir -p /etc/license-monitor/instances/flexlm
    sudo mkdir -p /etc/license-monitor/instances/rlm
    # FlexLM configuration
    sudo tee /etc/license-monitor/instances/flexlm/config.toml << 'EOF'
    [command_mode]
    command = "lmstat -a -c 27000@flexlm-server"
    interval_seconds = 300
    [api]
    enabled = true
    bind_address = "127.0.0.1"
    bind_port = 8081
    [daemon]
    log_file = "/var/log/license-monitor/flexlm.log"
    log_level = "warn"
    EOF
    # RLM configuration
    sudo tee /etc/license-monitor/instances/rlm/config.toml << 'EOF'
    [command_mode]
    command = "rlmstat -a -c 5053@rlm-server"
    interval_seconds = 300
    [api]
    enabled = true
    bind_address = "127.0.0.1"
    bind_port = 8082
    [daemon]
    log_file = "/var/log/license-monitor/rlm.log"
    log_level = "warn"
    EOF
  2. Create template service file

    Terminal window
    sudo tee /etc/systemd/system/license-monitor@.service << 'EOF'
    [Unit]
    Description=License Monitor Service - %i
    Documentation=https://github.com/keithce/license_monitor
    After=network-online.target
    Wants=network-online.target
    [Service]
    Type=simple
    User=license-monitor
    Group=license-monitor
    WorkingDirectory=/etc/license-monitor/instances/%i
    ExecStart=/usr/local/bin/license_monitor \
    --config /etc/license-monitor/instances/%i/config.toml \
    --mode command \
    --daemon
    Restart=on-failure
    RestartSec=10
    # Security hardening
    NoNewPrivileges=yes
    ProtectSystem=strict
    ReadWritePaths=/var/log/license-monitor
    [Install]
    WantedBy=multi-user.target
    EOF
  3. Enable instances

    Terminal window
    sudo systemctl daemon-reload
    sudo systemctl enable license-monitor@flexlm
    sudo systemctl enable license-monitor@rlm
    sudo systemctl start license-monitor@flexlm
    sudo systemctl start license-monitor@rlm
[Service]
# Limit to 50% of one CPU
CPUQuota=50%
# Or limit CPU time
CPUAccounting=yes
[Service]
# Hard memory limit
MemoryMax=512M
# Soft memory limit
MemoryHigh=384M
[Service]
CPUQuota=100%
MemoryMax=512M
LimitNOFILE=65536
LimitNPROC=4096
[Service]
# Drop all capabilities
CapabilityBoundingSet=
AmbientCapabilities=
# No new privileges
NoNewPrivileges=yes
# Filesystem protection
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
# Kernel protection
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
# Network isolation (if not needed)
# PrivateNetwork=yes
# System call filtering
SystemCallArchitectures=native
SystemCallFilter=@system-service
SystemCallFilter=~@privileged @resources
Terminal window
# Check for configuration errors
/usr/local/bin/license_monitor --config /etc/license-monitor/config.toml --debug
# Check systemd logs
journalctl -u license-monitor -n 100 --no-pager
# Check for permission issues
ls -la /etc/license-monitor/
ls -la /var/log/license-monitor/
Terminal window
# Check restart count
systemctl show license-monitor --property=NRestarts
# Check for crash logs
journalctl -u license-monitor --since "10 minutes ago"
# Check resource limits
systemctl show license-monitor --property=MemoryCurrent
Terminal window
# Check CPU and memory usage
systemctl status license-monitor
# Detailed resource usage
systemd-cgtop -p
# Check for file descriptor limits
cat /proc/$(pgrep license_monitor)/limits