March 4, 2019

[OwnServer] Schedule server shutdown/sleep and wake up

I'm running personal server at home and it doesn't need to be running 24x7.  It's set to shutdown at late night and start up in the morning or afternoon.

Environment:
  • OS: Ubuntu 16.04
  • Hardware clock is set to UTC

Add following cron entries for 'root' usr:

0 2 * * Sun-Thu /usr/sbin/rtcwake -m mem --date 14:00  >> /opt/automation/logs/rtcwake.log 2>&1

0 3 * * Fri-Sat /usr/sbin/rtcwake -m mem --date 08:00  >> /opt/automation/logs/rtcwake.log 2>&1



This is using "rtcwake" command.
-m : shutdown/suspend/sleep method.  "mem" is suspend to memory.
--date: wake up date in 24-hr format

It's set to suspend at 2am/3am -- plenty of time to do some batch job/back up that starts at night, then shutdown (or suspend).

References


No comments: