The example you used at systemd is a bad example. It states to Restart=always
. That doesn't help to "fix" a buggy service that failed to run stable. It will only spam your system with starting attempts until it will give up after some minutes.
In particular for your case it doesn't fit because you need to run your service only one time at start up and do not need to be in the background and work continuously as a service/daemon. I suggest to try this Unit File that you create with:
rpi ~$ sudo systemctl --full --force edit UpTime.service
In the empty editor insert these statements, save them and quit the editor:
[Unit]
Description=Up Time logging
After=mysql.service
[Service]
Type=oneshot
RemainAfterExit=yes
User=pi
WorkingDirectory=/home/pi
ExecStart=/home/pi/UpTime.py
[Install]
WantedBy=multi-user.target
I don't know the real name of the mysql service. I have named it in this example mysql.service
. You have to use the correct name from your system. In general you can just look with ~$ systemctl
what services are running. Enable your service with:
rpi ~$ sudo systemctl enable UpTime.service
and try with a reboot. It may not work on the first attempt because there are some additional environment settings are needed. We will look then.
@reboot
facility incron
for some ideas. Here's one that addresses some of your questions.$PATH
and other environment variables. This might make sense as that's part of the job that/etc/profile
does (as @Milliways points out): set up the environment for the shell.