17

I have a "service" that originates from an /etc/init.d/XX script, and a systemd wrapper is generated for it. It doesn't autostart in any runlevel, and when I run systemctl --all or systemctl list-unit-files --all it doesn't show up in any list.

My hunch is that because it has no dependencies, hasn't been started, it isn't "loaded" into systemd (so not enabled, not loaded) so systemd doesn't list it.

Is there a way to get a full list of all possible services, even those not yet started and that aren't auto-started? Or do a systemctl search equivalent?

This related question only asks for a list of services that will be attempted at boot time.

The man page for systemctl under "--all" says

To list all units installed on the system, use the list-unit-files command instead

but these disabled units do not show up in the output of list-unit-files.

2
  • How you tried systemctl show XX?
    – muru
    Commented May 8, 2019 at 20:38
  • systemctl show XX works, but I'm looking for a way to list "all the possible options for XX" as it were...even those that don't auto start, I added to the question.
    – rogerdpack
    Commented May 9, 2019 at 21:16

4 Answers 4

11

OK I asked "the systemd guys" and they said in old versions it didn't list them all, despite the man page saying this:

   -a, --all
       When listing units, show all loaded units, regardless of their
       state, including inactive units. When showing unit/job/manager
       properties, show all properties regardless whether they are set or
       not.

       To list all units installed on the system, use the list-unit-files
       command instead.

Most of the functionality listed above didn't seem to actually happen with "my" systemd version systemd 219 (CentOS 6). But it seems fixed in newer versions of systemctl on Debian 9 which has version systemd 232, perhaps that's why.

You can still control them like normal (status, start, stop) with the older systemd version if the init.d script does specify runlevels but is absent from all /etc/rc?.d dirs (a la chkconfig --del my_service or its equivalent systemctl disable my_service, or if chkconfig was never run initially on it) then the systemd-sysv-generator with older versions of systemd it doesn't [show up in the lists][2] if you run systemctl list-units --all etc. even though it's working fine and still controllable. Or if they're normal services but disabled they seem to also not show up in any lists, despite being still functional.

ref: https://lists.freedesktop.org/archives/systemd-devel/2019-May/042555.html

9

List every loaded service that is running, active, or failed in the system:

# sudo systemctl list-units --type=service --all

List all Disabled services in the system:

# sudo systemctl list-unit-files --type=service --state=disabled

List all Enabled services in the system:

# sudo systemctl list-unit-files --type=service --state=enabled

List every loaded service that is active state in the system:

# sudo systemctl list-units --type=service --state=active

List every loaded service that is running state in the system: This is my favorite command

# sudo systemctl list-units --type=service --state=running

List every loaded service that is failed state in the system:

# sudo systemctl list-units --type=service --state=failed

List every loaded service that is exited state in the system:

# sudo systemctl list-units --type=service --state=exited
4
  • Updated with full explanations. Commented Sep 13, 2022 at 8:40
  • And would this work when the service is a /etc/init.d script with a systems wrapper, as described in the question?
    – Kusalananda
    Commented Sep 13, 2022 at 9:03
  • so would you say this is buggy behavior? [root@podcast-2 ~]# systemctl --version systemd 252 (252.16-1.amzn2023.0.2) [root@podcast-2 ~]# systemctl list-units --type service --all|grep maria [root@podcast-2 ~]# systemctl status mariadb.service ○ mariadb.service - MariaDB 10.5 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; preset: disabled) Active: inactive (dead) Docs: man:mariadbd(8) mariadb.com/kb/en/library/systemd
    – djsadinoff
    Commented Apr 18 at 12:30
3

Are you running these commands as root? I believe that the list-unit-files command is exactly what you're looking for. It lists the unit files and not just the list of loaded services. I think you're likely looking at an issue with how your service is configured.

Maybe start by creating a dummy service and make sure it gets registered. Something that doesn't actually do anything. Then once that's working you can see how it differs from the service that isn't working. Or compare your service unit file with one of a simple service that is working.

2
  • 1
    There's a systemd SysV generator that translates init scripts to unit files, actually.
    – Jeff Schaller
    Commented May 9, 2019 at 0:28
  • OK I did some tests, even using a dummy systemd service, and it appears that if "any" service is disabled (i.e. bound to no targets), then after a systemctl daemon-reload it no longer shows up in any lists...so it's not an issue exclusive to the systemd-sysv-generator methinks...
    – rogerdpack
    Commented May 9, 2019 at 21:08
0

A cool TUI for systemctl:

joehillen/sysz: An fzf terminal UI for systemctl

A fzf terminal UI for systemctl

Installation:

wget -O ~/.bin/sysz https://github.com/joehillen/sysz/releases/latest/download/sysz
chmod +x ~/.bin/sysz

Usage: sysz <other systemctl args as you wish>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .