Systemd Services
This guide covers configuring License Monitor to run as a systemd service on Linux systems.
Prerequisites
Section titled “Prerequisites”- Linux system with systemd (Ubuntu 16.04+, RHEL/CentOS 7+, Debian 9+)
- Root or sudo access
- License Monitor binary installed
Installation
Section titled “Installation”-
Download and install the binary
Terminal window # Download latest releasecurl -L -o /tmp/license_monitor \"https://github.com/keithce/license_monitor/releases/latest/download/license_monitor-linux-x86_64"# Install to /usr/local/binsudo install -m 755 /tmp/license_monitor /usr/local/bin/license_monitor# Verify installation/usr/local/bin/license_monitor --version -
Create service user
Terminal window # Create system user (no home directory, no login shell)sudo useradd -r -s /sbin/nologin license-monitor -
Create directories
Terminal window # Configuration directorysudo mkdir -p /etc/license-monitor# Log directorysudo mkdir -p /var/log/license-monitorsudo chown license-monitor:license-monitor /var/log/license-monitor# Runtime directory (optional, for PID file)sudo mkdir -p /run/license-monitorsudo chown license-monitor:license-monitor /run/license-monitor -
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 = truebind_address = "127.0.0.1"bind_port = 8080allow_public_bind = falserate_limit_requests = 100rate_limit_window_seconds = 60[daemon]log_file = "/var/log/license-monitor/license_monitor.log"log_level = "warn"[update]channel = "stable"auto_check = falseEOF# Set ownershipsudo chown -R license-monitor:license-monitor /etc/license-monitor -
Create systemd service file
Terminal window sudo tee /etc/systemd/system/license-monitor.service << 'EOF'[Unit]Description=License Monitor ServiceDocumentation=https://github.com/keithce/license_monitorAfter=network-online.targetWants=network-online.target[Service]Type=simpleUser=license-monitorGroup=license-monitor# EnvironmentEnvironment="RUST_BACKTRACE=1"# Working directoryWorkingDirectory=/etc/license-monitor# CommandExecStart=/usr/local/bin/license_monitor \--config /etc/license-monitor/config.toml \--mode command \--daemon# Restart configurationRestart=on-failureRestartSec=10StartLimitBurst=5StartLimitIntervalSec=60# Resource limitsLimitNOFILE=65536LimitNPROC=4096# Security hardeningNoNewPrivileges=yesProtectSystem=strictProtectHome=yesPrivateTmp=yesPrivateDevices=yesProtectKernelTunables=yesProtectKernelModules=yesProtectControlGroups=yes# Allow writing to log directoryReadWritePaths=/var/log/license-monitor# LoggingStandardOutput=journalStandardError=journalSyslogIdentifier=license-monitor[Install]WantedBy=multi-user.targetEOF -
Enable and start the service
Terminal window # Reload systemdsudo systemctl daemon-reload# Enable service to start on bootsudo systemctl enable license-monitor# Start the servicesudo systemctl start license-monitor# Check statussudo systemctl status license-monitor
Service Management
Section titled “Service Management”Common Commands
Section titled “Common Commands”| Command | Description |
|---|---|
systemctl start license-monitor | Start the service |
systemctl stop license-monitor | Stop the service |
systemctl restart license-monitor | Restart the service |
systemctl reload license-monitor | Reload configuration |
systemctl status license-monitor | Check service status |
systemctl enable license-monitor | Enable start on boot |
systemctl disable license-monitor | Disable start on boot |
Viewing Logs
Section titled “Viewing Logs”# View recent logsjournalctl -u license-monitor -n 50
# Follow logs in real-timejournalctl -u license-monitor -f
# View logs since last bootjournalctl -u license-monitor -b
# View logs from specific timejournalctl -u license-monitor --since "2024-01-01 00:00:00"
# View logs with full outputjournalctl -u license-monitor -o verboseConfiguration Variations
Section titled “Configuration Variations”Command Mode Only
Section titled “Command Mode Only”[Service]ExecStart=/usr/local/bin/license_monitor \ --config /etc/license-monitor/config.toml \ --mode command \ --daemonTail Mode Only
Section titled “Tail Mode Only”[Service]ExecStart=/usr/local/bin/license_monitor \ --config /etc/license-monitor/config.toml \ --mode tail \ --file /var/log/flexlm/lmstat.log \ --daemonAPI Mode Only
Section titled “API Mode Only”[Service]ExecStart=/usr/local/bin/license_monitor \ --config /etc/license-monitor/config.toml \ --mode api \ --api-host 0.0.0.0 \ --api-port 8080 \ --daemonCombined Mode
Section titled “Combined Mode”[Service]ExecStart=/usr/local/bin/license_monitor \ --config /etc/license-monitor/config.toml \ --mode both \ --daemonMultiple Instances
Section titled “Multiple Instances”To run multiple License Monitor instances (e.g., for different license servers):
-
Create instance-specific configuration
Terminal window sudo mkdir -p /etc/license-monitor/instances/flexlmsudo mkdir -p /etc/license-monitor/instances/rlm# FlexLM configurationsudo tee /etc/license-monitor/instances/flexlm/config.toml << 'EOF'[command_mode]command = "lmstat -a -c 27000@flexlm-server"interval_seconds = 300[api]enabled = truebind_address = "127.0.0.1"bind_port = 8081[daemon]log_file = "/var/log/license-monitor/flexlm.log"log_level = "warn"EOF# RLM configurationsudo tee /etc/license-monitor/instances/rlm/config.toml << 'EOF'[command_mode]command = "rlmstat -a -c 5053@rlm-server"interval_seconds = 300[api]enabled = truebind_address = "127.0.0.1"bind_port = 8082[daemon]log_file = "/var/log/license-monitor/rlm.log"log_level = "warn"EOF -
Create template service file
Terminal window sudo tee /etc/systemd/system/license-monitor@.service << 'EOF'[Unit]Description=License Monitor Service - %iDocumentation=https://github.com/keithce/license_monitorAfter=network-online.targetWants=network-online.target[Service]Type=simpleUser=license-monitorGroup=license-monitorWorkingDirectory=/etc/license-monitor/instances/%iExecStart=/usr/local/bin/license_monitor \--config /etc/license-monitor/instances/%i/config.toml \--mode command \--daemonRestart=on-failureRestartSec=10# Security hardeningNoNewPrivileges=yesProtectSystem=strictReadWritePaths=/var/log/license-monitor[Install]WantedBy=multi-user.targetEOF -
Enable instances
Terminal window sudo systemctl daemon-reloadsudo systemctl enable license-monitor@flexlmsudo systemctl enable license-monitor@rlmsudo systemctl start license-monitor@flexlmsudo systemctl start license-monitor@rlm
Resource Limits
Section titled “Resource Limits”CPU Limits
Section titled “CPU Limits”[Service]# Limit to 50% of one CPUCPUQuota=50%
# Or limit CPU timeCPUAccounting=yesMemory Limits
Section titled “Memory Limits”[Service]# Hard memory limitMemoryMax=512M
# Soft memory limitMemoryHigh=384MCombined Resource Limits
Section titled “Combined Resource Limits”[Service]CPUQuota=100%MemoryMax=512MLimitNOFILE=65536LimitNPROC=4096Security Hardening
Section titled “Security Hardening”Minimal Permissions
Section titled “Minimal Permissions”[Service]# Drop all capabilitiesCapabilityBoundingSet=AmbientCapabilities=
# No new privilegesNoNewPrivileges=yes
# Filesystem protectionProtectSystem=strictProtectHome=yesPrivateTmp=yesPrivateDevices=yes
# Kernel protectionProtectKernelTunables=yesProtectKernelModules=yesProtectKernelLogs=yesProtectControlGroups=yes
# Network isolation (if not needed)# PrivateNetwork=yes
# System call filteringSystemCallArchitectures=nativeSystemCallFilter=@system-serviceSystemCallFilter=~@privileged @resourcesTroubleshooting
Section titled “Troubleshooting”Service Won’t Start
Section titled “Service Won’t Start”# Check for configuration errors/usr/local/bin/license_monitor --config /etc/license-monitor/config.toml --debug
# Check systemd logsjournalctl -u license-monitor -n 100 --no-pager
# Check for permission issuesls -la /etc/license-monitor/ls -la /var/log/license-monitor/Service Keeps Restarting
Section titled “Service Keeps Restarting”# Check restart countsystemctl show license-monitor --property=NRestarts
# Check for crash logsjournalctl -u license-monitor --since "10 minutes ago"
# Check resource limitssystemctl show license-monitor --property=MemoryCurrentPerformance Issues
Section titled “Performance Issues”# Check CPU and memory usagesystemctl status license-monitor
# Detailed resource usagesystemd-cgtop -p
# Check for file descriptor limitscat /proc/$(pgrep license_monitor)/limitsNext Steps
Section titled “Next Steps”- Windows Services - Windows deployment
- Reverse Proxy - Nginx/Apache configuration
- Production Setup - Production hardening