Setup Opsdroid as a service on Ubuntu 18.04 with systemd
I wrote previously on how to setup a Raspberry Pi 3 with Opsdroid a while back and needed to update the process for my web host just a bit.
I wrote a post on how to setup a Raspberry Pi 3 with Opsdroid a while back and needed to update the process for my web host just a bit.
Install Opsdroid
You may have Python and Pip already installed, but just in case here is the way you would get Opdroid installed on a fresh box [Install docs for reference].
# Update apt-get
$ sudo apt-get update
# Install pip for Python 3 and locales
$ sudo apt-get install python3-pip language-pack-en git
# Ensure pip is up-to-date
$ pip3 install --upgrade pip
# Install opsdroid
$ sudo pip3 install opsdroid
# Run opsdroid
$ opsdroid start
We start Opsdroid just to get a generic config created. The basic config has just enough to get you rollin'. You can stop the service via ctrl-C once it is online.
Create a Systemd Service
Open up your favorite command line text editor. We will be creating a systemd service file.
$ sudo nano /etc/systemd/system/opsdroid.service
Now paste the following in. Edit the $USER to your user that you will be installing and running the service as.
[Unit]
Description=opsdroid chatbot service
Documentation=https://docs.opsdroid.dev/en/stable/
[Service]
WorkingDirectory=/home/$USER
ExecStart=/home/$USER/.local/bin/opsdroid
User=$USER
Type=simple
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
Save the file and exit [ctrl+O, Enter, and ctrl+X for the nano text editor]
Reload and Set Service as Enabled
I do this initially with a default config to make sure everything is working. I break the service enough when configuring it, and like to know if the out of the box the service is working as intended.
# Services reload
$ sudo systemctl daemon-reload
# Start, Enable, and Check the status
$ sudo systemctl start opsdroid.service
$ sudo systemctl enable opsdroid.service
$ sudo systemctl status opsdroid
Once you are all done with the above you can start automating your life with "chatops".