jagrosh / MusicBot

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

Problem with linux .service startup #410

Closed TheDjRider closed 4 years ago

TheDjRider commented 4 years ago

Hello,

When i create subuser and edit the service file my code is:

[Unit] Description=EternalRadio Discord Bot After=network.target

[Service] WorkingDirectory=/home/eternalradio/ User=eternalradio Group=eternalradio ExecStart=nohup java -Dnogui=true -jar JMusic.jar &

RestartSec=15 Restart=always

[Install] WantedBy=multi-user.target

It start without errors but give:

eternalradio.service - EternalRadio Discord Bot Loaded: loaded (/lib/systemd/system/eternalradio.service; enabled; vendor preset: enabled) Active: activating (auto-restart) (Result: exit-code) since Wed 2020-05-20 11:01:30 EEST; 12s ago Process: 5865 ExecStart=/usr/bin/nohup java -Dnogui=true -jar JMusic.jar & (code=exited, status=1/FAILURE) Main PID: 5865 (code=exited, status=1/FAILURE)

and also the bot didn't start. If i load it on screen everything is ok but with this future is basically better to have it auto-load on system boot.

Also i have try other way to add startup command into run.sh file and put it into etrnalradio.service but again give the same error.

Sanduhr32 commented 4 years ago

Did it generate a crash log? (The music bot of course, not the service)

TheDjRider commented 4 years ago

No, nothing but sent in the message above.

jagrosh commented 4 years ago

I can't really help without more logs, but I'm guessing that the issue is using nohup ... & in a service; nohup is for terminal use, as it makes a process ignore the 'hangup' of closing the terminal, and & is for running in the background, which in theory a service would already be doing. I would recommend trying different variations without nohup or &. Feel free to re-open this issue if you try those and can produce more logs that might hint at the origin of the issue.

pbanj commented 3 years ago

if anyone else is having this issue here is my working one. make sure you change username, group, and working directory to your stuff. i was having the same issue and google brought me here @jagrosh was right about removing nohup and &. you also need the ExecStartPre=/bin/sh -c 'until ping -c1 google.com; do sleep 1; done;' so it will wait for a network connection. otherwise it will just error.

[Unit]
Description=musicbot systemd service unit file.

[Service]
ExecStartPre=/bin/sh -c 'until ping -c1 google.com; do sleep 1; done;'
WorkingDirectory=/home/musicbot/musicbot/
User=musicbot
Group=musicbot
ExecStart=java -Dnogui=true -jar JMusicBot.jar

RestartSec=15
Restart=always

[Install]
WantedBy=multi-user.target

image