You are not logged in.

#1 2023-06-22 20:30:09

zoof
Member
Registered: 2010-02-07
Posts: 33

[Solved] Use systemd to power off system after x minutes

Is it possible to set up a systemd timer to shutdown a computer after a specified period of time?  I found https://bbs.archlinux.org/viewtopic.php … 1#p1772261 which seems related and powers the computer off at a specific time.

Last edited by zoof (2023-06-23 14:32:28)

Offline

#2 2023-06-22 21:02:59

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,484
Website

Re: [Solved] Use systemd to power off system after x minutes

Assuming your session accurately reports idle status, just use logind's IdleAction=poweroff.

EDIT: oops, I misread - my mind inserted an "of idle time" after the title / description.  If you really just want to trigger it after a specific amount of time relative to the timer activation, then yes, just use a timer with OnActiveSec rather than OnCalendar.

Last edited by Trilby (2023-06-22 21:06:31)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2023-06-23 13:38:11

zoof
Member
Registered: 2010-02-07
Posts: 33

Re: [Solved] Use systemd to power off system after x minutes

Thank you!  If I set this up as a user timer, will it start once the target user logs on?  Trying to set automated screen time limits for my son.

Offline

#4 2023-06-23 13:41:52

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,484
Website

Re: [Solved] Use systemd to power off system after x minutes

That use case is explicitly covered clearly near the start of the systemd.timer man page in the table describing the different timer settings that can be used.  Read it.

Last edited by Trilby (2023-06-23 13:42:32)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2023-06-23 14:09:19

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

Re: [Solved] Use systemd to power off system after x minutes

While we're at reading mapages and things…

If I set this up as a user timer, will it start once the target user logs on?  Trying to set automated screen time limits for my son.

Sanity check: have you contemplated how you're gonna prevent the user from disabling the user timer?
(It's possible, given the system is encrypted, so there's effectively no physical access - but you'll have to jump through some hoops)

=> https://wiki.archlinux.org/title/Parental_control

Offline

#6 2023-06-23 14:32:10

zoof
Member
Registered: 2010-02-07
Posts: 33

Re: [Solved] Use systemd to power off system after x minutes

seth wrote:

Sanity check: have you contemplated how you're gonna prevent the user from disabling the user timer?
(It's possible, given the system is encrypted, so there's effectively no physical access - but you'll have to jump through some hoops)

=> https://wiki.archlinux.org/title/Parental_control

Ah,  this seems to be a much better idea although one might think of this as being a computing challenge for my son...  I did get the timer working but I guess for naught.  I'll try out some of the screentime options.

Offline

#7 2023-06-23 15:08:37

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,484
Website

Re: [Solved] Use systemd to power off system after x minutes

There's not much of a challenge even with powering off.  If he is not inclined to accept a proposed time limit, then all he'd have to do is turn the computer back on.  The end result would not be limiting screen time, but quite likely creating resentment as I suspect there could be certain moments in computer / online activities where an abrupt disconnect / poweroff would be received quite poorly and likely cause a lot of backlash.

In contrast, if your son is cooperative with the idea of a time limit, and egg timer next to the computer would do - without the downsides of an abrupt shutdown (e.g., if he's in the middle a writing an message, the timer goes off and he can still send the message and / or say goodbye to any online friends, etc).  This would be much more conducive to maintaining his cooperation.

In any case, if he is not cooperative with the idea of a limit, then there isn't really anything you can do that couldn't readily be undone by someone with physical access to the computer.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2023-06-23 15:21:59

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

Re: [Solved] Use systemd to power off system after x minutes

Hence the encryption condition.
Then you'll have to lockdown the uefi and restrict the boot devices.

Though i principally agree that you should educate your son to use a computer, not use a computer to educate him.

Offline

#9 2023-06-23 15:28:22

zoof
Member
Registered: 2010-02-07
Posts: 33

Re: [Solved] Use systemd to power off system after x minutes

Trilby wrote:

There's not much of a challenge even with powering off.  If he is not inclined to accept a proposed time limit, then all he'd have to do is turn the computer back on.  The end result would not be limiting screen time, but quite likely creating resentment as I suspect there could be certain moments in computer / online activities where an abrupt disconnect / poweroff would be received quite poorly and likely cause a lot of backlash.

He's not likely to be amenable and he gets far too much screen time.  There is a challenge in as far as he does not have the password for his computers, but I take your point about the backlash. The problem is the effort involved in monitoring and enforcing his computer usage limitations.

Trilby wrote:

In contrast, if your son is cooperative with the idea of a time limit, and egg timer next to the computer would do - without the downsides of an abrupt shutdown (e.g., if he's in the middle a writing an message, the timer goes off and he can still send the message and / or say goodbye to any online friends, etc).  This would be much more conducive to maintaining his cooperation.

If only I had cooperative children! wink

Trilby wrote:

In any case, if he is not cooperative with the idea of a limit, then there isn't really anything you can do that couldn't readily be undone by someone with physical access to the computer.

Still, it requires some technical know-how that he currently does not possess.

seth wrote:

Though i principally agree that you should educate your son to use a computer, not use a computer to educate him.

I certainly agree but not necessarily to teach him how to circumvent restrictions.

Offline

Board footer

Powered by FluxBB