So I have a python script that starts as expected during power-on by following: Startup by systemd
My Pi has a button connect to GPIO which is used to stop the logger and then shut down the Pi like this:
if DEBUG_FLAG:
print('Shutting down!!!')
with open('debug_file', 'w+') as f:
f.write('Starting shutdown!!\n')
try:
subprocess.Popen(['sudo','shutdown','-h','now'])
except:
with open ('failed_shutdown', 'w+') as f:
f.write('Shutdown from script failed\d')
So on a normal power-on and then pressing the button my script writes to the 'debug_file' and it does not write to the 'failed_shutdown' file but the pi is not shutdown since I can still ssh into it.
When starting the script from console and then pressing the button it does the same thing but also shuts down the pi.
How do I debug this? It feels like there is a different context when starting the script as a service from systemd then when starting from console. I have followed the above link exactly except for names and user.