Systemd Service does not start on reboot

Posted on

Problem :

I have the following systemd service called startupsh.service placed in /etc/systemd/system/ on my raspberry pi running rasbpian.

[Unit]
Description=Service to start telegram bot
After=graphical.target
Requires=network.target

[Service]
Type=forking
RemainAfterExit=yes
User=pi
ExecStart=/usr/bin/finder.sh &

[Install]
WantedBy=multi-user.target

I also enabled the service with

sudo systemctl daemon-reload
sudo systemctl enable startupsh.service

And sudo systemctl is-enabled startupsh.service shows that the service is in fact enabled.
Furthermore, if I run sudo systemctl start startupsh.service everything is working as expected. However, if the pi gets rebooted the service does not execute and sudo systemctl status startupsh.service shows that the service is inactive (dead)

What is going wrong on startup? How can I fix thsi?

Edit: The finder.sh scripts looks as follows

#!/usr/bin/env bash
echo "Starting Bot..."
source /home/pi/Desktop/Airdropfinder/airdropfinderEnv/bin/activate
python /home/pi/Desktop/Airdropfinder/airdropfinder/src/telegrambot.py

Solution :

Add Restart=on-failure to your systemd unit file.

systemd.service

Restart=

If set to on-failure, the service will be restarted when the process exits with a non-zero exit code

Leave a Reply

Your email address will not be published. Required fields are marked *