Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schedule power down/up of the system #735

Closed
schakrava opened this issue Jul 14, 2015 · 21 comments
Closed

Schedule power down/up of the system #735

schakrava opened this issue Jul 14, 2015 · 21 comments
Assignees
Labels
Milestone

Comments

@schakrava
Copy link
Member

feature request from the forum thread: http://forum.rockstor.com/t/features-i-would-like-in-rockstor/210

relevant section:
You can also power the NAS down and up again on a schedule, but I'm not sure this could be implemented on RockStor, due to lack of control over how to power the sytem up again.

@schakrava schakrava added this to the Yosemite milestone Jul 14, 2015
@phillxnet
Copy link
Member

@schakrava A "Task type" profile to go along with the existing scrub and snapshot profiles could do a poweroff command at a configurable time. Users can always configure their BIOS to do timed power on with many systems these days until we get a proper UEFI interface option to do timed power-ups.

MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Jul 17, 2016
Initial commit for custome scheduled tasks feature on Rockstor
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Jul 19, 2016
Initial commit for custome scheduled tasks feature on Rockstor
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Sep 30, 2016
Initial commit for custome scheduled tasks feature on Rockstor
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Oct 2, 2016
Initial commit for custome scheduled tasks feature on Rockstor
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Oct 7, 2016
Initial commit for custome scheduled tasks feature on Rockstor
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Nov 15, 2016
Initial commit for custome scheduled tasks feature on Rockstor
@phillxnet
Copy link
Member

Noting @MFlyer supplied link to acpi / RTC info for scheduled wake-up from the following forum thread:
https://www.mythtv.org/wiki/ACPI_Wakeup
please update the following forum thread with the resolution of this issue:
https://forum.rockstor.com/t/power-management-auto-power-off-and-on/2815/4

Linking back to related issue #1036 which also has some info on ACPI / RTC wake up programming.

@MFlyer
Copy link
Member

MFlyer commented Feb 10, 2017

Some good reference too:

https://www.linux.com/learn/wake-linux-rtc-alarm-clock

@MFlyer
Copy link
Member

MFlyer commented Feb 10, 2017

Having code on this like a separate/test/base PR for #1036

@MFlyer
Copy link
Member

MFlyer commented Feb 15, 2017

Cross ref to #1306

@MFlyer
Copy link
Member

MFlyer commented Feb 15, 2017

@schakrava @phillxnet
Updates:
successfully scheduled a reboot or shutdown task and tested it, currently missing:

  • task editing funcs
  • custom shutdown options to allow wake on rtc
  • live wake rtc tester (inform user about rtc avail or not and suggest a test to try shutdown + wake on rtc)
  • WebUI helpers to alert connected users on incoming shutdown/reboot

Mirko

MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Feb 16, 2017
Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Feb 16, 2017
Refs to rockstor#735 and rockstor#1306 - reboot and shutdown funcs already used
when performing those action via WebUI. Scheduled reboots/shutdowns
will have a 2 min delay (shutdown now is instead 1 min) to allow
users to stop system shutdown too

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Feb 16, 2017
Refs to rockstor#735 and rockstor#1306 - Url Dispatcher updated to handle new
reboot/shutdown delay param, same done over commands view
Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Feb 19, 2017
Refs to rockstor#735 rockstor#1306 - Adding rtc wake up hour and minute fields to
shutdown template plus auto toggle on rtc wake up checkbox

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
@MFlyer
Copy link
Member

MFlyer commented Feb 19, 2017

Asking @rockstor/developers, @schakrava and users (@maxhq , @magicalyak, @daniel-illi, @sfranzen, @chrstphrchvz, @PhilippeAB, @tomtom13 and others) feedbacks:

Can you shell check this?
journalctl | grep rtc

On my dev env got an S4 support, so no available rtc wake up after system shutdown, but wake up from suspend wyth systemctl suspend(ACPI reference)
Probably 99% env support S4 only, so we can grant a suspend+wake up and not shutdown + wake up

@phillxnet
Copy link
Member

@MFlyer OK, on my ASUS N3700-ITX board I get:

journalctl | grep rtc
Feb 19 18:50:39 cube kernel: rtc_cmos 00:00: RTC can wake from S4
Feb 19 18:50:39 cube kernel: rtc_cmos 00:00: rtc core: registered rtc_cmos as rtc0
Feb 19 18:50:39 cube kernel: rtc_cmos 00:00: alarms up to one month, y3k, 242 bytes nvram
Feb 19 18:50:39 cube kernel: rtc_cmos 00:00: setting system clock to 2017-02-19 18:50:39 UTC (1487530239)

From memory isn't S4 essentially off anyway, S3 is regular suspend. I.e when bios set to have WOL doesn't that mean that off is S4 level and no deeper.
This motherboard is very likely to have wake on RTC, even from off, ie power down not just suspend.

Also from a NUC I have I get the following:

Feb 19 08:46:40 ytagit kernel: [    1.693588] rtc_cmos 00:05: RTC can wake from S4
Feb 19 08:46:40 ytagit kernel: [    1.693705] rtc_cmos 00:05: rtc core: registered rtc_cmos as rtc0
Feb 19 08:46:40 ytagit kernel: [    1.693734] rtc_cmos 00:05: alarms up to one month, y3k, 242 bytes nvram, hpet irqs
Feb 19 08:46:40 ytagit kernel: [    1.708649] rtc_cmos 00:05: setting system clock to 2017-02-19 08:46:36 UTC (1487493996)

And this device wakes itself every morning via bios settings after shutting itself down via the following cron job every night:

# power off at 30 mins past midnight every day
30 0 * * * /sbin/poweroff

Does that help?

@MFlyer
Copy link
Member

MFlyer commented Feb 19, 2017

Thanks for your feedback @phillxnet ,
got same output on my Rockstor dev env, but no wake up from power off, trying to understand if guest over Proxmox related or not (quite sure about virtualization issue / missing params)

Can you test system wake up on that ASUS with:

echo 0 > /sys/class/rtc/rtc0/wakealarm
echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm
shutdown -h now

On a working motherboard this will provide system wake up from power off after 5 mins

@MFlyer
Copy link
Member

MFlyer commented Feb 20, 2017

Having some tests with built-in rtcwake tool (shutdown/suspend + wake after 120 sec):

rtcwake -m disk -s 120 -> fails, mode disk is S4
rtcwake -m mem -s 120 -> ok, mode mem is S3
rtcwake -m off -s 120 -> fails, mod off is system poweroff S5
rtcwake -m freeze -s 120 -> VM seems running, but no response

S1 (standby) not available on my env

To @phillxnet : you can try rtcwake -m off -s 120 to check wakeup from off without playing with echos to wakealarm :)

Finally I still have working wakeup only on suspend to RAM

@maxhq
Copy link
Contributor

maxhq commented Feb 20, 2017

Hi @MFlyer, on my HP ProLiant MicroServer Gen8 I get:

Jan 11 15:19:17 Sigurd kernel: rtc_cmos 00:01: RTC can wake from S4
Jan 11 15:19:17 Sigurd kernel: rtc_cmos 00:01: rtc core: registered rtc_cmos as rtc0
Jan 11 15:19:17 Sigurd kernel: rtc_cmos 00:01: alarms up to one day, 114 bytes nvram, hpet irqs
Jan 11 15:19:17 Sigurd kernel: rtc_cmos 00:01: setting system clock to 2017-01-11 14:19:17 UTC (1484144357)

@MFlyer
Copy link
Member

MFlyer commented Feb 20, 2017

Hi @maxhq ,
thanks for your feedback 👍
Can you try rtcwake -m mem -s 120 (suspend + wakeup) and rtcwake -m off -s 120 (poweroff + wakeup) ? Note: probably suspend + wakeup will work fine, not sure about poweroff + wakeup <- you' ll need to manually poweron your machine

Mirko

@magicalyak
Copy link
Contributor

magicalyak commented Feb 20, 2017

Nothing on journalctl (it's pretty busy) but dmesg | grep rtc
[root@rocky ~]# dmesg | grep rtc
[ 7.694698] rtc_cmos 00:01: RTC can wake from S4
[ 7.695045] rtc_cmos 00:01: rtc core: registered rtc_cmos as rtc0
[ 7.695076] rtc_cmos 00:01: alarms up to one month, y3k, 114 bytes nvram, hpet irqs
[ 7.733611] rtc_cmos 00:01: setting system clock to 2016-12-24 18:47:12 UTC (1482605232)

I'm not in a position shutdown/suspend and restart at the moment. My server is up 24/7 (it also runs DNS for me)

Server type:
[root@rocky ~]# dmesg | grep HP
[ 0.000000] DMI: HP ProLiant DL180se G6, BIOS O33 10/20/2012
[ 0.000000] ACPI: RSDP 0x00000000000FA170 000024 (v02 HP )
[ 0.000000] ACPI: XSDT 0x00000000BF770100 0000A4 (v01 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: FACP 0x00000000BF770290 0000F4 (v04 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: DSDT 0x00000000BF770740 005EF3 (v02 HP ProLiant 00000244 INTL 20051117)
[ 0.000000] ACPI: APIC 0x00000000BF770390 00011E (v02 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: SPCR 0x00000000BF7704B0 000050 (v01 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: MCFG 0x00000000BF770500 00003C (v01 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: SPMI 0x00000000BF770540 000041 (v05 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: SLIC 0x00000000BF770590 000176 (v01 HP SLIC1034 20121020 MSFT 00000097)
[ 0.000000] ACPI: BOOT 0x00000000BF770710 000028 (v01 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: OEMB 0x00000000BF77E040 00007A (v01 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: HPET 0x00000000BF77A740 000038 (v01 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: SRAT 0x00000000BF77A780 0001D0 (v02 HP ProLiant 00000001 INTL 00000001)
[ 0.000000] ACPI: SSDT 0x00000000BF780EA0 000363 (v01 HP ProLiant 00000012 INTL 20051117)
[ 0.000000] ACPI: EINJ 0x00000000BF77A950 000130 (v01 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: BERT 0x00000000BF77AAE0 000030 (v01 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: ERST 0x00000000BF77AB10 0001B0 (v01 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: HEST 0x00000000BF77ACC0 0000A8 (v01 HP ProLiant 20121020 MSFT 00000097)
[ 0.000000] ACPI: HPET id: 0x8086a301 base: 0xfed00000
[ 8.847705] scsi 0:0:10:0: Enclosure HP DL18xG6BP 2.18 PQ: 0 ANSI: 5

MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Feb 21, 2017
Refs to rockstor#735 rockstor#1306 and rockstor#1036 - Adding new suspend task on backend model
and view plus smart_manager migration patching
Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Feb 21, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036: If task is suspend, aka system suspend
to RAM, we force users to have a wake up!
Adding suspend too because probably many system won't support
full power off + wake, while suspend works

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 and rockstor#1306 - Url Dispatcher updated to handle new
reboot/shutdown delay param, same done over commands view
Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 - Adding rtc wake up hour and minute fields to
shutdown template plus auto toggle on rtc wake up checkbox

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 and rockstor#1036 - Adding new suspend task on backend model
and view plus smart_manager migration patching
Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036: If task is suspend, aka system suspend
to RAM, we force users to have a wake up!
Adding suspend too because probably many system won't support
full power off + wake, while suspend works

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036
Delay param for reboot and shutdown no more required, checking if
scheduled task via request.auth (none if command from WebUI, token if
over APIWrapper by scheduled task). When shutdown and reboot come from
a scheduled task we grant a 3 minute grace period to cancel it
New rtcepoch param used to pass desired system wakeup epoch for
shutdown and suspend
Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036
Added new handler for suspend task, served by same script.
Wakeup need rtc hour/minute int to compute if task will be this day or
next day, data conversion here to avoid it over cron script, so we convert
from string to int only on db saving.

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036
APIWrapper no more sending delay, using instead epoch wakeup time
if present (delay checks moved to command view with token/not token req check)
On shutdown and suspend tasks we check if wakeup option is on and parse
cron time vs wakeup time to find if wake is on same day or next day

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036
system_shutdown and system_reboot run with a delta, default to now when
running from user input from WebUi and 3 mins when called via scheduled tasks
Added system_suspend function just running a systemctl suspend
Added wakeup functions set_system_rtc_wake and clean_system_rtc_wake:
set_system_rtc_wake is our core function to set system wakeup, writing to default
rtc0 wakealarm user wakeup time in epoch format, after flushing every wakeup value
with clean_system_rtc_wake (write 0 to clean every time or we raise a resurce busy err)
IMPORTANT: epoch can't be passed as a string, needed int -> write('%s' % epoch) fails

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036 - Added new else statement over tasks list page
to handle common tasks like shutdown, suspend and reboot

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036 - Added new wakeup, rtc_hour and rtc_minute
fields to backbone properties for Task object

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036 - Cleaned template structure
Before this commit we had a page with 2 templates (main template and
optional-fields template), "child" optional-fields template was used
only when creating new tasks, tasks edit had a messy if else group on
main template -> Moved all to optional-fields rendering on edit too

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036
Scheduling task has a complete new view handling tasks edit over
optional-fields template instead of main template
Added some helpers (jquery helpers and Handlebars Helpers) for new
shutdown/suspend/reboot tasks plus Handlebars Partials to have global
vars to make taskObj available to main template and optional-fields
template to. @schakrava check inline comments for more infos ;)

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs rockstor#735 rockstor#1306 rockstor#1036 - Flake8 for some files

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs rockstor#735 rockstor#1306 rockstor#1036

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036 - Added user warning to check/test RTC WAKEUP capabilities
before setting a shutdown/suspend task

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036
Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs rockstor#735 rockstor#1306 rockstor#1036 - Added ad hoc div to alert user about scheduled
shutdown/reboot task
Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036 - Added systemd-shutdownd service to available services
for monitoring. Service turns on (rc=0) when a system shutdown/reboot scheduled,
turns off (rc=3) if no shutdowns scheduled

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
MFlyer added a commit to MFlyer/rockstor-core that referenced this issue Mar 8, 2017
Refs to rockstor#735 rockstor#1306 rockstor#1036 - frontend/backend adds to control pending
shutdown/reboot tasks. data_collector checks every 30 secs if we have
a pending shutdown (if scheduled returns shutdown message with time infos too)
On fronted we alert user with a message over Rockstor navbar

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
@MFlyer
Copy link
Member

MFlyer commented Mar 23, 2017

Hi @schakrava , like on #1306 i missed Fixes statement on commits.
Can be closed
M.

@schakrava schakrava modified the milestones: Point Bonita, Yosemite Mar 24, 2017
@MFlyer
Copy link
Member

MFlyer commented Apr 4, 2017

After Yum updates back on this: new job on May 🎉 , new nephew (welcome Zeno!!!), new cool issue 😃

Mirko

@MFlyer
Copy link
Member

MFlyer commented Apr 18, 2017

Starting up again with a fresh new branch from last rockstor core updates

@phillxnet
Copy link
Member

@MFlyer Am I right that this can be closed as Fixed by pr #1659
Your linked other issue #1306 has now been closed.
Bit confusing as further comment there after!

@MFlyer
Copy link
Member

MFlyer commented Jul 27, 2017

You're right @phillxnet , already told it to @schakrava on previous message :)
Mirko

@schakrava
Copy link
Member Author

Thank you @MFlyer ! Sorry this got missed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants