Autoshutdown and suspend to mem with rtcwake

    • OMV 2.x
    • Autoshutdown and suspend to mem with rtcwake

      Before switching to omv I was using powernap to put my server to sleep when it was inactive.

      I start a backup up every night and I would like to continue doing that using the autoshutdown plugin.

      How to I get it to call my script or what script do I have to change to get my system waking up at a predetermined time as before?

      Here is the suspend script that I used to use:

      Shell-Script

      1. #!/bin/sh
      2. #
      3. # Simple script for getting a computer to wake up at a predetermined time using rtcwake
      4. #
      5. #
      6. # What time should the server wake up at
      7. #
      8. WAKE_AT=04:02:00
      9. #
      10. # Get current time in seconds
      11. #
      12. NOW=`date +%s`
      13. #
      14. # Time in seconds for 4AM today
      15. #
      16. WAKE_TODAY=`date -d "today ${WAKE_AT}" +%s`
      17. #
      18. # Time in seconds for 4AM tomorrow
      19. #
      20. WAKE_TOMORROW=`date -d "tomorrow ${WAKE_AT}" +%s`
      21. #
      22. # Check to see if the wake up for to today is already in the past and reassign WAKE_AT to the value in seconds
      23. #
      24. if [ $NOW -gt $WAKE_TODAY ]; then
      25. WAKE_AT=$WAKE_TOMORROW
      26. else
      27. WAKE_AT=$WAKE_TODAY
      28. fi
      29. #
      30. # Log the event
      31. #
      32. logger "Sleeping until "`date --date=@$WAKE_AT`
      33. #
      34. # Suspend to memory until the desired time
      35. #
      36. rtcwake -m mem -t $WAKE_AT
      Display All
    • I recommend the WOL plugin because it installs rtcwake. You could just execute the rtcwake command (same as your script uses) with a scheduled job (daily) and use the autoshutdown plugin to put your system to sleep.
      omv 4.1.13 arrakis | 64 bit | 4.15 proxmox kernel | omvextrasorg 4.1.13
      omv-extras.org plugins source code and issue tracker - github

      Please read this before posting a question and this and this for docker questions.
      Please don't PM for support... Too many PMs!
    • Calling rtcwake suspends the system to memory so a scheduled suspend isn't really going to give me the functionality that I need.

      As I said in my OP, I'm looking for a way to call my script instead of the standard suspend but I don't know my way around the pm-utils package to get this to work.

      What would be really cool is if the autoshutdown maintainer could add a "scheduled wake up at" option to do this out of the box.
    • red-lichtie wrote:

      Calling rtcwake suspends the system to memory so a scheduled suspend isn't really going to give me the functionality that I need.

      You didn't look at the options of rtcwake... There is an option "No - Don't suspend. Sets RTC wakeup time only."

      If you want an option added to autoshutdown, file an issue here.
      omv 4.1.13 arrakis | 64 bit | 4.15 proxmox kernel | omvextrasorg 4.1.13
      omv-extras.org plugins source code and issue tracker - github

      Please read this before posting a question and this and this for docker questions.
      Please don't PM for support... Too many PMs!
    • subzero79 wrote:

      pm-utils also provides hook scripts for the designated folders. if you want to run scripts after a state.

      /etc/pm/sleep.d/ I'm guessing?
      omv 4.1.13 arrakis | 64 bit | 4.15 proxmox kernel | omvextrasorg 4.1.13
      omv-extras.org plugins source code and issue tracker - github

      Please read this before posting a question and this and this for docker questions.
      Please don't PM for support... Too many PMs!
    • ryecoaaron wrote:

      You didn't look at the options of rtcwake... There is an option "No - Don't suspend. Sets RTC…

      I'm sorry, I didn't realize that the rtc event would still happen doing it that way and now it also makes perfect sense what you said before about a cron job.

      I think that I shall try that out.

      I use drivish to make incremental backups and have that run 2 minutes after the scheduled wake up time.

      I'll give it a try this evening and let you all know how it works out.

      Thanks
    • I have it working now

      I meant to get back about this before but I forgot.

      Adding a script to "/etc/pm/sleep.d" was the solution with authshutdown installed.

      I have added a script called "01-set-wakeup" and set it executable.

      Shell-Script

      1. #!/bin/bash
      2. set_wakeup_time()
      3. {
      4. WAKE_AT=22:00:00
      5. NOW=`date +%s`
      6. WAKE_TODAY=`date -d "today ${WAKE_AT}" +%s`
      7. WAKE_TOMORROW=`date -d "tomorrow ${WAKE_AT}" +%s`
      8. if [ $NOW -gt $WAKE_TODAY ]; then
      9. WAKE_AT=$WAKE_TOMORROW
      10. else
      11. WAKE_AT=$WAKE_TODAY
      12. fi
      13. logger "Set rtcwake for "`date --date=@$WAKE_AT`
      14. rtcwake -a -m no -t $WAKE_AT
      15. }
      16. case "$1" in
      17. hibernate|suspend)
      18. set_wakeup_time
      19. ;;
      20. thaw|resume)
      21. # Do nothing
      22. ;;
      23. *)
      24. logger -s -t "$USER set-wakeup [$$]" "other: set-wakeup call from /etc/pm/sleep.d/set-wakeup"
      25. ;;
      26. esac
      Display All


      This gets called when pm-suspend is called and set the RTC to wake up my server at 22:00 local.

      At 22:04 my backup is started by cron and dirvish mounts my external USB drive, does an incremental backup and then unmounts the drive.

      It would be nice if enabling and setting the time was a standard part of the WOL-RTC plugin though.

      So I'm happy that my backup is now running automatically every evening.