------------- instructions to configure systemctl -------------
[Running a script at bootup : Good practices?, rc.local falling, Other options?
The following is the selected answer to the above question. It was written by Ingo. I can't make it work.
Create a new systemd unit with:
pi@raspberrypi:~ $ sudo systemctl --force --full edit thonny.service
In the editor insert these statements, save it and quit the editor:
[Unit]
Description=Service to start thonny
Wants=graphical.target
After=graphical.target
[Service]
User=pi # or must it run as root? Then omit this line
#ExecStart=/home/pi/thonny # or where your program is
ExecStart=/home/pi/testAutostart.py # replaced the above line with this
[Install]
WantedBy=graphical.target
Enable the new service:
pi@raspberrypi:~ $ sudo systemctl enable thonny.service
reboot.
Check with:
pi@raspberrypi:~ $ systemctl status thonny.service
pi@raspberrypi:~ $ systemctl cat thonny.service
Edit again with:
pi@raspberrypi:~ $ sudo systemctl --full edit thonny.service
--------------- testAutostart.py -------------
#!/usr/bin/thonny
# added the above line
# testAutostart.py
import time
cmdfile = "cmdfile.txt"
cf = open (cmdfile,"w")
# The flag cmd is changed external to this program, and forces a restart.
cmd = 1
cf.write (str(cmd))
cf.close
isRunning = cmd
cntr = 0
wait = 10
while isRunning == cmd:
cntr += 1
print("Hello World:", cntr)
cf = open (cmdfile,"r")
cmd = int(cf.read())
cf.close
if isRunning != cmd:
print ("check interrupt")
if cmd == 0:
import os
os.system("sudo reboot -h now")
else: # incremented
exit()
time.sleep(wait)
---------------- cmdfile.txt ----------------
1
-------------- error 203--------------------
pi@raspberrypi:~ $ systemctl status thonny.service
● thonny.service - Service to start thonny
Loaded: loaded (/etc/systemd/system/thonny.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2018-12-14 10:27:26 MST; 8min ago
Process: 549 ExecStart=/home/pi/testAutostart.py (code=exited, status=203/EXEC)
Main PID: 549 (code=exited, status=203/EXEC)
Dec 14 10:27:26 raspberrypi systemd[1]: Started Service to start thonny.
Dec 14 10:27:26 raspberrypi systemd[1]: thonny.service: Main process exited, code=exited, status=203/EXEC
Dec 14 10:27:26 raspberrypi systemd[1]: thonny.service: Unit entered failed state.
Dec 14 10:27:26 raspberrypi systemd[1]: thonny.service: Failed with result 'exit-code'.
------------ analysis --------------------
status=203 is file not found
what file is not found ?
testAutostart.py
or
/usr/bin/thonny
or
/usr/bin/python
or
/usr/bin/python3
or
/usr/bin/python3.5
or
is status=203 something else
------------ modifications --------------------
in systemctl replaced:
ExecStart=/home/pi/thonny # or where your program is
with
ExecStart=/home/pi/testAutostart.py # or where your program is
tried
ExecStart=/home/pi/thonny testAutostart.py # or where your program is
in testAutostart.py top line added:
#!/usr/bin/python
then it changed to
#!/usr/bin/thonny
I can't make it work.
is a very poor description of the problem that you are having ..... why did you post the selected answer when it does not resolve your problem? ..... you have not asked a question and you have not provided any information that could be used to solve the problem – jsotola Dec 22 '18 at 23:21