2

I seem to be able to shutdown my raspberry remotely over ssh using

sudo shutdown -h now

when I'm connected through ethernet - yet, when it's connected over wifi whenever I run this (or some similar command) nothing happens.. the ssh simply freezes there forever and if I interrupt with Ctrl-C I can still login back to the raspberry.

am I missing something?

(running the latest raspbian-lite on a raspberry pi 3 and ssh-ing from a macbook pro)

2

Not sure if I've observed this just plain not work before, although calling shutdown in an ssh session may often cause it to hang on your side. I'll hazard a guess and say the reason you have this problem with wifi but not ethernet is because of the bit of latency involved. TBH that's a dubious, unsatisfying guess, but I don't think we need a complete understanding.

The way I deal with shutdown via ssh is to send the command into the background and exit. My personal preference is actually halt -p but I am not sure if that matters:

sudo halt -p & exit

To explain: & backgrounds a process, meaning the call returns immediately, before the command itself completes. Shutting down the system usually takes at least a few seconds before the final move, which is to tell the hardware to poweroff (I'm not sure how meaningful that is on the pi -- so the -p may just be an irrelevant habit).

The exit then refers to the ssh login, so that will then be immediately disconnected properly. The way the timing works out is that halt on the other end won't have stopped sshd yet, so no snags.

Beware:

  • Using this method (foo & exit) with most processes will probably end up with the process failing or dying mysteriously. It works with halt (or shutdown) because these are actually commands to the init system. Not a complete explanation, but enough said here.

  • foo & bar is very different than foo && bar. The latter means wait for foo to finish executing and then only start bar if foo succeeded. That's not what you want to do.

0

I do this all the time with my Pi which run headless, although I use sudo poweroff. This works reliably and the host indicates connection lost.

It is probably a timing issue.

shutdown and poweroff all use the same code, but poweroff causes the activity LED to flash 10 times at 1 second intervals.

I have found some settings interfere with shutdown - dtoverlay=gpio-poweroff certainly does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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