Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Detecting intervals of inactivity in the tty/fbterm?

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
rlue
Posts: 13
Joined: 2017-10-30 02:04

Detecting intervals of inactivity in the tty/fbterm?

#1 Post by rlue »

"setterm --blank n" allows me to configure the virtual terminal to automatically shut the display off after n minutes of inactivity. Unfortunately, I spend all my time in fbterm, where setterm does not apply.

I've found that I can manually shut the display off with

Code: Select all

$ sudo sh -c 'echo 1 > /sys/devices/pci0000\:00/0000\:00\:10.0/0000\:02\:00.0/graphics/fb0/blank'
(and echo 0 to restore it).

Is there any way to detect periods of inactivity in the tty/fbterm, so that I can create a script to simulate a setterm --blank setting? Ideally, a solution would do the following things:
  • 1. not require manual password entry (i.e., for sudo)
    2. automatically trigger the display to shut off after n minutes
    3. automatically restore the display when any key is pressed
    4. automatically restore the display when resuming from suspend (e.g., if the system enters suspend mode after the script has triggered the display to shut off).
Better yet, is there a more native way to simulate "setterm --blank" in fbterm?

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: Detecting intervals of inactivity in the tty/fbterm?

#2 Post by debiman »

systemd has these things built in.
look at /etc/systemd/logind.conf, all the Idle... options.

rlue
Posts: 13
Joined: 2017-10-30 02:04

Re: Detecting intervals of inactivity in the tty/fbterm?

#3 Post by rlue »

This is a good start, but unfortunately, logind.conf only supports the following IdleActions:
  • • ignore
    • poweroff
    • reboot
    • halt
    • kexec
    • suspend
    • hibernate
    • hybrid-sleep
    • lock
"suspend" turns the display off, but I'd like to be able to set different intervals for display-off and suspend. "lock" doesn't seem to work at all. I'm not sure if it refers to the session-locking features of desktop environments, but I installed vlock, but even when invoked manually, it doesn't shut the display off.

Would anyone happen to know if systemd provides events for user (in)activity? I'd be happy to write my own scripts for this purpose, provided it's possible, but I haven't been able to find much on my own yet.

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: Detecting intervals of inactivity in the tty/fbterm?

#4 Post by debiman »

rlue wrote:Would anyone happen to know if systemd provides events for user (in)activity?
isn't that what IdleAction=... offers?
afaiu one can assign various actions. my guess is you could create your own service that would execute various commands depending on various other factors (besides idle time).

have you read

Code: Select all

man logind.conf
???

rlue
Posts: 13
Joined: 2017-10-30 02:04

Re: Detecting intervals of inactivity in the tty/fbterm?

#5 Post by rlue »

To clarify, when I say "provides events for user (in)activity", I mean "can a systemd service specify something like 'Before=idle.target' the way it can specify 'Before=sleep.target'?"

I have indeed read "man logind.conf" — this is what it says about IdleAction:
IdleAction=
Configures the action to take when the system is idle. Takes one of "ignore", "poweroff", "reboot", "halt", "kexec", "suspend", "hibernate", "hybrid-sleep", and "lock". Defaults to "ignore".

Note that this requires that user sessions correctly report the idle status to the system. The system will execute the action after all sessions report that they are idle, no idle inhibitor lock is active, and subsequently, the time configured with IdleActionSec= (see below) has expired.
Rather than supplying an event signal for a custom service to respond to, it initiates a specific event from a predefined set. I don't see any indication of the ability to specify custom actions. (In any case, I'd also like to reserve the option to use IdleAction to suspend the system — the scheme I have in mind is: display off after 2 minutes, suspend after 10 minutes.)

Hopefully I've misread something?

User avatar
pylkko
Posts: 1802
Joined: 2014-11-06 19:02

Re: Detecting intervals of inactivity in the tty/fbterm?

#6 Post by pylkko »

I don't know the answer but am also interested in knowing how to do this.

The man page of logind.conf says that systemd runs everything you put in /usr/lib/systemd/system-sleep/ before sleep, so first I was thinking that perhaps this could be used by setting IdleAction to ignore. That perhaps it then nevertheless reaches sleep.target or some other similar state and then you could hook your script to switch off the display at that target. However, I believe that this might not be the case, the ignore might just not do anything at all even if you set IdleActionSec to some amount of time.

Yet another idea would be to modify the exist sleep so that it does not actually do anything, but that it enters the target state and then perform stuff in that target only. This can be done in systemd-sleep.conf (see man)

Then I started thinking that perhaps you could jus make your own target to reach at some time of idle, set a timer and bind your script to the target. However, I wonder if you would be able to turn the screen on anymore, and how this could be done exactly?

Because as I undertand it, the standard sleep is set up so that you can put a script in /usr/lib/systemd/system-sleep/ and have it do stuff before and after reaching sleep.target. And you could make simple shell script to turn off screen and turn on screen. The only problem is that it would then do these btasks before either suspend, hibernate or other such state that you do not want. If state ignore does nothing but still executes the content nof that folder, then that would be really easy. However, it might not, hard to say, the manpage does not say. It says, however, that this is
the default behavior. One would assume that the only sensible thing to make default would be "do nothing", in this case.

The manpage of systemd-sleep(8) says that
systemd-suspend.service is a system service that is pulled in by suspend.target and is responsible for the actual system suspend
That sounds like that when normally you have idle time, then when it passes what you mark in logind.conf as the threshold for idle time, this triggers the IdleAction, and if it is sleep, then you enter suspend.target, possible additional scripts are run and then systemd-suspend.service is run to go to sleep. But what if you made suspend.service into an empty service? Most likely you could then use the pre/post scripts and reach suspension without suspending the system. That kind of hackish and would probably result in suspend no longer working normally, so would
be a dumb idea if you need suspend also.

EDIT: a third option that I came up with is that since systemd can monitor file and path states, that perhaps a service that monitors /dev/input/yourkeyboard could be used with a time, so that if no change for 10 min, then shut off monitor.

User avatar
ralph.ronnquist
Posts: 342
Joined: 2015-12-19 01:07
Location: Melbourne, Australia
Been thanked: 6 times

Re: Detecting intervals of inactivity in the tty/fbterm?

#7 Post by ralph.ronnquist »

One could of course use xautolock instead.

User avatar
pylkko
Posts: 1802
Joined: 2014-11-06 19:02

Re: Detecting intervals of inactivity in the tty/fbterm?

#8 Post by pylkko »

ralph.ronnquist wrote:One could of course use xautolock instead.
Do you know if that works on all kinds of minimal machines. It does not seem to require X. But on the machines that I am interested in this (I don't know about OP) there would be no x server and at times only a serial console.

User avatar
ralph.ronnquist
Posts: 342
Joined: 2015-12-19 01:07
Location: Melbourne, Australia
Been thanked: 6 times

Re: Detecting intervals of inactivity in the tty/fbterm?

#9 Post by ralph.ronnquist »

It requires some X libraries, but doesn't need X running, I believe. The following is from a barebone, minimal VM (Devuan ASCII)

Code: Select all

# apt-get -s install xautolock
The following additional packages will be installed:
  libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxss1 x11-common
Recommended packages:
  xtrlock | xscreensaver | i3lock | suckless-tools
Notably it doesn;t pull in any xserver-* packages.

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: Detecting intervals of inactivity in the tty/fbterm?

#10 Post by debiman »

^ i don't think any x-app will work without an X-session. but worth a try i guess...
rlue wrote:Rather than supplying an event signal for a custom service to respond to, it initiates a specific event from a predefined set.
i think you're right there. sorry.

however:
IdleAction=

Note that this requires that user sessions correctly report the idle status to the system.
this might warrant further investigation.
i know it works on my system (i.e. the session does report these things correctly)
so, how does it do that?
the scheme I have in mind is: display off after 2 minutes, suspend after 10 minutes.
that bit is easily achieved with a custom script that sleeps for 8 minutes.

i know, we have to get to the "custom" first.

in addition to debian resources, i recommend wiki.archlinux.org.

rlue
Posts: 13
Joined: 2017-10-30 02:04

Re: Detecting intervals of inactivity in the tty/fbterm?

#11 Post by rlue »

^ i don't think any x-app will work without an X-session. but worth a try i guess...
Yep, in tty, xautolock just spits out "Couldn't connect to" and then exits.
i know it works on my system (i.e. the session does report these things correctly)
so, how does it do that?
Yep, it does on my system, too. I think I don't possess enough knowledge about the system to do what I'm after, though. For instance, it doesn't just need to set the value of the /sys/.../blank file; it needs to detect user input as well to wake when the user resume activity. That means it needs to launch in the foreground no matter what other processes are open or on the screen (e.g., if vim is open in a tmux session, it would have to know which pane I'm in, background vim, and launch in the foreground over it).

My search continues, but I fear home-rolled options are bound to involve more surprises than I'm ready for.

User avatar
pylkko
Posts: 1802
Joined: 2014-11-06 19:02

Re: Detecting intervals of inactivity in the tty/fbterm?

#12 Post by pylkko »

By the way, you said that setterm does not work in the fbterm. But did you try setting the kernel boot parameter before userspace, that is by using consoleblank=Y as a boot parameter?
see: http://lkml.iu.edu/hypermail/linux/kern ... 00784.html
You give the time in seconds, as you wanted 10 min, you would use 600

Given that you can echo the /sys file, one would expect that to work?

rlue
Posts: 13
Joined: 2017-10-30 02:04

Re: Detecting intervals of inactivity in the tty/fbterm?

#13 Post by rlue »

Good idea, @pylkko. Unfortunately, the kernel option doesn't seem to persist beyond login. Once I log in, even at the regular tty, it goes back to whatever my setterm --blank setting is. Definitely doesn't work in fbterm.

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: Detecting intervals of inactivity in the tty/fbterm?

#14 Post by debiman »

rlue wrote:
IdleAction=
Note that this requires that user sessions correctly report the idle status to the system.
i'd like to get back to this one more time.
i wonder what the man page thinks what the user session generally is?
a program i guess.
i think it's agetty or getty or some such, not sure though.
agetty's man page tells me that it's /bin/login, though.
dig deep.

User avatar
pylkko
Posts: 1802
Joined: 2014-11-06 19:02

Re: Detecting intervals of inactivity in the tty/fbterm?

#15 Post by pylkko »

Out of curiosity, what happens if you direct the setterm command to the device, that is:

Code: Select all

setterm --blank n > /dev/fbX 

Post Reply