Setting up auto-restart using systemd on Linux

Creating the service file

In order to create the service file, you will first need the location of your redbot binary.

# If redbot is installed in a virtualenv
source redenv/bin/activate
which python

# If you are using pyenv
pyenv shell <name>
pyenv which python

Then create the new service file:

sudo -e /etc/systemd/system/red@.service

Paste the following and replace all instances of username with the username, and path with the location you obtained above:

Description=%I redbot

ExecStart=path -O -m redbot %I --no-prompt


Save and exit ctrl + O; enter; ctrl + x

Starting and enabling the service


This same file can be used to start as many instances of the bot as you wish, without creating more service files, just start and enable more services and add any bot instance name after the @

To start the bot, run the service and add the instance name after the @:

sudo systemctl start red@instancename

To set the bot to start on boot, you must enable the service, again adding the instance name after the @:

sudo systemctl enable red@instancename

If you need to shutdown the bot, you can use the [p]shutdown command or type the following command in the terminal, still by adding the instance name after the @:

sudo systemctl stop red@instancename


If the service doesn’t stop in the next 10 seconds, the process is killed. Check your logs to know the cause of the error that prevents the shutdown.

To view Red’s log, you can acccess through journalctl:

sudo journalctl -eu red@instancename