Debian – How to properly prepare a server for power outages

debianlinuxpower-management

I have a personal Debian server set up, that I'm able to access in person and remotely, but normally I'm away from it and it's remote. It's on a battery-backup surge protector, but sometimes that isn't enough to keep the server on through a power outage. The machine automatically starts and boots, but its left at the login screen (in person). What I want to know is, what is the best way to have the server get itself back on and online after it loses power, without leaving it vulnerable in person? I'd like it to not auto-login for the screen in person, so that the machine isn't overly vulnerable in-person while I'm away.

Are there battery backups that signal for hibernation or other safe power down automatically?
How can I have a user sign in automatically in the background?
What would you recommend as a "best practice" for this, considering it's just a home server?

Best Answer

Make sure your BIOS is set to restart the system after a power failure.

Turn off auto login unless you have a really good reason for it to be enabled. You shouldn't really need to be interactively logged on for any server type programs to function. Especially if you can get into the system remotely there is no reason for it.

For most any program you need running in the background you can either make an initscript (if there isn't one already) or start it from rc.local without needing to be logged in.

For example, I have apache running on my home server. It launches and runs in the background when I boot. I don't have to explicity start it when my server comes up.

Most battery backups over $50 have a serial port or other mechanism for communicating with a PC. If yours is an APC (a really common brand), you want a package called apcupsd. This lets you call scripts when the power goes out, comes back on, and the system is about to shut down because of low battery. Most battery backups support Linux, it's just a matter of going on the manufacturer's website or doing a bit of Googling.

Generally power events are delivered to init and then init calls the respective programs. Look at /etc/inittab and the comments illustrate this.

You can actually disable console login entirely if you really want to by removing all the "getty" lines in inittab. Don't recommend you do that though, because if your network fails or you misconfigure sshd one day you are screwed.

Related Question