First let's create a script to run a service

$ vim /full/path/to/custom_service.py

Paste a source

#!/usr/bin/env python3
import time
i = 0
while True:
  file = open(f"/full/path/to/custom_service.log","a")
  file.write(f"{i} - {time.ctime()}\n")
  file.close()
  time.sleep(5)
  i += 1

Create a file to write a log

$ touch /full/path/to/custom_service.log

Make a script executable

$ chmod +x /full/path/to/custom_service.py

Run a script with a command

$ /full/path/to/custom_service.py

Se a result in another terminal tab with a command

$ tail -f /full/path/to/custom_service.log

Creating a service

$ sudo vim /etc/systemd/system/custom_service.service

Paste a source

[Unit]
Description=Start My Service
[Service]
User=root
ExecStart=/bin/bash -lc "/full/path/to/custom_service.py"
TimeoutStopSec=10
RestartSec=5
[Install]
WantedBy=multi-user.target

Now you can use

$ systemctl start writer
$ systemctl stop writer
$ systemctl status writer

To call a service when system up just

$ systemctl enable writer

🗓 2016-10-26
850 👀