Xfce Forum

Sub domains
 

You are not logged in.

#1 2022-11-12 19:36:22

evg
Member
Registered: 2022-11-12
Posts: 2

How to stop a script started from autoload when the user logs out?

I set the bash script to autoload using the shortcut /home/localuser/.config/autostart/script.desktop
This script runs in the background ( some commands with "&" ).
When the user logs out, the script does not exit.
Instead of the parent xfce4-session, the parent of the script becomes /sbin/init

Is there a way to terminate the script when the user logs out?

OS Debian 11
xfce 4.16

P.S. It seems that when the user logs out, no signals are passed to the script
I used test.desktop shortcut for tests:

[Desktop Entry]
Encoding=UTF-8
Type=Application
Exec=/home/localuser/.config/autostart/test.sh
Terminal=false
Hidden=false
NoDisplay=true
Name=Signal monitoring

and script:

#!/bin/bash

sleep 10000 &
SLEEP_PID=$!

for SIGNAL in {1..64}; do
   trap "echo \$(date --rfc-3339=ns) signal $SIGNAL >> /home/localuser/.config/autostart/test.log" $SIGNAL
done

trap 'kill $(jobs -p)' EXIT

wait $SLEEP_PID;

Last edited by evg (2022-11-12 19:37:26)

Offline

#2 2022-11-12 23:40:38

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 9,524

Re: How to stop a script started from autoload when the user logs out?

Hello and welcome.

There is an open bug report for this. As a workaround, you could set "KillUserProcesses=yes" in /etc/systemd/logind.conf - however note that this will kill all session processes including screen & tmux (if you use those).

Offline

#3 2022-11-13 06:47:52

evg
Member
Registered: 2022-11-12
Posts: 2

Re: How to stop a script started from autoload when the user logs out?

Hello!
Thanks for the quick response.

As an idea for development: In the future, it would be nice if xfce could distinguish
between applications to be terminated and applications to be left running.
For example, for *.desktop shortcuts, add the RemineRunningAfterLogout or KillAfterLogout key.
And for applications launched by the user, xfce would ask when exiting - which applications should be left running, and which should be forcibly terminated.
Of course, everything is optional.

Xfce good system, I wish it further development and all the best

Offline

Board footer

Powered by FluxBB