1

I want to create a systemd service which runs a python code some seconds after the startup. I believe I can put this delay in the python script so it's not the important part. I'm just worried about the delay be applied to the system startup itself. The python script must be run with sudo since it will modify some system files.

2
  • Installed systems services run as root. sudo is not required.
    – doneal24
    Jan 13, 2023 at 22:48
  • 1
    Use a monotonic systemd Timer unit for such a job.
    – Freddy
    Jan 14, 2023 at 2:01

1 Answer 1

0

Create your Service By running vi /etc/systemd/system/pyhton_script.service

[Unit]
Description=My test Python Script
After=multi-user.target

[Service]
Type=simple
Restart=always
User=root
ExecStartPre=/bin/sleep 5
ExecStart=/usr/bin/python3 /home/<username>/pyhton_script.py

[Install]
WantedBy=multi-user.target

then run

systemctl daemon-reload
systemctl enable pyhton_script.service --now
systemctl status python_script

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .