You are not logged in.

#1 2020-05-30 14:08:38

Lone_Wolf
Forum Moderator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,922

list of enabled services incomplete ?

"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

#2 2020-05-30 14:11:15

judd1
Member
Registered: 2015-09-04
Posts: 260

Re: list of enabled services incomplete ?

systemctl

This isn't right. This isn't even wrong.
-- Wolfgang Pauli --

Offline

#3 2020-05-30 14:15:05

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: list of enabled services incomplete ?

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

#4 2020-05-30 14:19:56

loqs
Member
Registered: 2014-03-06
Posts: 17,373

Re: list of enabled services incomplete ?

What state does `systemctl list-unit-files` show for dhcpcd@enp4s0.service and syslog-ng@default.service?

Offline

#5 2020-05-30 14:36:45

Lone_Wolf
Forum Moderator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,922

Re: list of enabled services incomplete ?

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

#6 2020-05-30 14:39:14

judd1
Member
Registered: 2015-09-04
Posts: 260

Re: list of enabled services incomplete ?

Trilby wrote:

I'd only recommend using a find command on /etc/systemd.

I didn't know, thanks. smile


This isn't right. This isn't even wrong.
-- Wolfgang Pauli --

Offline

#7 2020-05-30 14:39:54

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: list of enabled services incomplete ?

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

#8 2020-05-30 14:47:34

Lone_Wolf
Forum Moderator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,922

Re: list of enabled services incomplete ?

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

#9 2020-05-30 14:50:54

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: list of enabled services incomplete ?

find /etc/systemd/ -name *.service -ls

Like that?

Offline

#10 2020-05-30 14:51:26

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,740

Re: list of enabled services incomplete ?

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

#11 2020-05-30 14:56:41

seth
Member
Registered: 2012-09-03
Posts: 51,253

Re: list of enabled services incomplete ?

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

#12 2020-05-30 14:57:37

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: list of enabled services incomplete ?

Lone_Wolf wrote:

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

#13 2020-05-30 15:04:09

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: list of enabled services incomplete ?

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

#14 2020-05-30 15:09:24

Lone_Wolf
Forum Moderator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,922

Re: list of enabled services incomplete ?

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)


V1del wrote:

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

#15 2020-05-30 15:15:37

loqs
Member
Registered: 2014-03-06
Posts: 17,373

Re: list of enabled services incomplete ?

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

#16 2020-05-30 15:45:58

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: list of enabled services incomplete ?

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

#17 2020-05-30 16:29:00

loqs
Member
Registered: 2014-03-06
Posts: 17,373

Re: list of enabled services incomplete ?

Is the following POSIX compliant?

find /etc/systemd -type l -exec test -f {} \; -print

Offline

#18 2020-05-30 16:39:00

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: list of enabled services incomplete ?

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

#19 2020-06-02 00:02:38

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: list of enabled services incomplete ?

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

#20 2020-06-02 06:16:33

seth
Member
Registered: 2012-09-03
Posts: 51,253

Re: list of enabled services incomplete ?

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

#21 2020-06-02 11:53:17

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: list of enabled services incomplete ?

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

#22 2020-06-02 15:07:21

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: list of enabled services incomplete ?

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

Board footer

Powered by FluxBB