You are not logged in.

#1 2020-03-12 22:11:52

ozooha
Member
Registered: 2009-09-29
Posts: 184

Issue with rtc wakealarm - does not work

Setting a systemd timer to shut my PC daily at 1 am and then wake it up after 7 hr

/etc/systemd/system/myshutwake.timer

[Unit]
Description=Runs myscript daily to shut and wake the PC

[Timer]
#Runs daily at 1 AM
OnCalendar=*-*-* 01:00:00
Unit=myshutwake.service

[Install]
WantedBy=timers.target

/etc/systemd/system/myshutwake.service

[Unit]
Description=My Script To Shut and wake the PC

[Service]
Type=simple
ExecStart=/usr/local/bin/shutwake

/usr/local/bin/shutwake

#!/bin/bash
sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm"
sh -c "echo `date '+%s' -d '+ 420 minutes'` > /sys/class/rtc/rtc0/wakealarm"
shutdown --halt now

I execute the command below with no issues.

systemctl start myshutwake.timer

So it shutsdown fine but never seems to wake up.

Below are the commands and the respective output for  the shutwake script with a wake up test for 5 mins.

[root@domain]# echo 0 > /sys/class/rtc/rtc0/wakealarm
[root@domain]# echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm
[root@domain]# cat /sys/class/rtc/rtc0/wakealarm
1584050778
[root@domain]# date -d @1584050778 +%F" "%T
2020-03-12 18:06:18
[root@domain]# cat /proc/driver/rtc
rtc_time    : 22:01:38
rtc_date    : 2020-03-12
alrm_time    : 22:06:18
alrm_date    : 2020-03-12
alarm_IRQ    : yes
alrm_pending    : no
update IRQ enabled    : no
periodic IRQ enabled    : no
periodic IRQ frequency    : 1024
max user IRQ frequency    : 64
24hr        : yes
periodic_IRQ    : no
update_IRQ    : no
HPET_emulated    : yes
BCD        : yes
DST_enable    : no
periodic_freq    : 1024
batt_status    : okay

Any help would be appreciated.
Let me know if you require any other information.

OZooHA

Offline

#2 2020-03-13 07:20:32

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,944

Re: Issue with rtc wakealarm - does not work

Does it wakeup from S3 (you can btw. use rtcwake for this task)?
Wakeup from S5 is no official ACPI feature - your BIOS might simply not support that.

Offline

#3 2020-03-13 09:38:49

NoSavvy
Member
From: Dorchester, Dorset, UK
Registered: 2013-01-23
Posts: 127

Re: Issue with rtc wakealarm - does not work

Is the myshutwake.timer actually ENABLED ie, "sudo systemctl enable myshutwaketimer" and not just started.
Just a guess.

Last edited by NoSavvy (2020-03-13 09:39:18)

Offline

#4 2020-03-13 15:50:36

ozooha
Member
Registered: 2009-09-29
Posts: 184

Re: Issue with rtc wakealarm - does not work

NoSavvy wrote:

Is the myshutwake.timer actually ENABLED ie, "sudo systemctl enable myshutwaketimer" and not just started.
Just a guess.

Yes it was enabled.

Offline

#5 2020-03-13 16:10:45

ozooha
Member
Registered: 2009-09-29
Posts: 184

Re: Issue with rtc wakealarm - does not work

seth wrote:

Does it wakeup from S3 (you can btw. use rtcwake for this task)?
Wakeup from S5 is no official ACPI feature - your BIOS might simply not support that.

Yes it supports S3 (from the BIOS) and not S5 and does not wakeup.
It does not wake up from rtcwake which I had used on the CLI to test.

My attempt at this systemd timer is to halt the PC at 0100 hrs and then let it sit for 7 hrs and then resume back.
Repeat this process daily.

How can I use the systemd halt and resume feature to do this instead of using the bash script with wakealarm?

Thanks and appreciate your thoughts and inputs.
OZooHA

Offline

#6 2020-03-13 17:44:22

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,944

Re: Issue with rtc wakealarm - does not work

I missed the "halt" part…

a) why do you want to do that itfp?
b) what do you think that does?
c) i don't think that there's any way to have the rtc timer reboot from a halted system

Does

rtcwake -m mem --date +5min # suspend to ram

work?
What about

rtcwake -m off --date +5min # shuts down and powers off

?

Offline

#7 2020-03-13 19:18:52

ozooha
Member
Registered: 2009-09-29
Posts: 184

Re: Issue with rtc wakealarm - does not work

seth wrote:

I missed the "halt" part…

a) why do you want to do that itfp?
b) what do you think that does?
c) i don't think that there's any way to have the rtc timer reboot from a halted system

Does

rtcwake -m mem --date +5min # suspend to ram

work?
What about

rtcwake -m off --date +5min # shuts down and powers off

?

a) I have a server and want to shut it down at a point in time during the day for 7 hours before I need it again.
b) Like I said above, It just shuts the PC server down and then wakes it up after 7 hours.
c) It doesn't have to be rtc timer per se but a systemd timer/halt/suspend etc as well.
    If you know of how one can do, can you direct me a .timer or .service script?

Outputs for both the rtc commands above:

[ozooha@domain ~]$ sudo rtcwake -m mem --date +2min
[sudo] password for ozooha: 
rtcwake: wakeup from "mem" using /dev/rtc0 at Fri Mar 13 15:00:00 2020
rtcwake: write error

The PC remains on.

[ozooha@domain ~]$ sudo rtcwake -m off --date +2min
[sudo] password for ozooha:  
rtcwake: wakeup from "off" using /dev/rtc0 at Fri Mar 13 15:08:22 2020
Connection closed by remote host.
Connection closed.

PC does not reboot back after 2 minutes.

Offline

#8 2020-03-13 19:29:28

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,944

Re: Issue with rtc wakealarm - does not work

Halting doesn't power off the system, it will just shut down the system and stop the CPU/s but the system remains running.
Apparently rtc wake from S5 doesn't work and rtcwake fails to initiate S3(??) - can you "systemctl suspend" (ie. did you ever sucessfully put the system to S3)?

Does the system support and would you consider https://wiki.archlinux.org/index.php/Wake-on-LAN ?

Offline

#9 2020-03-13 23:57:56

ozooha
Member
Registered: 2009-09-29
Posts: 184

Re: Issue with rtc wakealarm - does not work

seth wrote:

Halting doesn't power off the system, it will just shut down the system and stop the CPU/s but the system remains running.
Apparently rtc wake from S5 doesn't work and rtcwake fails to initiate S3(??) - can you "systemctl suspend" (ie. did you ever sucessfully put the system to S3)?

Does the system support and would you consider https://wiki.archlinux.org/index.php/Wake-on-LAN ?

The systemctl suspend worked as in it went down and upon hitting the resume button, the pc resumed back again.

So as per your suggestion I have successfully tested Wake-on-LAN to resume my PC after using systemctl suspend.

Point me to a systemd timer file which will suspend the PC for a few hours and then wake it up.
OR
How do I use my current timer file to start back the PC after X hours as in using my modified myshutwake.service file (see below)?
Is there a way to suspend the PC and wake it up after X hours?

/etc/systemd/system/myshutwake.timer

    [Unit]
    Description=Runs myscript daily to shut and wake the PC

    [Timer]
    #Runs daily at 1 AM
    OnCalendar=*-*-* 01:00:00
    Unit=myshutwake.service

    [Install]
    WantedBy=timers.target

/etc/systemd/system/myshutwake.service

    [Unit]
    Description=My Script To Shut and wake the PC

    [Service]
    Type=simple
    ExecStart=/usr//bin/systemctl suspend

Thanks for your valuable thoughts and feedback, much appreciated.
OZooHA

Offline

#10 2020-03-14 09:04:04

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,944

Re: Issue with rtc wakealarm - does not work

I'm not sure why rtcwake fails to send your system to S3, but if "systemctl suspend" works, you could simply adjust your original script but instead of "shutdown --halt now" run "systemctl suspend".

WOL was intended as an alternative approach, ie. you send the server to sleep when you do no longer need it and have it wake up by a WOL package from the client the next morning (no timer stuff) in case the rtc completely fails to wake the system.

Offline

#11 2020-03-14 11:20:02

merlock
Member
Registered: 2018-10-30
Posts: 262

Re: Issue with rtc wakealarm - does not work

This wakes my machine every day at 0200 for maintenance tasks (works when suspended by direct command, inactivity timer or i3 keybind):

/etc/systemd/system/auto-resume.timer
----------------------------------------------------------
[Unit]
Description=Wake the stoopid computer up

[Timer]
OnCalendar=*-*-* 02:00:00
WakeSystem=true

[Install]
WantedBy=timers.target
/etc/systemd/system/auto-resume.service
----------------------------------------------------------
[Unit]
Description=Wake the stoopid computer up

[Service]
Type=oneshot
ExecStart=/usr/bin/true

@ozooha, your shutwake timer should work; mine fires at 0235 when my maintenance tasks are complete (is just like yours, except for the typo in yours):

ozooha wrote:
ExecStart=/usr//bin/systemctl suspend

Change to

ExecStart=/usr/bin/systemctl suspend

Eenie meenie, chili beanie, the spirits are about to speak -- Bullwinkle J. Moose
It's a big club...and you ain't in it -- George Carlin
Registered Linux user #149839
perl -e 'print$i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10); '

Offline

#12 2020-03-14 15:37:30

NoSavvy
Member
From: Dorchester, Dorset, UK
Registered: 2013-01-23
Posts: 127

Re: Issue with rtc wakealarm - does not work

This works for me and has always done so after a manual suspend when I finish.

[Unit]
Description=rtcwake, switches PC on at 7.50 every morning
After=multi-user.target

[Service]
Type=simple
ExecStart=/bin/bash /home/johnny/ShellFiles/rtcwake.sh

[Install]
WantedBy=multi-user.target


rtcwake contains  --   /usr/sbin/rtcwake -m no -l -v -t $(date +%s -d 'tomorrow 07:50')


Apologies for posting wrong text.

Last edited by NoSavvy (2020-03-16 11:33:43)

Offline

#13 2020-03-14 20:47:44

ozooha
Member
Registered: 2009-09-29
Posts: 184

Re: Issue with rtc wakealarm - does not work

First of all, thanks so much for your help guys. Much appreciated.

So if I wanted to build just a timer which suspends after an hour of inactivity would this timer work (modified myshutwake.timer from above)?
I would then use Wake-on-LAN to wake it up and would it then wait for an hour of inactivity from the WOL and suspend the PC again?
Would it require any modifications?

myshutPCHour.timer

[Unit]
Description=Suspends the PC

[Timer]
#Runs daily everyhour of inactivity
OnCalendar=*-*-* *:00:00
Unit=myshutPCHour.service

[Install]
WantedBy=timers.target

myshutPCHour.service

[Unit]
Description=suspends the PC

[Service]
Type=simple
ExecStart=/usr/bin/systemctl suspend

Thanks again for your inputs and time.
OZooHA

Offline

#14 2020-03-14 23:22:38

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,944

Re: Issue with rtc wakealarm - does not work

I don't think systemd timers handle inactivity, but you could use the IdleAction in /etc/systemd/logind.conf - whether that works drastically depend on the environment (systemd relies on an external idle hint which is provided by eg. the big desktop environments, but I'm less than sure you'd get that from eg. sshd - although: https://github.com/systemd/systemd/issues/9622 )

It really matters what the server does and what counts as "idle" (eg. if this is a http or mpd server or …)

Offline

Board footer

Powered by FluxBB