Dubman
Posts: 127
Joined: Thu Mar 15, 2018 3:53 pm

How to shut down and re-start RPi?

Wed Jul 11, 2018 8:09 am

HI, I'm planning to install my RPi 3 B+ in fairly inaccessible exterior location, as part of a home security system. But I plan to run a normal on/off switch from the power cable to the RPi and PIR detector - this physical switch would obviously be in an accessible location.
My question is about powering it off.
Would the following be correct?
In RPi terminal, type:

Code: Select all

sudo shutdown -h now
Then after about a minute, turn off the switch on the power line to RPi. And when I want to turn it on again, simply turn on the switch. Would a normal domestic switch be suitable, or should I use a bipolar switch that would turn off both wires that feed the pi?
Thank you.

drgeoff
Posts: 9915
Joined: Wed Jan 25, 2012 6:39 pm

Re: How to shut down and re-start RPi?

Wed Jul 11, 2018 8:21 am

Yes and yes to shutdown and restart.

You only need to interrupt one of the two power wires.

Why would you not be switching the AC mains side of the PSU?

Heater
Posts: 13873
Joined: Tue Jul 17, 2012 3:02 pm

Re: How to shut down and re-start RPi?

Wed Jul 11, 2018 9:46 am

Dubman,
...planning to install my RPi 3 B+ in fairly inaccessible exterior location...
No matter what you do there will be unexpected power outages and such and your SD card will get corrupted.

The more inaccessible your Pi is the more this is true this is. Murphy's Law and all that.

To make this reliable your really should mount your root file system as read only. Then power can be cut at anytime with no chance of corruption and subsequent failure to boot when the power comes back up.

As this is part of a security system I imagine reliability is important. That suggests you make use of the hardware watchdog to automatically reboot the thing if the OS or such crashes out for some odd reason.
Memory in C++ is a leaky abstraction .

Dubman
Posts: 127
Joined: Thu Mar 15, 2018 3:53 pm

Re: How to shut down and re-start RPi?

Wed Jul 11, 2018 10:54 am

drgeoff wrote:
Wed Jul 11, 2018 8:21 am

Why would you not be switching the AC mains side of the PSU?
My plan is to place the switch on the main 220 V power line that feeds the pi and PIR detector The pi and camera will be installed in the same outdoor enclosure
IMG_20180711_110636_058.jpg
IMG_20180711_110636_058.jpg (91.17 KiB) Viewed 848 times
. To make this reliable your really should mount your root file system as read only.
How would I do that?
Thanks!

Heater
Posts: 13873
Joined: Tue Jul 17, 2012 3:02 pm

Re: How to shut down and re-start RPi?

Wed Jul 11, 2018 12:48 pm

I did it last year by following ejolson's instructions here: viewtopic.php?f=63&t=161416

Sadly that thread has gotten long and winding and I gather the original instructions don't quite work on recent Raspbian releases. Perhaps ask there.
Memory in C++ is a leaky abstraction .

User avatar
Roken
Posts: 309
Joined: Sun Dec 31, 2017 4:35 pm
Location: UK

Re: How to shut down and re-start RPi?

Wed Jul 11, 2018 9:28 pm

For a straightforward restart, use

Code: Select all

sudo shutdown -r now
Headless PI. OMG, someone cut it's head off. Oh, hang on. it didn't have one to start with.

btidey
Posts: 1625
Joined: Sun Feb 17, 2013 6:51 pm

Re: How to shut down and re-start RPi?

Wed Jul 11, 2018 9:59 pm

Heater wrote:
Wed Jul 11, 2018 9:46 am
Dubman,
...planning to install my RPi 3 B+ in fairly inaccessible exterior location...
No matter what you do there will be unexpected power outages and such and your SD card will get corrupted.

The more inaccessible your Pi is the more this is true this is. Murphy's Law and all that.

To make this reliable your really should mount your root file system as read only. Then power can be cut at anytime with no chance of corruption and subsequent failure to boot when the power comes back up.

As this is part of a security system I imagine reliability is important. That suggests you make use of the hardware watchdog to automatically reboot the thing if the OS or such crashes out for some odd reason.
I agree with the general sentiment that for the 'highest reliability' system an approach that either guarantees a clean shutdown in the event of primary power loss or a read only file system can be a good idea. BUT the use of the word will (corrupt) is incorrect, may or might would be better. The chance of corruption can be quite small and for many situations this may be an acceptable risk. E.g. if the risk is comparable with other potential failures requiring access to repair.

See for example, https://raspberrypi.stackexchange.com/q ... corruption for what I think is a fairly rational discussion on this.

Heater
Posts: 13873
Joined: Tue Jul 17, 2012 3:02 pm

Re: How to shut down and re-start RPi?

Thu Jul 12, 2018 9:38 am

btidey,
BUT the use of the word will (corrupt) is incorrect, may or might would be better.
I think "will" is perfectly correct.

Consider this: If you roll a fair six sided die it "may" or "might" come up with a 3. If you roll that same die 100 times I think we can confidently say it "will" come up with a 3 at some point.

Or if we roll 100 similar die we can pretty much be sure one of them will be a 3.

"may" or "might" is the same as "will" to an extent depending on what you are doing.
The chance of corruption can be quite small and for many situations this may be an acceptable risk. E.g. if the risk is comparable with other potential failures requiring access to repair.
Ok, now we are talking. It's all about assessing the probabilities of failure and balancing the cost (time, money, effort, whatever) of having to fix things when they fail in use vs the cost of trying to ensure they don't fail.

One has to make one's own judgement call on that. I'm just alerting our OP to a common failure mode of Pi systems.

For example: In my case we deployed a bunch of Pi in inaccessible locations, high up on poles where making visits to repair them would cost thousands of dollars. Not only that, these poles are in a different continent 6000 miles away! Previous experience was that Pi SD cards and/or the file systems on them get corrupted at the drop of at hat. So, the only sensible thing to do is to try and ensure that is not a possibility and make the SD read only.

As it turns out those Pi have been running for a year now, having faced all manner of power interruptions, so far without failure. Touch wood. Not so for some other industrial devices we have up those poles with the Pi, but that is another story.

To be fair, this is not just a Pi and SD card issue, it's very common in all kind of equipment.
Memory in C++ is a leaky abstraction .

btidey
Posts: 1625
Joined: Sun Feb 17, 2013 6:51 pm

Re: How to shut down and re-start RPi?

Thu Jul 12, 2018 10:33 am

My only reason for raising this was the original wording seemed to imply a high probability of failure on unexpected power outage, and I wanted to indicate that there may be an acceptable risk in a simpler strategy.

The OP was planning to shutdown cleanly under most circumstances, a good strategy significantly reducing the risk of corruption.

Pedant mode on. 'will' is not the same as 'may'. 'will' says something is definitely going to happen. That is not the case even if the probability is very high (e.g. under repeated events). A 100 throws of a dice will not necessarily roll a 3 even though it is highly likely. Pedant mode off.

I think we are in agreement that a risk/cost analysis is a good strategy to employ in making these type of decisions.

Return to “General discussion”