Page 1 of 1

Reboot raspberry pi and run a script after

Posted: Fri Jun 14, 2019 3:33 pm
by Nathan1258
Hi, I’m making an application in Python and my script runs some terminal commands via “os.system”. However, after them commands are run, the Pi needs to reboot to make the changes happen. I need to carry on running the rest of the script once the Pi reboots, how would I do that? Basically how do I continue running the script once the pi has rebooted again?

Thanks,
Nathan

Re: Reboot raspberry pi and run a script after

Posted: Fri Jun 14, 2019 3:49 pm
by dl324
Nathan1258 wrote:
Fri Jun 14, 2019 3:33 pm
Basically how do I continue running the script once the pi has rebooted again?
Can't be done. You can start the script automatically at reboot, but you can't have it resume. The current state can't be maintained across boots.

Re: Reboot raspberry pi and run a script after

Posted: Fri Jun 14, 2019 4:05 pm
by B.Goode
Nathan1258 wrote:
Fri Jun 14, 2019 3:33 pm
Hi, I’m making an application in Python and my script runs some terminal commands via “os.system”. However, after them commands are run, the Pi needs to reboot to make the changes happen. I need to carry on running the rest of the script once the Pi reboots, how would I do that? Basically how do I continue running the script once the pi has rebooted again?

Thanks,
Nathan

Maybe break the script into two : pre-boot and post-boot. Arrange for the post-boot element to be run automatically after a reboot.

Or re-examine your assumption that the entire system needs to be rebooted to enable the configuration changes you are making: maybe just the process or sub-system involved needs restarting?

Re: Reboot raspberry pi and run a script after

Posted: Fri Jun 14, 2019 4:08 pm
by Andyroo
Get the first part to check for a file on the SD card.

If it’s not present, run the first part, create the file and do a clean reboot
If it’s present, run the second part and delete the file

Re: Reboot raspberry pi and run a script after

Posted: Sat Jun 15, 2019 8:47 am
by Nathan1258
Andyroo wrote:
Fri Jun 14, 2019 4:08 pm
Get the first part to check for a file on the SD card.

If it’s not present, run the first part, create the file and do a clean reboot
If it’s present, run the second part and delete the file
Yep. I went for that idea. I just have a normal file with either ‘true’ or ‘false’ in and do whatever depending on that.

Re: Reboot raspberry pi and run a script after

Posted: Sat Jun 15, 2019 12:27 pm
by Andyroo
When using Windows I had a lot of code handling the old style ini files. Imagine my pleasure to find the config parser module for Python https://docs.python.org/3.7/library/configparser.html

First tine I read up on this was for a background program that had been hard coded for a given job and every time I wanted a new action I coded it in :oops: it’s now driven by the file contents and a lot easier to add bits in :D