[systemd-devel] Stop all uninstalled units
gmane at colin.guthr.ie
Wed Jul 17 08:09:47 PDT 2013
'Twas brillig, and Tim Cuthbertson at 17/07/13 13:14 did gyre and gimble:
> Hi Folks,
> I've posted a serverfault question , but it got no answers so I
> thought I'd bring it to the mailing list:
> I have some systemd units installed and running. Let's say I manually
> uninstall foo.service by
> - removing its .service (and .socket) files
> - removing all symlinks (e.g from default.target.wants/)
> I can run systemctl daemon-reload, and then I see:
> # systemctl status foo.service
> Loaded: error (Reason: No such file or directory)
> Active: active (running) since Mon 2013-07-08 13:50:29 EST; 48s ago
> Main PID: 1642 (node)
> So systemd knows that it's not installed, and that it is running. Is
> there some command I can use to stop all running services which no
> longer have a unit file?
> I do not want to have to somehow know what I've uninstalled, or for the
> command to work only in some circumstances - I want something that I can
> run at any point, with no additional knowledge, that will stop all units
> not backed by a unit file.
You should really not uninstall something before stopping it. This is
why all the packaging systems will always be careful to stop things
I'm unsure, but I would have thought systemd would no longer know the
exact sequence of commands to run when stopping the unit without the
unit file to guide it (it depends how much of the original unit was kept
around when doing a daemon-reload, but I would hope it would clean out
pretty much everything).
Likely all that systemd is doing here is killing the processes that
remain in the cgroup rather than any kind of graceful shutdown (but then
sometimes a graceful shutdown would require running binaries that no
longer exist anyway so this is probably a good thing).
> I've currently got a hacky script that:
> - Runs `list-units` to get all unit names
> - Then `show -p ActiveState -p UnitFileState $unit` on each
> - It then runs `systemctl stop` on each unit with a UnitFileState of ""
> (empty string), and ActiveState of anything but "failed".
> This is almost certainly missing some edge case, as I couldn't really
> find any documentation of these properties, it just seemed to be what
> occurred with the examples I encountered.
> I'm hoping there's a better way, can anyone point me in the right direction?
To be honest, if this is something you encounter so often that you need
to have a script for it, I would suggest "you're doing it wrong" ;)
The units should be shipped in the same package as the service binary so
the units should only really be removed when the service's package is
removed and it should be the job of the packaging system to ensure the
service is stopped before it the files relating to that package are
Maybe I'm missing the reason things end up in that state so you could
elaborate on how this situation crops up then perhaps people here could
Regardless, of whether or not this is good or bad practice, I think the
principle you described above seems sensible enough.
Tribalogic Limited http://www.tribalogic.net/
Mageia Contributor http://www.mageia.org/
PulseAudio Hacker http://www.pulseaudio.org/
Trac Hacker http://trac.edgewall.org/
More information about the systemd-devel