7

My current configuration uses

kdesu shutdown -[rh] now

to reboot/shut down. The entire shutdown procedure takes about 1-2 seconds. But after every boot Firefox says it was shut down prematurely, very likely indicating that it was brutally murdered rather than laid to rest. How do I configure a "normal" WM shutdown procedure (something like kill -SIGTERM && sleep 10 && kill -SIGKILL, but preferably using an existing tool) in Awesome WM?

Related question for GDM.

3
  • how about running ksmserver and invoking its power off shortcut using dbus?
    – don_aman
    Mar 17, 2023 at 20:46
  • @don_aman Those are certainly words, but I've no idea what they mean. :)
    – l0b0
    Mar 17, 2023 at 20:51
  • actually ignore the dbus part. ksmserver is the kde session management server, which takes care of graceful logouts/shutdown in the kde desktop. what i suggested is running it in your user session so it already adds the kde session management shortcuts, such as ctrl-alt-del or the power button.
    – don_aman
    Mar 17, 2023 at 21:00

2 Answers 2

3
+100

wmctrl may help you (package name wmctrl).

wmctrl helps you interact with a EWMH/NetWM compatible X Window Manager. I'm not sure is AwesomeWM fits this description, but if it does, this answer would work.

$ wmctrl -l
0x0100002d  1 stewbian arch linux - How to reboot/shut down gracefully in Awesome WM? - Unix & Linux Stack Exchange — Mozilla Firefox
0x01200007  0 stewbian ~ : bash — Konsole
$ wmctrl -c 0x01200007

This could be scripted to list all windows (wmctrl -l), iterate over the list, and close each (wmctrl -c). When that is done, then shut down.

#!/bin/bash

wmctrl -l | awk '{ print $1 }' | while read -r windowid; do
  wmctrl -c $windowid
done

shutdown -h now

If that doesn't work, wmctrl can get a PID of the parent process, where you could send a signal (kill) to each PID.

#!/bin/bash
pids=$(wmctrl -lp | awk '{print $3}')
kill -SIGTERM $pids
sleep 2

pids=$(wmctrl -lp | awk '{print $3}')
kill -SIGKILL $pids
sleep 2

shutdown -h now

You could also split this by processes. You could send SIGTERM to windows with Firefox in the titlebar, but SIGINT to instances of QtCreator, then SIGABRT to everything else including Firefox and QtCreator if they still exist.

#!/bin/bash
pids=$(wmctrl -lp | awk '/Firefox/{print $3}')
kill -SIGTERM $pids

pids=$(wmctrl -lp | awk '/Qt Creator/{print $3}')
kill -SIGINT $pids

sleep 10

pids=$(wmctrl -lp | awk '{print $3}')
kill -SIGABRT $pids

shutdown -h now
-2

You probably want to end the session in an orderly manner. This answer over at SuperUser would appear to accomplish that: https://superuser.com/questions/395820/how-to-properly-end-a-kde-session-from-shell-without-root-privileges

3
  • 1
    Not sure how I'm going to achieve that without KDE (the fact I'm using kdesu is irrelevant).
    – l0b0
    Jan 30, 2015 at 16:08
  • That you were using kdesu implied you were using KDE. If you're logging into a GNOME-like session, then you want gnome-session-quit --power-off.
    – ewhac
    Feb 3, 2015 at 21:32
  • 1
    That's a common misunderstanding of Linux software. In Linux it's quite possible to install and use tons of GNOME and KDE software, like GIMP and Kompare, without using either desktop environment. I tagged the question awesome (my WM) and added a link to "Related question for GDM" (since I'm not using that).
    – l0b0
    Feb 4, 2015 at 8:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .