14

I have a home server on Ubuntu Server 12.04 that really doesn't need to be using power, making noise, etc. at night. I'm too lazy, though, to actually turn it off at night and back on in the morning.

I'd like a command line tool that I can run in a cronjob that sleeps my laptop-server and wakes it at a set time automatically.

In short:

  • If it has a GUI, it must be optional.
  • It must be able to be run from a cronjob.
  • It must be able to awake the machine later without side effects.

Is there a program that does such a thing?

5
  • 3
    Err... why a simple cronjob that executes pm-utils wouldn't cut it?
    – Braiam
    Feb 19, 2014 at 14:55
  • 3
    Check whether your BIOS doesn't have a wake-up timer that can be set to specific hour to start periodically. That would solve the wake-up problem, with common "shutdown" runnable from Cron doing the powerdown side.
    – SF.
    Feb 19, 2014 at 15:40
  • Do you need the wakeup time to be variable and controllable from another (watchdog) machine or is setting a fixed time every day enough?
    – Caleb
    Feb 20, 2014 at 9:53
  • @Caleb Setting a fixed time for every day should be enough
    – Undo
    Feb 20, 2014 at 17:55
  • Or just a wall-plug with an on/off clock setting? Just in case you don't have the BIOS support Aug 9, 2018 at 10:02

3 Answers 3

13

You don't need new software to do this; here is how your existing software can handle this.

  • Use cron to suspend the machine at a pre-configured time.
  • Use the BIOS timer to wake it up at a pre-configured time.

Shutdown

For the last few releases Ubuntu has used their own home baked init system called upstart1. The power management utilities have gone through a couple of phases, so depending on what version you have there might be a couple ways of making this happen. This question on Ask Ubuntu should be helpful at figuring this part out, but you cat also just try to find which of these commands suspend your machine (as root):

# From the powermanagement-interface package
pmi action suspend

# From the pm-utils package
pm-suspend

# Using DBUS
dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend

# A little raw kernel api call 
echo -n mem > /sys/power/state

Once you find one of those that suspends to your satisfaction on your version, stick it in a root cron job:

0 11 * * * <working command from previous step>

This assumes that you go to bed at a reasonable hour like 11. Obviously you can change that part :)

Startup

For this you are going to need to bust around in your BIOS. What this feature is called is going to vary by manufacture, but most boards have a way to power on at a certain clock time.

Here is one configured for a late morning rise:

BIOS

You can get an idea of what these settings are going to look like in various BIOSes from Google image search: bios wake timer.

1 This actually is changing in the next release as they have settled on systemd along with most other major distros. When that happens the commands above will be obsoleted by systemctl suspend.

5
  • 1
    Do you know if there a way to wake up a server from the network? Feb 26, 2014 at 11:10
  • 2
    @Fractaliste It's called Wake On LAN (WOL) and most network cards and BIOSes these days support it, but that would be a question for Super User or something, not for here.
    – Caleb
    Feb 26, 2014 at 12:55
  • 2
    At least in Debian, there is a nvram-wakeup package that might save you from mucking around in BIOS settings. Or at least let you wake at a different time on different days.
    – derobert
    Mar 28, 2014 at 17:47
  • 1
    @Fractaliste : There's also Wake on Wan. May 28, 2014 at 13:52
  • You might want to add systemd alternative ;).
    – Braiam
    Oct 6, 2014 at 16:40
3

I know this is an old thread but for those who have recently found it, I used "systemctl suspend" on Ubuntu Server 14.04.3 (with no GUI) and it seems to work correctly. I wake the server with the WOL utility.

I have no GUI interface and the "pmi-suspend" method did suspend and awaken with WOL but I was never able to successfully log back in (via SSH) and had to power-cycle.

Peace and blessings.

1

You can try sspender https://github.com/mountassir/sspender

It allows you to suspend your machine based on pre-defined CPU/Disk usage, and makes sure the machine wakes up at certain times when you need it to be ON.

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.