Nohup does not work in scripts started by KDE autostart

I have a main startup script that is started by the KDE autostart. It starts other scripts with nohup so that they continue running when the main startup script has finished. Anyhow the scripts stop when the main startup script finishes.
Starting the main startup script manually from a console works fine - the other scripts continue when the main script finishes.

This happens with Leap 15.5 (plasma 5.27.4, KDE framworks 5.103.0, Qt 5.15.8, X11).
It works fine (other scripts continue) with Leap 15.2 (plasma 5.18.5, KDE frameworks 5.71.0, QT 5.12.7, X11).

Why is the subscript started with nohup closed when the main script finishes?


Here are the scripts:

SCRIPTFILE=`readlink -f $0`
# change to the script directory 
cd `dirname $SCRIPTFILE`

# start subscript which should run even when this script finshes
nohup ./ > /dev/null 2>&1 &

# wait some time - while this script is running is also running
sleep 60
# the script ends now -> stops also although nohup was used?!



sleep 300


[Desktop Entry]

nohup makes no sense in this case. It detaches program from controlling tty, but startup scripts are not interactive and do not have associated tty anyway.

My best guess is that KDE in Leap 15.5 is using systemd for session management and converts KDE autostart into systemd units. It should be available since 5.21, not sure when it became the default.

As a quick check you may try to disable systemd

kwriteconfig5 --file startkderc --group General --key systemdBoot false

Plasma and the systemd startup – David Edmundson’s Web Log

If it works with traditional session management, we can try to find out how to do it using new and shiny systemd.

Thanks arvidjaar!

After disabling systemdBoot it works. The subscript remains running when the mainscript exits.

How can I realize this with systemd?

systemd considers service stopped when the main process exits and by default kills all remaining processes that are part of this service. It was fixed in systemd v250 (by making generated services to remain active as long as some process still runs), but Leap 15.5 has v249. It is possible to work around it by setting KillMode property via drop-in. Something like

bor@leap15:~> mkdir -p .config/systemd/user/
bor@leap15:~> cat > .config/systemd/user/ << \EOF
> [Service]
> KillMode=none

Which results in

bor@leap15:~> systemctl --user --no-pager -l status 
○ -
     Loaded: loaded (/home/bor/.config/autostart/; generated)
    Drop-In: /home/bor/.config/systemd/user/
     Active: inactive (dead) since Thu 2023-08-17 21:28:11 MSK; 59s ago
       Docs: man:systemd-xdg-autostart-generator(8)
    Process: 4163 ExecStart=/home/bor/ (code=exited, status=0/SUCCESS)
   Main PID: 4163 (code=exited, status=0/SUCCESS)
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/
             ├─ 4170 /bin/bash ./
             └─ 4172 sleep 100000000000

See man systemd.kill for description of KillMode.

Thanks for the very helpful explanations!!