You are not logged in.
Pages: 1
"systemctl list-unit-files --state=enabled" is often used on our forums to determine potential conflicts.
On my system it lacks atleast 2 services.
$ systemctl list-unit-files --state=enabled
UNIT FILE STATE VENDOR PRESET
autovt@.service enabled disabled
getty@.service enabled enabled
nftables.service enabled disabled
ntpd.service enabled disabled
4 unit files listed.
$
$ ls -l /etc/systemd/system/multi-user.target.wants/
total 0
lrwxrwxrwx 1 root root 39 14 jun 2019 dhcpcd@enp4s0.service -> /usr/lib/systemd/system/dhcpcd@.service
lrwxrwxrwx 1 root root 40 18 jun 2019 nftables.service -> /usr/lib/systemd/system/nftables.service
lrwxrwxrwx 1 root root 36 4 dec 2018 ntpd.service -> /usr/lib/systemd/system/ntpd.service
lrwxrwxrwx 1 root root 42 19 jan 14:08 syslog-ng@default.service -> /usr/lib/systemd/system/syslog-ng@.service
$
dhcpcd@enp4s0.service & syslog-ng@default.service are enabled , but not listed in the first output.
Is there a different command that does show everything that is enabled ?
Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
(A works at time B) && (time C > time B ) ≠ (A works at time C)
Offline
systemctl
This isn't right. This isn't even wrong.
-- Wolfgang Pauli --
Offline
I don't ever recommend using the systemctl command on the forums. It doesn't do what some people seem to think it does. I'd only recommend using a find command on /etc/systemd.
dhcpcd is listed in the output of list-unit-files, just not with state=enabled, which is why it's filtered out when you use that flag.
As for whether there is a different command that works, you showed one in your own post: ls (though I prefer find for this).
You could get "better" results with the following:
systemctl list-unit-files --state=indirect,enabled
But is that even really what you want? Isn't the ls or find output exactly what's needed?
Last edited by Trilby (2020-05-30 14:20:34)
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
What state does `systemctl list-unit-files` show for dhcpcd@enp4s0.service and syslog-ng@default.service?
Offline
systemctl output has to much info.
The downside of ls is that the info is scattered over multiple locations, the getty@.service f.e is not in multi-user.target .
A find command would probably be a lot better, but my knowledge of find is very limited.
systemctl list-unit-files
dhcpcd.service disabled disabled
dhcpcd@.service indirect disabled
syslog-ng@.service indirect disabled
systemctl list-unit-files --state=indirect,enabled is better, but has undesired info.
A command that traverses all folders under etc//systemd and lists all .service files found would be great.
If it could skip subdirs without .service files/links it would be even better.
Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
(A works at time B) && (time C > time B ) ≠ (A works at time C)
Offline
I'd only recommend using a find command on /etc/systemd.
I didn't know, thanks.
This isn't right. This isn't even wrong.
-- Wolfgang Pauli --
Offline
find /etc/systemd -name *.service
Would that not do it?
Edit: add -printf "%f\n" for just the filename
Last edited by twelveeighty (2020-05-30 14:46:28)
Offline
It's a big improvement, could that list somehow be used as input for ls -l ?
Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
(A works at time B) && (time C > time B ) ≠ (A works at time C)
Offline
find /etc/systemd/ -name *.service -ls
Like that?
Offline
Then you'd miss the sockets (of course one could have various degrees of find commands to cover for all this)
This reads like a bug in systemctl to me, and why does it work with the getty@ service?
Offline
ls -l /etc/systemd/system/*.wants/*.{service,socket}
?
netctl@ is listed as well.
Edit: just searching the patch would find random files that are not actually enabled (eg. the non-symlink actual netctl@ethernet.service would be placed in /etc/systemd/system/)
Last edited by seth (2020-05-30 14:58:29)
Offline
could that list somehow be used as input for ls -l ?
For what purpose? ls lists files. Find finds and lists of files.
What could ls add to this?
Oh, if you want `ls -l` you could use -exec:
find /etc/systemd -name *.service -exec ls -l '{}' \+
Or just use stat formats to specify only the information you want:
$ find /etc/systemd -name *.service -exec stat -c %N '{}' \+
But using type rather than name may be better:
$ find /etc/systemd -type f -o -type l -exec stat -c %N '{}' \+
Last edited by Trilby (2020-05-30 15:02:17)
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
It could have something to do with the large amount of "states" that systemd uses - if you run "systemctl --state=help", you can a plethora of different states that may or may not get filtered out. Trilby already mentioned "indirect" as a possible exclusion. It could be a bug, of course.
Offline
While trying out the suggestions, I realised find output didn't differrentiate between masked and enabled services, but ls did show that.
find /etc/systemd -name *.service -exec ls -l '{}' \+
This is the most usable output sofar, I don't mind having to change the command to see *.sockets (or conf files)
This reads like a bug in systemctl to me
That thought crossed my mind, but I do tend to be negatively biassed towards systemd.
Edit: using stat instead of ls is even better.
$ find /etc/systemd -name *.service -exec stat -c %N '{}' \+
/etc/systemd/system/getty.target.wants/getty@tty1.service' -> '/usr/lib/systemd/system/getty@.service'
'/etc/systemd/system/systemd-binfmt.service' -> '/dev/null'
'/etc/systemd/system/lvm2-monitor.service' -> '/dev/null'
'/etc/systemd/system/multi-user.target.wants/dhcpcd@enp4s0.service' -> '/usr/lib/systemd/system/dhcpcd@.service'
'/etc/systemd/system/multi-user.target.wants/ntpd.service' -> '/usr/lib/systemd/system/ntpd.service'
'/etc/systemd/system/multi-user.target.wants/syslog-ng@default.service' -> '/usr/lib/systemd/system/syslog-ng@.service'
'/etc/systemd/system/multi-user.target.wants/nftables.service' -> '/usr/lib/systemd/system/nftables.service'
'/etc/systemd/system/default.target' -> '/usr/lib/systemd/system/multi-user.target'
'/etc/systemd/system/lvm2-activation-early.service' -> '/dev/null'
'/etc/systemd/system/lvm2-activation.service' -> '/dev/null'
'/etc/systemd/user/sockets.target.wants/gpg-agent-extra.socket' -> '/usr/lib/systemd/user/gpg-agent-extra.socket'
'/etc/systemd/user/sockets.target.wants/gpg-agent-ssh.socket' -> '/usr/lib/systemd/user/gpg-agent-ssh.socket'
'/etc/systemd/user/sockets.target.wants/gpg-agent.socket' -> '/usr/lib/systemd/user/gpg-agent.socket'
'/etc/systemd/user/sockets.target.wants/dirmngr.socket' -> '/usr/lib/systemd/user/dirmngr.socket'
'/etc/systemd/user/sockets.target.wants/gpg-agent-browser.socket' -> '/usr/lib/systemd/user/gpg-agent-browser.socket'
'/etc/systemd/user/sockets.target.wants/p11-kit-server.socket' -> '/usr/lib/systemd/user/p11-kit-server.socket'
'/etc/systemd/user/default.target.wants/xdg-user-dirs-update.service' -> '/usr/lib/systemd/user/xdg-user-dirs-update.service'
$
Last edited by Lone_Wolf (2020-05-30 15:14:36)
Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
(A works at time B) && (time C > time B ) ≠ (A works at time C)
Offline
Find only links excluding broken symlinks and those pointing to a character special (/dev/null) used to mask the service
find /etc/systemd -type l ! -xtype c ! -xtype l
Edit:
Can be simplified to find only links pointing to regular files.
find /etc/systemd -type l -a -xtype f
Last edited by loqs (2020-05-30 15:18:34)
Offline
Note that -xtype is a non-POSIX gnu add-on for find.
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Is the following POSIX compliant?
find /etc/systemd -type l -exec test -f {} \; -print
Offline
No gnuisms, but I'm not sure what it's supposed to do. The exec clause there is efectively a no-op
EDIT: nevermind - yes that prevents listing of links to /dev/null and broken links.
Last edited by Trilby (2020-05-30 16:40:35)
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
I noticed seth put this to use on a topic that came up today in NC and I couldn't help but add one suggestion to better group/sort the output for lazy/old people like me:
find /etc/systemd -type l -exec test -f {} \; -print | sort
Offline
We can make this arbitrarily complex ;-)
find /etc/systemd -type l -exec test -f {} \; -print | awk -F'/' '{ printf ("%-40s | %s\n", $(NF-0), $(NF-1)) }' | sort -f
Offline
I rather like this:
find /etc/systemd -type l -exec /bin/realpath --relative-base=/usr/lib/systemd '{}' \+ | tr '/' ' ' | column -t
Joking aside, realpath might be simpler than the -exec test and -print:
find /etc/systemd -type l -exec realpath '{}' \+
Added benefit of `realpath` is that we see ... well, the realpath. So when someone says dhcpcd@.service isn't working we'll get a good clue what's going on when we see this result from realpath which would be missed by the other approaches:
/opt/services/dhcpcd/dhcpcd@.service
Last edited by Trilby (2020-06-02 16:43:37)
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Add seasoning where required:
find /etc/systemd -type l -exec realpath '{}' \+ | sort
That actually showed something I never realized: NetworkManager is linked twice on my system - through multi-user.target.wants and explicitly enabled, whereas other multi-user.target.wants targets are not.
Offline
Pages: 1