'runsv service cannot find python file in the same directory

I have a service called 'heartbeat'.

bash-4.2$ ls -ltr /etc/service/heartbeat/
total 12
-rwxr-xr-x 1 someusr root   3184 Mar  3 01:07 run
-rw-r--r-- 1 someusr root   4937 Mar  3 01:07 some.py
drwxr-xr-x 1 someusr root     23 Mar  3 05:38 log
drwx------ 2 someusr someusr   80 Mar  3 05:38 supervise

Within the 'run' file, I am asking the service to execute 'some.py' file, which is housed in the same folder.

try:
    output = subprocess.run(['python3', '/etc/service/heartbeat/some.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    if output.stderr:
        _log.error("Failed to execute debug script %s" % str(output.stderr.decode("utf-8")))
    with open('/etc/service/heartbeat/diagnosis.json', 'r') as fd:
        details = fd.read().decode("utf-8").strip()
except Exception as error:
    _log.error("Failed to generate debug details %s" % str(error))

When the service is run, it complains that it cannot find the 'some.py' file.

2022-03-03 07:48:41,443 INFO heartbeat Current working directory /etc/service/heartbeat
2022-03-03 07:48:41,444 INFO heartbeat Current user someusr
2022-03-03 07:48:41,466 ERROR heartbeat Failed to execute debug script python3: can't open file '/etc/service/heartbeat/some.py': [Errno 2] No such file or directory

2022-03-03 07:48:41,467 ERROR heartbeat Failed to generate debug details [Errno 2] No such file or directory: '/etc/service/heartbeat/diagnosis.json'

I am unable to debug what is wrong? Please help me identify the problem.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source