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?

Thanks!

Here are the scripts:
/home/willi/mainautostart.sh

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

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

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

/home/willi/subautostart.sh

#!/bin/bash

sleep 300

/home/willi/.config/autostart/mainautostart.sh.desktop

[Desktop Entry]
Comment[en_US]=
Comment=
Exec=/home/willi/mainautostart.sh
GenericName[en_US]=
GenericName=
Icon=dialog-scripts
MimeType=
Name[en_US]=mainautostart.sh
Name=mainautostart.sh
Path=/home/willi
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-KDE-AutostartScript=true
X-KDE-SubstituteUID=false
X-KDE-Username=

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/app-mainautostart.sh@autostart.service.d
bor@leap15:~> cat > .config/systemd/user/app-mainautostart.sh@autostart.service.d/KillMode.conf << \EOF
> [Service]
> KillMode=none
> EOF
bor@leap15:~> 

Which results in

bor@leap15:~> systemctl --user --no-pager -l status app-mainautostart.sh@autostart.service 
○ app-mainautostart.sh@autostart.service - mainautostart.sh
     Loaded: loaded (/home/bor/.config/autostart/mainautostart.sh.desktop; generated)
    Drop-In: /home/bor/.config/systemd/user/app-mainautostart.sh@autostart.service.d
             └─KillMode.conf
     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/mainautostart.sh (code=exited, status=0/SUCCESS)
   Main PID: 4163 (code=exited, status=0/SUCCESS)
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/app-mainautostart.sh@autostart.service
             ├─ 4170 /bin/bash ./subautostart.sh
             └─ 4172 sleep 100000000000
bor@leap15:~> 

See man systemd.kill for description of KillMode.

Thanks for the very helpful explanations!!