I'm trying to write a service that updates my monitor-setup when I resume from standby.
The script I wrote for updating the setup works.
Calling it with `monitor-hotplug.sh; exit` also works.
But when it is called from a systemd oneshot service with `systemctl start monitor-hotplug-resume.service` it apparently fails to disown the process of the panel (lemonbar is restarted as part of the monitor configuration).
That means the panel is started but immediately killed as the script exits. When I insert `sleep 3s` at the end of the script the panel appears for 3s and then disappears.
As I said, that does not happen when calling the script from a terminal and then exiting the terminal.
Here`s the script I use:
#!/bin/bash . /home/eisfreak7/bin/active-xsession export USER="$active_user" sudo --user "$active_user" --set-home --login --non-interactive --preserve-env /home/eisfreak7/.config/bspwm/bspwmrc & disown # sleep 3s wait
The `active-xsession` script simply finds the current x-user and display variable. That works (as I said, inserting sleep 3s makes the panel show up for 3s).
The panel is called from withing the bspwmrc.
Any ideas how to fix this?
Either use a different Type for the service (systemd is supposed to clean up OneShot zombie processes), or use setsid when launching the process you want to stick around (I think this should work).
Unfortunately, both solutions dont work.
Calling 'setsid sudo ...' in the script doesnt change anything (and calling the panel itself with setsid doesnt help either) and removing the `type=oneshot` line also doesnt change anything.
I was thinking oneshot would be the correct type of service since I want this to be executed once every time I return from standby, not just the first time I do so.
Thank you for the fast reply.
In hindsight I think you are right about type oneshot. Sorry, I was thinking of another type. Unfortunately that's the only idea I had.
I still think Trilby was on the right track. Removing type=oneshot implies type=simple which means the called process should persist, but your process forks to launch bspwmrc and then terminates. Using disown does not work here because systemd tracks processes with cgroups.
I think this should be one of the following:
a. Set type=forking and use your script as is, allowing forked processes to persist after the main process terminates.
b. Set type=simple and launch bspwmrc with exec so that it takes over the main process instead of forking.
Thank you both.
Setting type=forking works. Learned something about systemd again.
It only works if I keep the 'sleep 1s' at the end of the script though, because apparently the 'wait' doesnt do it. Thats not pretty, but I guess it'll do it for a script.