Detecting intervals of inactivity in the tty/fbterm?

If none of the more specific forums is the right place to ask

Detecting intervals of inactivity in the tty/fbterm?

Postby rlue » 2017-10-30 02:38

"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?
rlue
 
Posts: 13
Joined: 2017-10-30 02:04

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

Postby debiman » 2017-10-31 06:19

systemd has these things built in.
look at /etc/systemd/logind.conf, all the Idle... options.
User avatar
debiman
 
Posts: 1519
Joined: 2013-03-12 07:18

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

Postby rlue » 2017-10-31 07:44

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.
rlue
 
Posts: 13
Joined: 2017-10-30 02:04

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

Postby debiman » 2017-10-31 19:10

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
???
User avatar
debiman
 
Posts: 1519
Joined: 2013-03-12 07:18

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

Postby rlue » 2017-11-01 02:11

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?
rlue
 
Posts: 13
Joined: 2017-10-30 02:04

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

Postby pylkko » 2017-11-01 09:28

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
pylkko
 
Posts: 1174
Joined: 2014-11-06 19:02

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

Postby ralph.ronnquist » 2017-11-01 11:14

One could of course use xautolock instead.
User avatar
ralph.ronnquist
 
Posts: 308
Joined: 2015-12-19 01:07
Location: Melbourne, Australia

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

Postby pylkko » 2017-11-01 13:50

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
pylkko
 
Posts: 1174
Joined: 2014-11-06 19:02

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

Postby ralph.ronnquist » 2017-11-01 19:20

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
ralph.ronnquist
 
Posts: 308
Joined: 2015-12-19 01:07
Location: Melbourne, Australia

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

Postby debiman » 2017-11-02 05:31

^ 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.
User avatar
debiman
 
Posts: 1519
Joined: 2013-03-12 07:18

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

Postby rlue » 2017-11-02 13:43

^ 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.
rlue
 
Posts: 13
Joined: 2017-10-30 02:04

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

Postby pylkko » 2017-11-02 18:51

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?
User avatar
pylkko
 
Posts: 1174
Joined: 2014-11-06 19:02

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

Postby rlue » 2017-11-03 00:05

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.
rlue
 
Posts: 13
Joined: 2017-10-30 02:04

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

Postby debiman » 2017-11-03 05:24

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
debiman
 
Posts: 1519
Joined: 2013-03-12 07:18

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

Postby pylkko » 2017-11-03 08:52

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

Code: Select all
setterm --blank n > /dev/fbX
User avatar
pylkko
 
Posts: 1174
Joined: 2014-11-06 19:02


Return to General Questions

Who is online

Users browsing this forum: calkekecal and 5 guests

fashionable