Systemd Service Setup
Running Lavalink as a systemd service ensures that it starts automatically on boot, restarts on failure, and integrates seamlessly with your Linux system’s service management.This is the recommended way to run Lavalink on Linux production servers.
Prerequisites
Verify systemd is available
Ensure your Linux distribution uses systemd:You should see version information for systemd.
Install Lavalink binary
Follow the Binary Installation guide to download and set up Lavalink before proceeding.Make sure you have:
- Downloaded
Lavalink.jar - Created an
application.ymlconfiguration file - Tested that Lavalink runs correctly
Service Configuration
Create the systemd service file
Create a new service file at Add the following configuration, replacing the values in
/usr/lib/systemd/system/lavalink.service:<> brackets with your actual values:lavalink.service
Example configuration
Here’s a concrete example for a user named
musicbot with Lavalink installed in /home/musicbot/lavalink:lavalink.service
Enable the service
Enable the service to start automatically on boot:You should see output confirming the service has been enabled.
Managing the Service
Check service status
View logs
Follow logs in real-time
View recent logs
Restart the service
Stop the service
Disable auto-start on boot
Memory Configuration
Adjust the memory allocation in theExecStart line of your service file:
- Small bot (< 10 servers): 512MB - 1GB (
-Xmx1G) - Medium bot (10-100 servers): 1GB - 2GB (
-Xmx2G) - Large bot (100+ servers): 2GB - 4GB+ (
-Xmx4G)
After modifying the service file, run
sudo systemctl daemon-reload and sudo systemctl restart lavalink to apply changes.Additional Java Options
You can add additional Java options to optimize performance:-Xmx4G- Maximum heap size-Xms4G- Initial heap size (matching Xmx reduces garbage collection overhead)-XX:+UseG1GC- Use G1 garbage collector (recommended for most cases)-XX:+ParallelRefProcEnabled- Enable parallel reference processing
Troubleshooting
Service fails to start
If the service fails to start, check the logs:- Permission denied: Ensure the user specified in the service file has read/execute permissions on
Lavalink.jar - Java not found: Install Java 17 or higher and ensure it’s in the system PATH
- Configuration errors: Verify your
application.ymlis valid
Check file permissions
Service keeps restarting
If the service is constantly restarting, there’s likely a configuration error. Check the logs:Security Considerations
Create a dedicated user
It’s best practice to create a dedicated user for running Lavalink:Next Steps
Configuration
Learn how to configure sources, plugins, and advanced settings
Troubleshooting
Having issues? Check our troubleshooting guide
Monitoring
Set up monitoring and metrics collection
Clients
Choose a client library to connect your bot to Lavalink