Debian 12 Kiosk – Keep Screen Active

Here is a robust way to prevent screen blanking on a Debian 12 kiosk during specific hours (10:00 to 13:00, Monday to Friday) while avoiding persistent configuration changes that could be missed during power cycles. The system also must stay in S0 (fully awake) mode to maintain SSH responsiveness.

Here’s a breakdown of the problem and a solution using systemd timers and xdotool to simulate activity, which is generally a good approach for kiosks:

Understanding Screen Blanking on X11

Screen blanking in X11 environments usually involves a combination of:

  1. X Screen Saver: Controlled by xset s commands.
  2. DPMS (Display Power Management Signaling): Controlled by xset dpms commands, which tells the monitor to enter standby, suspend, or off modes.
  3. Desktop Environment Power Management: In a desktop environment (like GNOME, XFCE, etc.), it will likely have its own power management settings that can override or interact with xset. For a kiosk, it’s often best to disable these entirely if possible.
  4. Kernel Console Blanking: Less common for X11 sessions, but setterm controls this for text consoles. This usually won’t affect an active X session, but it’s good to be aware of.

The key is that an X session goes idle when there’s no keyboard or mouse activity. We need to “trick” it into thinking there’s activity.

The Best Solution: systemd Timers with xdotool

This approach avoids persistent changes to Xorg configuration files or .xinitrc that might be problematic. It uses systemd to schedule actions, which are robust and will apply on boot-up.

1. Install xdotool

xdotool is a command-line tool that can simulate keyboard and mouse input, move and resize windows, etc. It’s perfect for the “artificial activity” requirement.

Bash

sudo apt update
sudo apt install xdotool

2. Create a Script to Simulate Activity

Create a script: /home/kiosk/keep_screen_active.sh:

Bash

#!/bin/bash

# Ensure this script runs as the user running the X session
export XDG_RUNTIME_DIR="/run/user/$(id -u kiosk"
export DISPLAY=:0.0
export XAUTHORITY="/home/kiosk/.Xauthority" # VERIFY THIS PATH 

# Move mouse 1 pixel right, then 1 pixel left
# This resets the X idle timer with minimal visual disruption.
xdotool mousemove_relative --sync 1 0
xdotool mousemove_relative --sync -- -1 0

Important Notes for the Script:

  • kiosk: Crucially, replace kiosk with the actual username that is running the X11 session (DISPLAY=:0.0). xdotool needs to run in the context of the user’s X session.
  • XAUTHORITY: The XAUTHORITY file is essential for xdotool to interact with the X server. The path /home/kiosk/.Xauthority is common. Verify its location by running echo $XAUTHORITY as kiosk when the X session is active.

Make the script executable:

Bash

sudo chmod +x /home/kiosk/keep_screen_active.sh

3. Create a systemd Service Unit

Create a service file, e.g., /etc/systemd/system/keep-screen-active.service:

Ini, TOML

[Unit]
Description=Keep X11 screen active for kiosk

[Service]
Type=oneshot
ExecStart=/home/kiosk/keep_screen_active.sh
User=kiosk
Group=kiosk
Environment="DISPLAY=:0.0"
Environment="XAUTHORITY=/home/kiosk/.Xauthority"
# Ensure the user's graphical session is running
After=display-manager.service graphical.target

Again, replace kiosk with the correct username.

4. Create a systemd Timer Unit

This is where the scheduling logic comes in. Create a timer file, e.g., /etc/systemd/system/keep-screen-active.timer:

Ini, TOML

[Unit]
Description=Run script to keep screen active every minute during specified hours

[Timer]
# Schedule to run every minute between 10:00 and 13:00, Monday to Friday
OnCalendar=Mon..Fri *-*-* 10:00:00..13:00:00
AccuracySec=1s
Persistent=false # This prevents it from running for missed events if system is off

[Install]
WantedBy=timers.target

Explanation of OnCalendar:

  • Mon..Fri: Specifies Monday through Friday.
  • *-*-*: Any day of the month, any month, any year.
  • 10:00:00..13:00:00: Specifies the time range from 10:00:00 to 13:00:00. The timer will trigger every minute within this range.

5. Enable and Start the systemd Timer

Reload systemd and then enable/start your timer:

Bash

sudo systemctl daemon-reload
sudo systemctl enable keep-screen-active.timer
sudo systemctl start keep-screen-active.timer

6. Verify Functionality

  • Check the status of your timer: systemctl status keep-screen-active.timer
  • Check the logs to see if the service is being triggered: journalctl -u keep-screen-active.service
  • During the specified hours, observe your kiosk. The screen should remain active.

Why this is a good solution:

  • No Persistent Manual xset Changes: You don’t need to manually modify xorg.conf or .xinitrc with xset s off or xset -dpms. The xdotool method simply simulates activity, allowing the default X11 power management to be reset, effectively preventing blanking.
  • Robust Scheduling with systemd: systemd timers are designed for reliable scheduling and integrate well with Debian. They will automatically start on boot and manage the execution of your script.
  • Idempotent: The xdotool command is largely idempotent for this purpose. Running it multiple times within a short period won’t cause issues.
  • Minimal Impact: Simulating a single key press every minute is very low overhead.
  • SSH Responsive: Since the system remains in S0, SSH access will be unaffected.

Alternatives and Considerations:

Disabling Screen Blanking Permanently (Less Recommended for this specific use case but good to know):

To ensure the screen never blanks, use xset commands:

Bash

xset s off      # Disable screensaver
xset -dpms      # Disable DPMS (Display Power Management Signaling)
xset s noblank  # Don't blank the video device

These commands would typically be placed in a file that runs when the X session starts, like ~/.xinitrc (if you’re using startx) or an autostart script for the desktop environment (e.g., ~/.config/lxsession/LXDE/autostart for LXDE). For a kiosk, sometimes these can be put directly in the lightdm.conf or equivalent display manager config. However, the requirement for scheduled behavior makes the systemd timer approach better.

caffeine or similar utilities:

Some desktop environments have utilities like caffeine (often a tray icon) that can temporarily disable screen blanking. While convenient, they are typically designed for interactive users and might not be easily scriptable for your precise scheduling needs or reliable in a head-less kiosk setup.

Potential Issues:

  • XAUTHORITY Path: The XAUTHORITY path is critical. If it’s not found, xdotool won’t be able to connect to the X server.
  • Display Manager Differences: For a display manager other than LightDM (e.g., GDM, SDDM), the XAUTHORITY file location might differ. Verify it for the specific setup.
  • User vs. System Timers: Here, a system timer (/etc/systemd/system/) because it’s managed by root and applies globally. If the kiosk user logs in and out frequently, a user-specific systemd --user timer might be considered, but system-wide is generally more robust for a dedicated kiosk.

This systemd timer and xdotool combination provides a clean, scheduled, and non-persistent way to keep your Debian 12 kiosk screen active during your specified hours while maintaining S0 and SSH responsiveness.

WordPress Appliance - Powered by TurnKey Linux