You are not logged in.

#1 2018-03-06 08:58:41

ronnylov
Member
Registered: 2010-12-21
Posts: 65

How to schedule poweroff with systemd?

Hi!

I am trying to figure out how to schedule poweroff every monday to friday at 5 AM and then I will set a poweron schedule in bios at 9 AM. I think this can be done with a cron job but I want to do it in modern systemd way. I need to reduce power draw in mornings and my quad socket opteron server could save some power then by shutdown.

I guess I need a systemd timer
https://wiki.archlinux.org/index.php/Sy … eplacement

And use systemd-shutdownd.service
https://utcc.utoronto.ca/~cks/space/blo … OfShutdown

But not sure how to pull everything together.
So I am asking for some friendly hints.

Thanks!

Offline

#2 2018-03-06 10:30:41

Awebb
Member
Registered: 2010-05-06
Posts: 6,272

Re: How to schedule poweroff with systemd?

For each .timer file, a matching .service file exists (e.g. foo.timer and foo.service). The .timer file activates and controls the .service file. The .service does not require an [Install] section as it is the timer units that are enabled. If necessary, it is possible to control a differently-named unit using the Unit= option in the timer's [Timer] section.

If I am not entirely mistaken, this is the answer you are looking for.

Offline

#3 2018-03-06 11:05:21

r4ptor
Member
Registered: 2012-12-30
Posts: 46

Re: How to schedule poweroff with systemd?

Well yes, you need a a timer file and a service file.
So for the timer you want something like this

# /etc/systemd/system/poweroff.timer
[Unit]
Description=Poweroff maschine at 5 AM Mo-Fri

[Timer]
OnCalendar=Mon..Fri *-*-* 05:00:00
Persistent=true
 
[Install]
WantedBy=timers.target

and create the suiteable service file

# /etc/systemd/system/poweroff.service
[Unit]
Description = Poweroff maschine at 5 AM Mo-Fri

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

Enable the timer with

# systemctl enable /etc/systemd/system/poweroff.timer

Last edited by r4ptor (2018-03-06 11:05:44)

Offline

Board footer

Powered by FluxBB