Scheduled Shutdown / reboot

Hi all.
I want to set up a scheduled shutdown on one of my machines and only wake it (reboot) and be available on a specific day - say for 24 hours then shutdown again. So in effect it’s shutdown for 6 days and awake for 1 day a week.
I get the system suspend and it seems to work but it’s a little inflexible as you have to schedule a suspend / start time on a daily basis.

Does anyone have any insight into this? There’s nothing on the forums and no documentation about this feature (shutdown & reboot), or how to use it.

Hoping that someone has worked with this feature - and can enlighten me!

Many thanks

1 Like

You’d probably need to setup a cronjob calling something like RTCWake.
Lets say that at 5:00pm on Wednesday you want to shutdown, and wake up again at 9:00am the following wednesday.

The first thing I would try is a cron job in /etc/crontab as follows

# Cron job definition:
#   .----------------------------------------------------< Minute (0 - 59) >
#   |       .--------------------------------------------< Hour (0 - 23) >
#   |       |       .------------------------------------< Day of month (1 - 31) >
#   |       |       |       .----------------------------< Month (1 - 12) OR jan,feb,mar,apr ... >
#   |       |       |       |       .--------------------< Day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat >
#   |       |       |       |       |       .------------< User running the command >
#   |       |       |       |       |       |       .----< Command to be run >
#   |       |       |       |       |       |       |
    00      17      *       *       4       root    /usr/sbin/rtcwake -m disk -t $(date -d "9:00 Next Wednesday" +"%s")

Note that a value of * means Any
In this way, we run at 5:00pm on the dot, on any day of the month, in any month of the year
But ONLY if it’s a wednesday.

The command breakdown is as follows:
Call RTCWake
Use the function ‘Suspend to disk’ (S4 suspend)
Set the wake time to the time “9:00 Next Wednesday” presented un unix epoch time (Seconds since 00:00:00 UTC on 1 January 1970)

Experiment from there to suit your needs.

I think RTCWake should be installed by default. If not, it should be provided by the “util-linux” package.

Hope this helps.


HI Haioken
That’s a great reply - certainly looks like the way to do it. Sadly I’m not that linux savvy so a fundamental for me is how do I go about setting up that cron job on my machine? - Ask me to write c# or html or anything to do with any flavour of Windows I’m there!

I did rather hope the Rockstor UI would have this basic functionality built in, otherwise why have the suspend, shutdown and reboot options in the first place?

I’ve tried setting up a test scheduled (using the ui) shutdown at say 10am then at 11am I’ve set up a reboot - But the reboot does not fire.
As in my previous post daily suspend / wake up works fine, but it lacks flexibility, and in any event the suspend won’t work unless you check the Enable System RTC wake up box and specify a time. So in the event of setting a weekly suspend how does the wake up work?

Hoping I’m missing something!

I wouldn’t consider this ‘basic’ functionality, and the Rockstor UI while very useful is still pretty rudimentary. It’s designed to accommodate for the most common needs of users.
This particular need wouldn’t be considered common.
I think that there’s an open issue regarding adding a more flexible scheduling service, but this likely won’t be addressed very soon.

The first thing that you’ll need to do is gain shell access.
If you haven’t configured SSH access for yourself, the easiest way to do this in Rockstor is via the ‘shellinabox’ plugin. I’m not next to my Rockstor box at the moment, so somebody else might need to guide you through getting this up and running, and logging into it.

Next, you’ll need to edit the crontab file using a text editor. Typically I suggest Vim, but if you’re not accustomed to Vim, this will have a learning curve, so instead I suggest nano.
Edit the file by running:

sudo nano /etc/crontab

When the text editor is open, add the uncommented line to the end of the file, then write and exit.
The uncommented line is separated into 7 fields, each separated by any horizantal whitespace.
I used a lot of spaces for alignment to show you how the fields are structured, but it will be easier to write simply as:

00 17 * * 4 root /usr/bin/rtcwake -m disk -t $(date -t "9:00 Next Wednesday" +"%s")

That’s because the reboot command is a separate cron task, and cron is only fired when the system is online. Also this is not the purpose of the reboot command. It’s not “Boot an offline computer”, it’s “Restart a running computer”.

Cron is a service that runs on an online computer and monitors the clock. As the clock hits certain times, cron can be instructed to run scheduled tasks (via the crontab)

RTCWake by comparison works a little differently. It registers a “wake” command in the real-time clock of the system (RTC), and then suspends the system.
This means that the ‘wake’ command does not rely on the system being online to process cron jobs.

By running RTCWake in the manner specified in the example provided, cron only processes RTCWake to suspend the computer, cron does NOT wake the computer.

The wake is handled by the register set by RTCWake in the computer’s RTC, which will continue operating during any system suspend state.


Hi @PaulK,

I believe @Haioken perfectly answered how to do what you are seeking, I wanted to add a couple things related to Rockstor’s implementation.

First of all, thanks for pointing out the lack of details on this feature in Rockstor’s documentation. I have now created an issue on the corresponding Github repository to keep track of and correct this:

As @Haioken mentioned, this particular part of Rockstor is–like pretty much every other part–designed to provide an interface as as simple as possible for the user to perform tasks such as these. As a result, it is driven by the users’ needs and I’m thus happy to see your suggestion to improve this specific part of it. I’ve now created an issue on the corresponding Github repository (linked below) to keep track of it.

For this reason, don’t hesitate to keep this thread updated with your resolution.

1 Like