- Transfer repo to your pi. Either use git directly or send it from your local machine via ssh
scp -r yoink/ username@raspberrypi:/home/username/yoink
- Install requirements globally. It is important to use sudo for the service to work.
sudo pip3 install -r requirements.txt
- Create a .env file in the /yoink folder and store your telegram api key like this
API_KEY='your-api-key'
Now we're going to define the service to run the yoink script:
cd /lib/systemd/system/
sudo vi yoink.service
The service definition must be on the /lib/systemd/system folder. Be sure to switch 'username' for your name.
[Unit]
Description=yoink service
After=multi-user.target
[Service]
WorkingDirectory=/home/username/yoink
Type=simple
ExecStart=/usr/bin/python /home/username/yoink/src/backend/botservice.py
Restart=always
[Install]
WantedBy=multi-user.target
Here we are creating a very simple service that runs the yoink script and if by any means is aborted is going to be restarted automatically. It also starts automatically when the pi restarts. You can check more on service's options in the next wiki: https://wiki.archlinux.org/index.php/systemd.
Now that we have our service we need to activate it:
sudo chmod 644 /lib/systemd/system/yoink.service
chmod +x /home/username/yoink/src/backend/botservice.py
sudo systemctl daemon-reload
sudo systemctl enable yoink.service
sudo systemctl start yoink.service
For every change that we do on the /lib/systemd/system folder we need to execute a daemon-reload (third line of previous code). If we want to check the status of our service, you can execute:
sudo systemctl status yoink.service
In general:
sudo systemctl status yoink.service
sudo systemctl start yoink.service
sudo systemctl stop yoink.service
sudo journalctl -f -u yoink.service
- When you use python version < 3.10 the kw_only flags of the dataclasses wont work. Either upgrade the python version or delete all kw_only flags.