[systemd-devel] Unload disabled units

Andrei Borzenkov arvidjaar at gmail.com
Thu Nov 21 13:32:21 UTC 2019


15.09.2019 6:12, Daniel Duong пишет:
> Hi,
> 
> I have a 2 template units: 1 for a service and 1 for a socket. Each
> instance is a version of my web application.
> 
> After a successful deploy, I stop and disable the old version and I
> enable the new one:
> 	systemctl start belleshop at 0.2.socket
> 	# Test that everything is fine
> 	systemctl enable belleshop at 0.2.socket
> 	systemctl stop belleshop at 0.1.socket
> 	systemctl stop belleshop at 0.1.service
> 	systemctl disable belleshop at 0.1.socket
> 
> I've done that for a few versions now, and it seemed to work OK. There
> is a little problem though. The old versions are still loaded:
> 
> 	$ systemctl --no-legend --all list-units belleshop@*
> 	belleshop at 0.110.service loaded active   running Belleshop server
> 	belleshop at 0.34.service  loaded inactive dead    Belleshop server
> 	belleshop at 0.36.service  loaded inactive dead    Belleshop server
> 	belleshop at 0.37.service  loaded inactive dead    Belleshop server
> 	[...]
> 	belleshop at 0.110.socket  loaded active   running Belleshop socket
> 	belleshop at 0.34.socket   loaded inactive dead    Belleshop socket
> 	belleshop at 0.36.socket   loaded inactive dead    Belleshop socket
> 	belleshop at 0.37.socket   loaded inactive dead    Belleshop socket
> 	[...]
> 
> Is there any way I can unload these old versions?
> 
> Here are my unit files:
> 
> belleshop at .service:
> 	[Unit]
> 	Description=Belleshop server
> 	Requires=belleshop@%i.socket
> 	After=network.target
> 
> 	[Service]
> 	User=belleshop
> 	Group=belleshop
> 	ExecStart=/opt/belleshop/bin/belleshop-%i.pyz server --bind unix:/run/belleshop/belleshop-%i.sock
> 	ConfigurationDirectory=opt/belleshop/
> 	StateDirectory=belleshop
> 	CacheDirectory=belleshop
> 	RuntimeDirectory=belleshop
> 	Environment="SHIV_ROOT=/var/cache/belleshop"
> 	RuntimeDirectoryPreserve=yes
> 	StandardOutput=journal
> 	StandardError=inherit
> 
> 	[Install]
> 	WantedBy=multi-user.target
> 

This pins all service units

> belleshop at .socket:
> 	[Unit]
> 	Description=Belleshop socket
> 
> 	[Socket]
> 	ListenStream=/run/belleshop/belleshop-%i.sock
> 
> 	[Install]
> 	WantedBy=sockets.target
> 


And this pins all socket units.

Units are not unloaded if they are part of dependency chain, and here
units are Wanted by another unit(s).

I am not sure if reloading systemd will help here. It preserves current
state across reload so it comes up with the same dependencies. There is
really no way to tell systemd that this unit no more exists. It was
never designed for such dynamic reconfiguration.


More information about the systemd-devel mailing list