Topics

Faster way to shutdown/restart RaspberryPi?


Steve Todd
 

All,
There was some discussion a while back that included better scripts to shutdown or restart a RaspberryPi.
The script I'm using: http://jmri.org/jython/RaspberryPiShutdown.py works fine, but has a one minute delay included.
So, I'm looking for an improved method, that still waits for JMRI to shutdown completely, but avoids that one minute delay. IIRC, one suggestion had a loop to check if JMRI was still running, then performed "shutdown now".
I now cannot find that earlier conversation. Can someone point me in the right direction?
Alternately, can someone convince me that "shutdown now" is safe while JMRI is running?
Note: I'm not looking for "buttons" or external apps to do the shutdown. I'm aware of those, but I want something that has no external requirements.
--SteveT


whmvd
 

Hi Steve,

Assuming you're using something very bash-like, try putting this line above 'shutdown now':

while [ $(ps auxww | grep -i :JMRI.jar: | grep Djava.library.path= | wc -w) -ne 0 ];do sleep 1;done

Tested OK on my (Linux!) system. I would suggest adding the options
--no-wall -P
to the shutdown command (see man-page).

Wouter


On Thu, 10 Sep 2020 at 13:57, Steve Todd <mstevetodd@...> wrote:
All,
There was some discussion a while back that included better scripts to shutdown or restart a RaspberryPi.
The script I'm using: http://jmri.org/jython/RaspberryPiShutdown.py works fine, but has a one minute delay included.
So, I'm looking for an improved method, that still waits for JMRI to shutdown completely, but avoids that one minute delay. IIRC, one suggestion had a loop to check if JMRI was still running, then performed "shutdown now".
I now cannot find that earlier conversation. Can someone point me in the right direction?
Alternately, can someone convince me that "shutdown now" is safe while JMRI is running?
Note: I'm not looking for "buttons" or external apps to do the shutdown. I'm aware of those, but I want something that has no external requirements.
--SteveT


Ken Cameron
 

Steve T,

Simply changing the script to replace the "+1" with "now" will tell it not
to wait. Now how the interaction of JMRI getting the shutdown from the next
line combines with the shutdown signal that the system shutdown will also
send, I don't know. Very old memory had the system shutdown sending the
normal kill to all user processes and then waiting something like 15 seconds
or something before sending a more forceful kill to the remaining processes.
In older days I think that was 'kill -HUP' followed by 'kill -9' or
something like that.

If you have a console terminal (not network) displaying while this goes on
you should be able to see if it goes well or not.

-Ken Cameron, Member JMRI Dev Team
www.jmri.org
www.fingerlakeslivesteamers.org
www.cnymod.org
www.syracusemodelrr.org


whmvd
 

PS:

I have always been very uncomfortable stopping systems while applications are still running. The chances of disk (or in this case: card) corruption may be small, but they aren't zero. I'm from the 'better safe than sorry' school of thought.


On Thu, 10 Sep 2020 at 13:57, Steve Todd <mstevetodd@...> wrote:
All,
There was some discussion a while back that included better scripts to shutdown or restart a RaspberryPi.
The script I'm using: http://jmri.org/jython/RaspberryPiShutdown.py works fine, but has a one minute delay included.
So, I'm looking for an improved method, that still waits for JMRI to shutdown completely, but avoids that one minute delay. IIRC, one suggestion had a loop to check if JMRI was still running, then performed "shutdown now".
I now cannot find that earlier conversation. Can someone point me in the right direction?
Alternately, can someone convince me that "shutdown now" is safe while JMRI is running?
Note: I'm not looking for "buttons" or external apps to do the shutdown. I'm aware of those, but I want something that has no external requirements.
--SteveT


Steve_G
 

Hi Steve T.
Start panelpro with..
systemd-inhibit pathtojmri/PanelPro
Then the system can't be shut until panel pro ends
Steve G.




On September 10, 2020 8:57:52 AM EDT, Steve Todd <mstevetodd@...> wrote:
All,
There was some discussion a while back that included better scripts to shutdown or restart a RaspberryPi.
The script I'm using: http://jmri.org/jython/RaspberryPiShutdown.py works fine, but has a one minute delay included.
So, I'm looking for an improved method, that still waits for JMRI to shutdown completely, but avoids that one minute delay. IIRC, one suggestion had a loop to check if JMRI was still running, then performed "shutdown now".
I now cannot find that earlier conversation. Can someone point me in the right direction?
Alternately, can someone convince me that "shutdown now" is safe while JMRI is running?
Note: I'm not looking for "buttons" or external apps to do the shutdown. I'm aware of those, but I want something that has no external requirements.
--SteveT

--
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Steve_G
 

Hi 
Try to leverage the code we use to restart JMRI when the preferences change.
Steve G


Steve_G
 

Hi
Method in  apps
/**
     * The application decided to quit, handle that.
     *
     * @return true if successfully ran all shutdown tasks and can quit; false
     *         otherwise
     */
    static public boolean handleQuit() {
        return AppsBase.handleQuit();
    }


Steve_G
 

The nicest way is
Add in Apps,AppsBase and shutdown manager class an shutdowntopoweroff()
that exists with a code 200 say.
then in panel and decoderpro check not only for a restart but also a shutdown.
Dont know how it would work in windows, its always been a bit of mystery how it starts!
I can do a PR if you like.
Steve G.

 


Steve Todd
 

Sure, a PR would be great, as I'm not following how that would help. Thanks!


Matthew Harris
 

All our launchers, support a restart of JMRI with a 100 return code.

Other status codes can be used in the launchers to do something else.

Best regards, 

Matt H


Steve Todd
 

A big thanks to SteveG for https://github.com/JMRI/JMRI/pull/9015 to handle the shutdown of the OS, using return code "200".
I'm going to update the scripts to use this new feature.

I'm also going to copy his work to add a restartOS() function, which will use return code "210" to restart the OS instead of shutting it down.

"210" is an arbitrary choice, I'll gladly use another code if someone knows of a reason.

--SteveT


Matthew Harris
 

Seems sensible enough.

I'll update the Windows Launcher to suit this, assuming no dissenting opinions wrt '210'

Best regards,

Matt H