Auto-Restart a Crashed X Session

Configurare noua (How To)

Situatie

You’re running a minimalist Linux setup using a window manager like i3, Openbox, or bspwm, and sometimes your X session crashes — maybe due to a misbehaving compositor or GPU hiccup. Instead of rebooting your whole machine, you’d like your session to automatically restart with minimal disruption.

Solutie

Solution Overview:

Use a systemd user-level service to monitor and automatically restart your X session via startx or a custom startup script.

Steps:

  1. Create a systemd user service:

mkdir -p ~/.config/systemd/user
nano ~/.config/systemd/user/xsession-watch.service

Paste this:

[Unit]
Description=Auto-restart X session on crash
After=graphical.target
[Service]
ExecStart=/usr/local/bin/startx
Restart=always
RestartSec=3
Environment=DISPLAY=:0
Environment=XDG_SESSION_TYPE=x11

[Install]
WantedBy=default.target

  1. Ensure your .xinitrc is properly set up:

nano ~/.xinitrc

Add your window manager or desktop environment launcher, e.g.:

exec i3
  1. Enable and start the user service:

systemctl --user enable xsession-watch
systemctl --user start xsession-watch
  1. Enable lingering so it works even after logout:

sudo loginctl enable-linger $USER

Benefits:

  • You no longer need to reboot your whole system after an X crash

  • Great for minimal or headless setups with a monitor attached

  • Keeps your setup resilient even without a full display manager like GDM or LightDM.

Tip solutie

Permanent

Voteaza

(4 din 7 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?