Systemd service unit failed with result 'exit-code'

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 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like