1

I have a python script that works fine if I run it with /usr/bin/python3.

But I would like to be able to run it from a bash file as root through a service unit from systemd. I want to be able to pass a bash script because I would like to chain this python script and then a php script afterwards).

For this, I have created the following service (without timer for the moment):

[Unit]
Description=My service

[Service]
User=root
ExecStart=/usr/bin/bash /home/myself/script.sh
Type=oneshot

and a simple bash script :

#!/bin/bash

python3 /home/myself/script.py

but when I run "sudo systemcl start myservice.service", I have this error :

Job for myservice.service failed because the control process exited with error code.
See "systemctl status myservice.service" and "journalctl -xe" for details.

and when I look at the status :

..... systemd[1]: Starting My service...
..... bash[13176]: Traceback (most recent call last):
..... bash[13176]:   File "/home/myself/script.py", line 33, in <module>
..... bash[13176]:     files_number = next(os.walk(files_path))[2]
..... bash[13176]: StopIteration
..... systemd[1]: myservice.service: Main process exited, code=exited, status=1/FAILURE
..... systemd[1]: myservice.service: Failed with result 'exit-code'.
..... systemd[1]: Failed to start My service.

I don't understand why it doesn't work. Is it because I'm using the 'os' library in my script or something else I don't understand?

2
  • 1
    This is a Python script problem, not a systemd problem, so 1) you'll need to include the script or at least the relevant parts of it, 2) the thread will probably get migrated to Stack Overflow. Feb 15, 2021 at 17:09
  • You're right, this is not a systemd problem. Even if the python script is launched from my working directory, I still have to declare it.
    – spergynerd
    Feb 16, 2021 at 8:47

0

You must log in to answer this question.

Browse other questions tagged .