Systemd: Create a New Service and Run on Boot

Systemd service

For this occasion, I wanted my telegram bot to start automatically right after my Raspberry Pi Zero booted and connected to the network.

Creating the service file

I named my service file telegram-bot.service:

sudo touch /etc/systemd/system/telegram-bot.service

And started editing it with sudo vim /etc/systemd/system/telegram-bot.service.

I wanted this service to execute python3.6 on boot, after connecting to the network, under my user (i.e. not as root).

The final form of the file:

Description=Start telegram bot on boot



Enabling the service

sudo systemctl enable telegram-bot.service

Now, after every reboot, the service will be executed as we wanted.