The officially official Devuan Forum!

You are not logged in.

#1 2022-11-21 15:18:25

GNUser
Member
Registered: 2017-03-16
Posts: 561  

[SOLVED] shell script to restart Xorg

Hello, Devuan friends. I'm on Devuan Chimaera x86_64 with SysVinit, lightdm, Xorg 7.7, and MATE. I'm trying to write a shell script that restarts Xorg. Let's call it RestartX.sh

I already tried several variations of this:

#!/bin/sh
sudo service lightdm stop
sleep 1
sudo service lightdm start

I also tried:

#/bin/sh
sudo chvt 1
sudo pkill -f lightdm
sleep 1
sudo service lightdm start

And I also tried:

#!/bin/sh
sudo pkill Xorg
sleep 1
startx

I run the script in a terminal emulator like so: $ ./RestartX.sh & exit
X seems easy to stop but difficult to start from a shell script. Any ideas on how to make it work?

Last edited by GNUser (2022-11-21 15:20:33)

Offline

#2 2022-11-21 15:42:26

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] shell script to restart Xorg

Restarting X would only really work with autologin. Otherwise killing X also kills the login session so the user would have to log in again afterwards.

If you set up autologin for your user (preferably without LightDM because it's really not needed at all for that configuration) then killing X should do what you want.

And I have to ask: why do you think you have to restart X? What is the actual problem you are attempting to solve here?

Last edited by Head_on_a_Stick (2022-11-21 15:43:04)


Brianna Ghey — Rest In Power

Offline

#3 2022-11-21 15:56:49

GNUser
Member
Registered: 2017-03-16
Posts: 561  

Re: [SOLVED] shell script to restart Xorg

I do have autologin enabled for my user, with this in /etc/lightdm/lightdm.conf:

[SeatDefaults]
autologin-user=bruno
autologin-user-timeout=0

I'd rather not ditch lightdm, since I would have to reconfigure multiple machines.

There's no actual problem. A few years ago, Xorg disabled Control+Alt+Backspace as the keyboard shortcut for restarting X (supposedly for security reasons). I liked having that shortcut because it was useful for the rare instances when X would freeze. If X acts up, I'd rather simply restart it than doing a full reboot. So the goal is to bring back that functionality by creating a script that works as intended, then binding it to Control+Alt+Backspace.

Wanting to get this script to work is mostly an exercise in getting my computer to do what I want it to do.

Last edited by GNUser (2022-11-21 16:03:31)

Offline

#4 2022-11-21 16:06:55

GNUser
Member
Registered: 2017-03-16
Posts: 561  

Re: [SOLVED] shell script to restart Xorg

Head_on_a_Stick wrote:

If you set up autologin for your user ... then killing X should do what you want.

If I run sudo pkill Xorg, then lightdm presents me with a login screen. This is unexpected, since lightdm is configured for autologin and does, in fact, automatically log me at every boot.

Can you help me configure lightdm so that it also automatically logs me in when Xorg is killed?

Last edited by GNUser (2022-11-21 16:10:55)

Offline

#5 2022-11-21 16:19:45

GNUser
Member
Registered: 2017-03-16
Posts: 561  

Re: [SOLVED] shell script to restart Xorg

I figured it out. I just needed to add a line to /etc/lightdm/lightdm.conf. Now instead of just this in the relevant section:

[SeatDefaults]
autologin-user=bruno
autologin-user-timeout=0

I have this:

[SeatDefaults]
autologin-user=bruno
autologin-user-timeout=0
session-cleanup-script=service lightdm restart

With that added line, now all I need to restart Xorg is sudo pkill Xorg. Thanks for pointing me in the right direction, HoaS!

Last edited by GNUser (2022-11-21 16:58:41)

Offline

#6 2022-11-21 17:01:18

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] shell script to restart Xorg

GNUser wrote:

A few years ago, Xorg disabled Control+Alt+Backspace as the keyboard shortcut for restarting X (supposedly for security reasons). I liked having that shortcut because it was useful for the rare instances when X would freeze.

Either apply the DontZap option in an Xorg configuration file snippet to restore the old behaviour or use the <AltGr>-<SysReq>-K combination instead. See also https://www.debian.org/doc/manuals/secu … rq.en.html & https://xyproblem.info/.


Brianna Ghey — Rest In Power

Offline

#7 2022-11-21 17:09:55

GNUser
Member
Registered: 2017-03-16
Posts: 561  

Re: [SOLVED] shell script to restart Xorg

I am familiar with the XY Problem, thank you. Not the case here, as the goal was to reimplement the old behavior with a shell script (or a simple shell command, as it turned out), not by tweaking Xorg config files. I love shell scripts and actually quite dislike Xorg, which I tolerate only out of necessity.

I use sxhkd for keyboard hotkeys. Binding sudo pkill Xorg to control + alt + BackSpace does exactly what I was looking for. Thanks again for the help.

Last edited by GNUser (2022-11-21 17:10:15)

Offline

#8 2022-11-21 17:14:35

GNUser
Member
Registered: 2017-03-16
Posts: 561  

Re: [SOLVED] shell script to restart Xorg

Rant: Did you actually read this?

Option "DontZap" "boolean"
This disallows the use of the Terminate_Server XKB action (usually on Ctrl+Alt+Backspace, depending on XKB options). This action is normally used to terminate the Xorg server. When this option is enabled, the action has no effect. Default: off.

This illustrates exactly what I dislike about Xorg. Everything is overly complicated. This is not a human-friendly description. The header says the DontZap option is boolean, so expected default values would be "true" or "false", not "off" (what exactly is off?).

But all's well that ends well. Thanks to lightdm and sxhkd I don't have to deal with this smile

Last edited by GNUser (2022-11-21 17:43:35)

Offline

#9 2022-11-21 17:29:54

chris2be8
Member
Registered: 2018-08-11
Posts: 264  

Re: [SOLVED] shell script to restart Xorg

On one system I resorted to ctrl-alt-F3 and logging on as root, ready to restart the desktop if it hung (I think the system has hardware problems that cause the desktop to lock up intermittently). So if the desktop suddenly hangs I just press ctrl-alt-F3 and restart it, even if it's ignoring the keyboard. And if that fails I can reboot the system as a last resort.

Offline

#10 2022-11-22 17:21:02

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] shell script to restart Xorg

GNUser wrote:

The header says the DontZap option is boolean, so expected default values would be "true" or "false", not "off"

man xorg.conf wrote:
Boolean options may optionally have a value specified. When no value is specified, the option's value is TRUE. The following boolean option values are recognised as TRUE:

1, on, true, yes

and the following boolean option values are recognised as FALSE:

0, off, false, no

If an option name is prefixed with "No", then the option value is negated.

Example: the following option entries are equivalent:

Option "Accel"   "Off"
Option "NoAccel"
Option "NoAccel" "On"
Option "Accel"   "false"
Option "Accel"   "no"

tongue

GNUser wrote:

Thanks to lightdm and sxhkd I don't have to deal with this

LightDM is awful. Are you really comfortable with X running under the root user?


Brianna Ghey — Rest In Power

Offline

Board footer