I am writing a bash script and am checking whether the application is running. If it is not running it should be started in a separate process (not a child process). If it is running, the window should be maximized. I kind of made it but the new process terminates shortly after being started, probably because the script process ends. When I don't run it in background via &, the app doesn't close, but then I can't run the script a second time to maxmize the app.
#!/bin/bash
if pgrep app
then
echo app is running
# Maximize the app
wmctrl -x -r WMClassOfapp -b "add,maximized_vert,maximized_horz"
else
echo app is not running
/usr/bin/app
fi
When I execute it in a terminal, it works fine. When I call it from the udev rule, the app terminates. Using nohup yields the same outcome. Here is the udev rule
ACTION=="add" \
, KERNEL=="hci0:3585" \
, SUBSYSTEM=="bluetooth" \
, ENV{DISPLAY}=":0" \
, ENV{HOME}="/home/user"
, RUN+="/home/user/runapp"
udevrule you used to start the service?systemdapproach? Note that theoneshottype should be used withRemainAfterExit=true, otherwise it will never reach theactivestate, but directly transition todead. The problem with starting a script fromudevis thatudevis now part ofsystemdanyway, and running a script from audevrule may block processing of furtherudevevents.systemdon the other hand mercilessly kills all processes and sub-processes started by a service when that service has ended ...RemainAfterExit=truebut the same happens. So when udev is a part of systemd anyway, I should not need systemd. I just want to start this app and keep it running. Like I said, it works when I don't run it in background in the script, but it needs to start in a separate process. Else I can't call the script a second time and maximize the app.runAppin yourExecStartline a typo? In yourudevrule it wasrunappin all-lowercase ...