-1

I have a discord bot that run on my server. I wanted to create a service in systemd instead of using the shell to start by hand. I want the bot to restart when it fails or it is stopped. So I put Restart=always in my service file. When tell the bot to stop it restart without any problems. But after 3 hours and 51 minutes of running the service stops without any reason and I'm not able to tell why.

The bot is a python module and I have a python script start_bot.py that starts the bot.

Here is the output of journalctl:

Apr 14 20:49:56 sapinet927 systemd[23065]: Stopping Service du bot du lg de la rez...
Apr 14 20:49:56 sapinet927 python[8408]: Disconnected.
Apr 14 20:49:56 sapinet927 systemd[23065]: lgrez.service: Succeeded.
Apr 14 20:49:56 sapinet927 systemd[23065]: Stopped Service du bot du lg de la rez.

It says the bot stopped but I don't understand why.

Here is the status of the service :

lgrez.service - Service du bot du lg de la rez
   Loaded: loaded (/home/lgrez/.config/systemd/user/lgrez.service; enabled; vendor preset: enabled)
   Active: inactive (dead)

Here is my service file ~/.config/systemd/user/lgrez.service :

[Unit]
Description=Service du bot du lg de la rez
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
WorkingDirectory=/home/lgrez
ExecStart=/home/lgrez/env/bin/python -u start_bot.py .env
Restart=always
RestartSec=1
StandardOutput=journal+console
StandardError=journal+console
 
[Install]
WantedBy=multi-user.target

Is there any problem in my service file ?

I enabled it with systemctl --user enable lgrez.

louisld
  • 101
  • 1
  • 4

1 Answers1

0

The issue was that systemd kills all user services when user logs out as specified here : https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=825394

To bypass this problem I used :

loginctl enable-linger lgrez

And put KillUserProcesses=no in /etc/systemd/logind.conf.

Now it works well.

louisld
  • 101
  • 1
  • 4