jagrosh / MusicBot

🎶 A Discord music bot that's easy to set up and run yourself!
https://jmusicbot.com
Apache License 2.0
5.38k stars 2.57k forks source link

[Wiki edit] Feature a systemd example file #597

Closed Wobak closed 6 months ago

Wobak commented 3 years ago

Is your feature request related to a problem? Please describe. No way to put the server headless on an auto startup mechanism

Describe the solution you'd like Example systemd service file

Describe the basic flow/steps of using this feature How this feature would be used:

  1. In the setup alongside the example config.txt

Additional context I created the file and put it here as an example :

Have you confirmed that this idea is not already described here? Yes

[Unit]
Description=JMusic Bot
After=network.target network-online.target

[Service]
Environment=JMusicDIR=/opt/JMusicBot
Environment=JMusicExec=JMusicBot-current.jar
Environment=JMusicCfg=config.txt
Environment=LC_ALL=en_US.UTF-8
Environment=LANG=en_US.UTF-8
ExecStart=/usr/bin/java -Dnogui=true -Dconfig=${JMusicDIR}/${JMusicCfg} -jar ${JMusicDIR}/${JMusicExec}
Type=simple
User=JMusic
Group=JMusic
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3

Then :

# systemctl start discordmusicbot.service
# systemctl status discordmusicbot.service
● discordmusicbot.service - JMusic Bot
   Loaded: loaded (/etc/systemd/system/discordmusicbot.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-02-08 14:19:52 CET; 2s ago
 Main PID: 9263 (java)
    Tasks: 27 (limit: 410012)
   Memory: 176.6M
   CGroup: /system.slice/discordmusicbot.service
           └─9263 /usr/bin/java -Dnogui=true -Dconfig=/opt/JMusicBot/config.txt -jar /opt/JMusicBot/JMusicBot-current.jar

Feb 08 14:19:52 newbox.wobak.fr systemd[1]: Started JMusic Bot.
Feb 08 14:19:55 newbox.wobak.fr java[9263]: [14:19:55] [WARN] [Settings]: Failed to load server settings (this is normal if no settings have been set ye>
Feb 08 14:19:55 newbox.wobak.fr java[9263]: [14:19:55] [INFO] [Startup]: Loaded config from /opt/JMusicBot/config.txt
MichailiK commented 3 years ago

This may fit more in the setup wiki page, or perhaps a separate wiki page: Using service managers for JMusicBot.

Osanchez commented 3 years ago

so is this an open issue to get correct systemd configuration, or request to update the wiki with configuration steps?

MichailiK commented 3 years ago

Latter, a request to update the Wiki with a systemd example.

Osanchez commented 3 years ago

still new to systemd, but was able to get it working with this config. Added isntall section to make sure network is working before it tries to run the bot (at least from my understanding)

[Unit]
Description=JMusic Bot
After=network-online.target

[Service]
Environment=JMusicDIR=/home/BotUser/Musicbot
Environment=JMusicExec=JMusicBot-0.3.5.jar
Environment=JMusicCfg=config.txt
Environment=LC_ALL=en_US.UTF-8
Environment=LANG=en_US.UTF-8
ExecStart=/usr/bin/java -Dnogui=true -Dconfig=${JMusicDIR}/${JMusicCfg} -jar ${JMusicDIR}/${JMusicExec}
Type=simple
User=BotUser
Restart=on-failure

[Install]
WantedBy=network-online.target

as a pre-req, I had a non root user created on my ubuntu machine named BotUser.

unit file will be created under (musicbot.service) /etc/systemd/system/

commands to enable and add service to systemd sudo systemctl start musicbot.service sudo systemctl enable musicbot.service

any changes to service file you will need to run sudo systemctl daemon-reload

Wobak commented 3 years ago

Hi,

I had already put one in my first comment :)

MichailiK commented 6 months ago

The running as a service page has been added a good while ago & this issue is still open, whoops! Well... it's there now :)