You are not logged in.

#1 2016-01-15 15:54:22

Eisfreak7
Member
Registered: 2016-01-14
Posts: 3

systemd oneshot service disown process

Hi
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?

Offline

#2 2016-01-15 15:58:26

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,006
Website

Re: systemd oneshot service disown process

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).


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#3 2016-01-15 16:30:38

Eisfreak7
Member
Registered: 2016-01-14
Posts: 3

Re: systemd oneshot service disown process

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.

Offline

#4 2016-01-15 16:56:27

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,006
Website

Re: systemd oneshot service disown process

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.


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#5 2016-01-15 17:25:15

branch
Member
Registered: 2014-03-16
Posts: 196

Re: systemd oneshot service disown process

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.

OR

b. Set type=simple and launch bspwmrc with exec so that it takes over the main process instead of forking.

Offline

#6 2016-01-16 00:19:57

Eisfreak7
Member
Registered: 2016-01-14
Posts: 3

Re: systemd oneshot service disown process

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.

Offline

Board footer

Powered by FluxBB