Systemd Setup

Running mtrack as a systemd service allows it to start automatically on boot and restart if it crashes.

Generating the Service File

Generate a systemd service file:

1
sudo mtrack systemd > /etc/systemd/system/mtrack.service

Configuration File

The service expects your player configuration to be defined in /etc/default/mtrack:

1
sudo nano /etc/default/mtrack

Add:

# The configuration for the mtrack player.
MTRACK_CONFIG=/mnt/storage/mtrack.yaml

Service Requirements

The service expects:

  • mtrack to be available at /usr/local/bin/mtrack
  • Configuration file path in /etc/default/mtrack

Starting the Service

Start the service:

1
sudo systemctl start mtrack

Enable it to start on boot:

1
sudo systemctl enable mtrack

Service Management

Check Status

1
sudo systemctl status mtrack

View Logs

1
journalctl -u mtrack

Follow logs in real-time:

1
journalctl -u mtrack -f

Restart Service

1
sudo systemctl restart mtrack

Stop Service

1
sudo systemctl stop mtrack

Disable Auto-Start

1
sudo systemctl disable mtrack

Troubleshooting

Service Fails to Start

Check the logs:

1
journalctl -u mtrack -n 50

Common issues:

  • Configuration file path incorrect
  • mtrack binary not found at /usr/local/bin/mtrack
  • Permission issues accessing audio/MIDI devices
  • Configuration file syntax errors

Permission Issues

Ensure the service user has access to audio devices:

1
2
3
4
5
# Check which user the service runs as
sudo systemctl show mtrack | grep User

# Add user to audio group (replace 'user' with actual username)
sudo usermod -a -G audio user

Device Access

If devices aren’t accessible, you may need udev rules or to run the service as a specific user. Edit the service file:

1
sudo systemctl edit mtrack

Add:

1
2
3
[Service]
User=your-username
Group=audio

Then reload and restart:

1
2
sudo systemctl daemon-reload
sudo systemctl restart mtrack