#Prevent pacman hook from waiting for subprocess to exit

48 messages · Page 1 of 1 (latest)

eternal urchin
#

I have a custom system updater package for arch, which sometimes needs to install/remove packages from the system itself. Due to it being impossible to install/remove packages from a pacman hook, the packages starts a systemd service that waits for pacman to finish before installing the packages.
Here is the issue. The pacman hook starts the systemd service (with systemctl start eupnea-update.service) in a subthread (specifically with subprocess.Popen in python), but for some reason pacman keeps waiting for this subprocess, instead of just exiting like it normally would. I know this because if I kill that systemd service (which is waiting in a loop for pacman to finish) pacman immediately finishes (successfully).
-> This means pacman somehow keeps track of all subprocesses created by the hook. How can I spawn a new process without pacmans hook knowing about it? Is there a way to disable pacman waiting for subprocesses of a hook?

wary dagger
#

If I have to guess, I'd say that eupnea-update.service has declared an incorrect Type.

#

See man systemd.service

eternal urchin
#

Thing is, the exact same setup works with apt

wary dagger
#

Yeah looks like my guess is correct. You can't use Type = oneshot for this.

#
           •   Behavior of oneshot is similar to simple; however, the service manager will consider the
               unit up after the main process exits. It will then start follow-up units.
               RemainAfterExit= is particularly useful for this type of service.  Type=oneshot is the
               implied default if neither Type= nor ExecStart= are specified. Note that if this option
               is used without RemainAfterExit= the service will never enter "active" unit state, but
               directly transition from "activating" to "deactivating" or "dead" since no process is
               configured that shall run continuously. In particular this means that after a service of
               this type ran (and which has RemainAfterExit= not set) it will not show up as started
               afterwards, but as dead.
#

This is from man systemd.service

#

If Type = oneshot, systemctl start will only exit after the service's binary exits. And in this case your service is stalled waiting on pacman, which makes systemctl start stall, which makes pacman stall. There's your deadlock

#

Try changing it to Type = simple.

#

@eternal urchin

eternal urchin
#

im like 99% sure that I already tried that, but lemme try again

eternal urchin
#

Even just manually running sudo systemctl start eupnea-update.service makes the terminal wait for it

wary dagger
#

Just making sure: you did systemctl daemon-reload after modifying the unit file correct?

eternal urchin
#

yes

#

pretty sure systemd wouldve thrown a warning otherwise

wary dagger
#

So even when you run systemctl start manually, it still hangs your terminal huh

#

Yikes that's weird

eternal urchin
#

yup

#

and it also has a timeout

#

Which just cancelled the script after like 15 secs

#

Wasnt the case with oneshot

wary dagger
#

I mean, I've seen a couple of units do that. Sometimes a systemctl restart just randomly hangs for a while before returning

#

Although I'm pretty sure it's not related to your issues here

eternal urchin
#

nah, this systemctl start eupnea-update just hangs until the service is killed by systemd

#

Coz of timeout

#

starting with sudo systemctl start eupnea-update & works fine btw

#

in terminal

#

or the python equivalent of subprocess.Popen

#

but when run from the hook, pacman waits for that subprocess for some reason

wary dagger
#

If I'm debugging, at this point I would probably suspect the script (modify-packgases) is inadvertently waiting on acquiring a pacman lock or something. Idk just brainstorming

eternal urchin
#

unlikely

#

it works in apt

#

The deb postinst scripts work the same, they start the same script

#

And they also wait for the script to exit

#

But it seems like pacman is keeping track of all subprocesses spawned by the hook

wary dagger
#

Man I don't know then. If you've spent so much time debugging it with the problem right in front of you and can't figure it out, I trust that I probably can't do better across the internet

#

Sorry I guess 🤷‍♂️

#

Also it's too late where I live. Really need to sleep now

eternal urchin
#

ok

#

any idea where I can seek further help?

#

Coz I have made quite a few posts here and this is the first time anyone even responded

wary dagger
#

Yikes I don't know. Maybe try Arch reddit? I think the discoverability is better there

eternal urchin
#

alright

#

thx