[Guide] RTCwake to turn off/on your nas at a specific time

  • In my earlier setup i had a lot of small servers running different processes. These servers were turned on at differnet times of the day when needed. To this I used different rtcwake setups. My MythTV backend server is turned off every night at 02:00 and turned on again at 14:00 by rtcwake. The goal was to save on the electricity bill. The same can be done with a nas like OMV. You can turn off your nas every night and turn it on at a specific time every morning.


    The rtcwake command is

    Code
    rtcwake -m [type of suspend/off] -s|t [s=time to sleep in sec|t=time to wake up]


    Rtcwake depends on your motherboard acpi support. Rtcwake can use four different modes of sleep/off – these are selected by the ”-m” parameter:
    - standby - which offers the least power save
    - mem – suspending to ram – saves some more power than standby
    - suspend - to disk and turns of the unit - saves more power than mem
    - off – which is turning the unit completely off - saves the the most power


    First you must test the capability of acpi that your mobo/bios supports. Test the different modes of sleep by giving a rtcwake command with each of the sleeping modes. If the board is not going to the requested sleep/off mode or not waking up - that mode isn't supported by your mobo in its current setup. You options are to either use another sleep/off mode or to enter bios setup and chacek that your acpi and sleep mode options are turned on. Check you'r mobo documentation.


    Everything here needs root priviledges so do your ”sudo -i” or what ever your setup needs to give roots rights.


    Lets put the unit to sleep with the different modes and test if it wakes up as expected:
    with root priv type:

    Code
    rtcwake -m off -s 300


    This should turn of your machine in an orderly manner and set the bios to wake it up 5 minutes later. I use -s 300 because the most nas's needs some time to umount disks and stop all processes before turning off. If you'r setup turns off faster you can shorten the -s parameter. Just make shure the unit is able to turn completely off before the wakeup time is reached.


    If you mobo isn't turning on after 5 minutes your acpi doesn't support the "off" state and you must try one of the other states. Anyhow the ”off” mode is not an official part of the acpi standard. I have several small boxes that doesn't support the ”off” mode.


    Test the other modes in the same manner till you find the mode that works and gives the lowest power consumption. My small Fit-pc2 supports only ”mem” mode but this even saves 90% energy compared to a normal on state.


    When you have found the sleep/off state you can build your rtcwake command. If you want to turn off your unit at a specific time say 01:00 and turn it on the next morning at 08:00 (7 hours of sleep) the command looks like this:

    Code
    rtcwake -m off -s 25200


    if you put this in a cron job that runs a 01:00 every night your unit will wake up every morning at 08:00


    If you wan't to turn the unit on at a specific time but not turn it off by your rtcwake command you can use this command:

    Code
    rtcwake -m no -l -t $(date +%s -d ‘tomorrow 08:00’)


    The ”-m no” means that no suspend will be done by rtcwake so you must suspend using an other command or manually.
    You can put this command in a scrip that will turn off your nas at a specific condition or what ever you prefer.
    If you put this job in cron you will have to be sure that the unit is on at the time the cron job is running. If the unit is turning on after the cron jo should have run your nas will not turn automatically on for before 08:00 the day after.


    You can save yourself a lot of troubles with rtcwake if you have your bios set to UTC time and your tzdata setup to reflect your timezone.


    Read more about rtcwake on the man pages http://linux.die.net/man/8/rtcwake

  • Hi, first of all, thanks for the guide. I'm not exactly a Linux connossieur and I didn't even know rtcwake existed.


    Very useful. I have some questions tough, but first I'll explain my case:


    I have a server on which, using the "scheduled jobs" I have configured like the following:



    The command used being: rtcwake -m disk -s 25200 (so it hibernates the server at 2:00am every day and wakes it up at 9:00am every day, if I'm not mistaken)


    When I do short tests like rtcwake -m disk -s 200 the computer goes to hibernation and wakes up 3 minutes later as expected, but I think that, for some reason the server doesn't go to sleep every night as configured in "sceduled jobs" because I can see this in the logs:



    and



    Does that mean that the server is on at those times, right? Do you know what I'm doing wrong?


    Thanks!

  • I wrote a "autowakeup"-script, some time ago, but haven't made it public. If anyone wants to test it, please let me know. You can setup a starttime for every day of the week and the PC is started with rtcwake. So you don't need a cronjob anymore ;)
    I'm on a vacation until wednesday, so be patient ...

  • For those os specific jobs i use cron from the root account login
    Login via console/ssh to a root account

    Code
    crontab -e


    Insert your command

    Code
    00 02 * * * rtcwake -m mem -s xxxxxx


    then deactivate the cronjob that you have entered in the OMV gui
    Try this and wait until tomorrow to se if it has been sleeping during night time

  • On second look it seems like your machine is in the proces of booting in the log entries from 2.03.38 and on. So it might have been shutdown but the -s parameter wasn't passed along correctly so it boots emediately after.


    Still try to enter the rtcwake command ind the os crontab to se if rtcwake works there

  • I tried the crontab way, same result. Do you know if the -s parameter has a maximum numer of seconds allowed? I'm gonna try to put it into sleep now by hand and see what happens tomorrow. Many thanks to all your answers!

  • Well, I finally discovered the reason my computer didn't go to sleep: it has to have a screen connected to it. If there's no screen connected, instead of going to sleep it restarts. The funny thing is that the screen doesn't need to be on. Or even plugged to the wall socket. Only the VGA cable has to be connected for rtcwake to work. It's a headless server, so leaving a screen attached is not the ideal situation. Does anyone know what is causing this strange behavior? Any solution? Thanks.

    • Offizieller Beitrag

    There are ways to make a dummy plug to make the system think it has a monitor connected. Check google for ideas.

    omv 7.0-32 sandworm | 64 bit | 6.5 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.9 | compose 7.0.9 | cputemp 7.0 | mergerfs 7.0.3


    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • hello, i need help to create a rtcwake-job.


    i want that my pc every monday morning at 4:00 according german time (we have summer/wintertime here).
    my server goes into standby with the autoshutdown-plugin.


    is this code right?


    RTC CODE:
    rtcwake -m no -t $(date -d 'next Monday 04:00' +%s)


    CRONJOB - New RTCWAKE entry 2 minutes after wakeup
    2 4 * * 1 rtcwake -m no -t $(date -d 'next Monday 04:00' +%s)

    Server:
    BitFenix Phenom M - ASRock B75 Pro3-M - 8GB Crucial B.S. - Intel G2140 - Corsair CX430M - 1x 64GB SanDisk SDSSDP (system) - 2x 2TB WD20EARX (data) - 1x 3TB WD30EFRX (Snapraid) - TBS6981 DVB-S2 - OMV 0.5x

  • Well if you have your timezone set correctly it should work including when the time changes for summertime soon. You can make sure that you are using the corect time by setting the -l parameter for local time and the -u parameter for universal time. To use your example:

    Code
    rtcwake -m no -l -t $(date +%s -d 'Monday 04:00')
  • Zitat von "Solo0815"

    I wrote a "autowakeup"-script, some time ago, but haven't made it public. If anyone wants to test it, please let me know. You can setup a starttime for every day of the week and the PC is started with rtcwake. So you don't need a cronjob anymore ;)
    I'm on a vacation until wednesday, so be patient ...


    If the offer is still there, I'd like to give it a go - saves having to write my own from scratch ;)


    Not sure what you've done, but I was going to put something in a start-up script, so that each power on re-writes the next wakeup time to the BIOS...


    Thanks

    • Offizieller Beitrag

    Here is Solo's github.

    omv 7.0-32 sandworm | 64 bit | 6.5 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.9 | compose 7.0.9 | cputemp 7.0 | mergerfs 7.0.3


    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Thanks ryecoaaron


    This looks good... however... I can't get this to work.


    The complete illustrated book of instructions appeared to be missing ;)


    So, I...


    Downloaded & extracted the files:

    Code
    wget https://github.com/walterheisenberg/omv-autowakeup/archive/master.zip
    unzip master.zip
    cp -rPv omv-autowakeup-master/* /


    edited /etc/autowakeup.conf (just to set debug=true)
    edited /etc/autowakeup.schedule
    installed the service:

    Code
    sudo update-rc.d autowakeup defaults


    attempted to start the service:

    Code
    sudo service autowakeup start
    autowakeup starting.
    .


    This appears to only work during a startup, so I rebooted ...


    Logging back in, I looked at the logfile and saw that it wasn't working:



    Now, from a command line (logged in as root...), I tried:


    Code
    rtcwake -m no -l -t 1397712600


    Which gave:


    Which appears to be working fine... :?


    So... I'm guessing it's a permissions thing??


    I have no idea on how to get any further... my interweb searches aren't pulling up anything useful...


    Any poiners?


    Thanks

  • I can see no error in the script, besides the "rtcwake"-command isn't working. This command is executed by the script:

    Code
    rtcwake -m no -l -t 1397712600


    maybe you have to experiment with

    Code
    RTC_SHOW_MODE


    It can be 1 or 2, don't know which one is working for you. I wrote the code 7 months ago ;)
    First make sure, you get rtcwake working from the commandline, then you can go on with the script
    Does rtcwake already work from the CLI?

  • Thanks for getting back to me.


    Yes - as I mentioned in my earlier post, if I execute the same command manually, then running "cat /proc/driver/rtc" appeared to show a correct wake up time:

    Code
    rtc_time        : 06:14:46
    rtc_date        : 2014-04-17
    alrm_time       : 07:29:59
    alrm_date       : 2014-04-18
    alarm_IRQ       : yes


    When the script ran during boot, it didn't appear to set a wake up time:

    Code
    rtc_time        : 06:13:57
    rtc_date        : 2014-04-17
    alrm_time       : 07:30:00
    alrm_date       : ****-04-17
    alarm_IRQ       : no


    I have

    Code
    RTC_SHOW_MODE=2


    because:

    Code
    rtcwake -m show
    rtcwake: unrecognized suspend state 'show'



    My earlier testing (before using this script) didn't use rtcwake at all, I was just echoing to wakealarm, ie:


    Code
    echo 0 > /sys/class/rtc/rtc0/wakealarm
    echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm
    cat /sys/class/rtc/rtc0/wakealarm


    Which worked.


    This was taken from this site:
    http://www.mythtv.org/wiki/ACPI_Wakeup


    In fact, I wasn't even aware of the rtcwake command before seeing your script :roll:



    One point which I wanted to check - your script gave this last output:


    Code
    Please check your start times, rtcwake and rights to set rtcwake


    So, running the same command as root worked, which makes me think that it's permissions
    How can I confirm what "user" your script is running as? I've presumed that it would run as root (which is how I ran my test commands), but how could I confirm it?


    I have noticed that rtcwake is also using localtime instead of UTC.
    In my case, my system clock is set to UTC, so I need to remove "-l" from the command line options.


    So, I will try hacking your scripts to add that as an option to /etc/autowakeup.conf until something appears to work :D


    Did you want me to post any code changes in this forum, or send direct to you, or just keep to myself? :D

  • Yes, please share the code with us. Post it here or direct on github. The script was never tested "out in the wild" only on my Server ;)

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!