9

I am using my raspberry pi as a headless server. The problem is that after a couple of hours of inactivity it seems to enter a power suspend state where it disappears from the web and refuses ssh connections. After having prodded it via ssh it comes back after a couple of minuttes and uptime informs that it has been alive all the while. This makes me think it is some kind of power management scheme that is in effect but I have read other places that the pi is not able to suspend.

Does anyone have an idea what is wrong?


Update:

After having spent a great deal of time trying to figure this out it seems a number smaller issues have helped:

  1. Configure postfix to not use ipv6.
  2. Use fail2ban to blacklist ssh login attempts.
  3. Update firmware on router.

All three items seems to have had a positive effect on the pi's uptime. It is now reasonably stable and I have not the login-problem for about three weeks.

Kenneth
  • 721
  • 1
  • 4
  • 11

2 Answers2

14

The wireless device goes to sleep after a period of no activity. It's a powersaving scheme.

You need to turn off the powersave feature of wlan0.

I'm using an edimax wireless usb receiver:

Bus 001 Device 005: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]

It uses the 8192cu module in the kernel.

To turn off powersave, add the following to /etc/modules, or create a file (8192cu.conf) in /etc/modprobe.d/ with the line(s):

# prevent power down of wireless when idle
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

Next reboot (or rmmod/insmod) it should disable the sleepy mode and your pi will be accessible all the time.

I create the file for /etc/modprobe.d and it's part of a script I built to do preliminary setup on a new build.

lornix
  • 1,066
  • 8
  • 13
5

The raspberry pi hardware has no power management capability. Period. End of story. It does not have a sleep or suspend mode. It cannot not even be turned off. There's either power (plugged in), or there isn't (not plugged in).

When you shutdown the system, the software stops, meaning there is now no way to get it to do anything again. However, the "power state" of the hardware is still the same (because it only has one state, on).1

So whatever your problem is, that is not it. You may want to look at your logs to see if anything else has been going on during the network downtime -- eg, (I'm speculating), if you have stuff attached to the usb ports that is near the limits of the pi's 150 mA output, that thing may intermittently fail, and if it's a wifi dongle, the system will then have to wait until the interface reappears. You'd see lots of evidence that in /var/log/syslog or /var/log/messages.

If it's any consolation, I use the pi headless on a WLAN and don't turn it off very often, and it's been pretty flawless. I use this methodology to ensure the connection stays up; peeking at the current log, it's had to reconnect itself only twice in the past 48 hours. However, I make pretty light use of it too, maybe occasionally there is a big download, etc., but not constant traffic (the more it's accessed the more opportunities there are for something to fail, so I can't say how reliable it would be serving a cafe full of people all day). Also, I have it on a 3.8A hub and the only thing plugged directly into the pi's usb is a "nano"-size wifi dongle.


  1. Not 100% true, since all models can have the SoC or significant parts thereof powered off, in which case the "power state" of the device could be said to have changed. This is what happens when the OS is shutdown properly (eg. via halt -p). The only way to power that stuff back up, though, is to cycle the main power to the board or reset the SOC (or PMIC for later models).
Milliways
  • 62,573
  • 32
  • 113
  • 225
goldilocks
  • 60,325
  • 17
  • 117
  • 234