Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am creating a quick python3 program and at one part the server will need to be restarted. The thing is, that is not the end of the what the python file is supposed to do. Is there a way to make it start up from where it stopped when the user restarts or (if that isn't possible) automatically open a 2nd python file, which will continue with the rest of the task required.

Thanks!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

A reboot of the server obviously will also kill all running applications. Therefore we need to create a file on the harddisk that survives this.

This file only needs to flag whether the server is going to reboot or if it was just rebooted like:

rebooted = False
rebooted = True

We then let our application run different paths like:

rebooted = load_bootflag()
if not rebooted:
    do_this()
    rebooted = True
    save_bootflag(rebooted)
    shutdownroutine()
else:
    do_that()
    rebooted = False
    save_bootflag(rebooted)

Where load_bootflag() and save_bootflag() are your routines to create this file.

share|improve this answer
    
Thanks. Did this with a "reboot.txt" file, some read file and if statements. –  Eden Crow Apr 15 '11 at 12:00
    
But that still means I'm going to have to ask the user to reopen the file after restart. –  Eden Crow Apr 15 '11 at 12:37
    
unless you do a trick with autostarting some app that checks this. –  Takkat Apr 15 '11 at 13:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.