When it comes to placing your Discord bot's executable JAR file and related files on a Linux system, especially when you're setting up a systemd service, you should consider the Linux Filesystem Hierarchy Standard (FHS) and best practices for service management. Since you've created a systemd service running under a user without a home folder, you'll need to decide on an appropriate location for your JAR file and any associated configuration or data files.
For the Executable JAR File
-
/usr/local/bin or /usr/local/lib/your-bot-name:
/usr/local/bin is typically used for executables. If your JAR file is the main executable, you could place a symbolic link here pointing to the actual JAR file located elsewhere (like /usr/local/lib/your-bot-name/your-bot.jar).
/usr/local/lib is more commonly used for libraries and collections of files that are not directly executed. You could place your JAR file and related libraries here in a subdirectory named after your bot.
-
/opt/your-bot-name:
/opt is a directory for optional application software packages. Placing your bot's JAR file and related files in /opt/your-bot-name is a good practice, as it keeps your bot's files separate and contained. This is a common location for third-party applications.
For Configuration Files
- /etc/your-bot-name:
- Configuration files for your bot should be stored in
/etc/your-bot-name. This follows the convention of storing configuration files in /etc, and using a subdirectory named after your application helps keep things organized.
For Data or Log Files
- /var/lib/your-bot-name for data and /var/log/your-bot-name for logs:
- Data that your bot generates and needs to operate should be stored in
/var/lib/your-bot-name.
- Log files should be written to
/var/log/your-bot-name. Make sure the service user has write permissions in these directories.
systemd Service File Considerations
In your systemd service file, you can specify the user and group that the service runs under. Ensure that this user has read access to your JAR file and any necessary configuration files, and write access to any directories where your bot needs to write data or logs.
Here's a simple example of a systemd service file that assumes your JAR file is in /usr/local/lib/your-bot-name/your-bot.jar and you're running it as a user named botuser:
[Unit]
Description=Your Discord Bot
After=network.target
[Service]
User=botuser
ExecStart=/usr/bin/java -jar /usr/local/lib/your-bot-name/your-bot.jar
Restart=always
[Install]
WantedBy=multi-user.target
Permissions
Make sure to set the appropriate permissions for the user running the service. For example, if you place your bot's files in /usr/local/lib/your-bot-name, you might do:
sudo chown -R botuser:botgroup /usr/local/lib/your-bot-name
sudo chmod -R 500 /usr/local/lib/your-bot-name
Adjust the paths and permissions according to your setup.
Conclusion
For a Discord bot running as a systemd service under a dedicated user without a home directory, consider placing the JAR file in /usr/local/lib/your-bot-name or /opt/your-bot-name, configuration files in /etc/your-bot-name, and data or logs in /var/lib/your-bot-name and /var/log/your-bot-name, respectively. Always follow best practices for security and adhere to the Linux FHS as closely as possible.