I wanted to write my own program using python and keep it running at all times, so I tried to service it using Systemd, but when I started the service, I usually get some error. There are errors due to permissions and errors that the gpiozero module does not exist. The worst syslog may not show any details and onlyzishin.service: Main process exited, code = exited, status = 203/EXEC. When run as a service, you will encounter various errors, but when you debug withvscode, no errors will occur.
The unit file is as follows.

Description = zishinmonitor
After = multi-user.target
ExecStart =/usr/bin/python3 /home/pi/Git/zishinMonitor/main.py
Type = simple
WantedBy = multi-user.target

Is there anything I should be aware of when creating a service for my program?

  • Answer # 1

    I didn't mention it in the question, but when I run it as a service, the working directory is not set to/home/pi/Git/zishinMonitor, and\, and as a workaround, I added RootDirectory to the unit file and specified the working directory. After careful examination, the working directory was specified as WorkingDirectory. I tried to specify the WorkingDirectory before, but I thought it was wrong because the working directory was not changed well, but the cause was another part of the unit file. The module is said not to exist because if RootDirectory is set to/home/pi/Git/zishinMonitor, directories above its parent are ignored.
    Since the question was asked while the causal relationship of the problem that occurred was confused, the question became very difficult to understand. Excuse me.

  • Answer # 2

    Is the environment variable PATH different or is there no standard input/output?