Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Deploy systemd

Brian Mitchell edited this page Aug 13, 2019 · 2 revisions

weatherBot can be configured to run as a systemd service on supported Linux systems.

The following is a basic example, but for a more secure installation, you will want to configure the service to run under its own user and store the tokens and secrets in a directory that is not world readable.

Example

  1. Make sure a supported version of Python is installed on the system.
python3 -V
  1. Clone the repository.
git clone https://github.com/BrianMitchL/weatherBot.git
  1. Install dependencies.
# in the weatherBot directory
pip3 install -r requirements.txt
  1. Configure the bot
  • Enter tokens/secrets into keys.py
  • Customize strings in string.yml
  • Configure weatherBot.conf
  1. Create the systemd service. Make sure this is owned by root.
sudo touch /etc/systemd/system/weatherBot.service

Edit the service to contain the following

[Unit]
Description=weatherBot

[Service]
Type=simple
WorkingDirectory=/path/to/weatherBot/GitHub/clone
ExecStart=/usr/bin/python3 weatherBot.py weatherBot.conf
# restart the service if it crashes (watch out for rate limiting and repeated crashing)
# Restart=always

[Install]
WantedBy=multi-user.target
  1. Enable and start the service.
# start the service at boot
sudo systemctl enable weatherBot.service
# start the service
sudo systemctl start weatherBot.service

Tips

You can check the status by running

sudo systemctl status weatherBot.service

If changes are made to the weatherBot.service file, you will need to reload the service for changes to take effect.

sudo systemctl daemon-reload

Clone this wiki locally