Dietpi view installed services and status

Hi guys,
I like to have Node-Red Dashboard which shows me the status of running services from all my PI’s I do have in my LAN. At the moment I run the comman “sudo systemctl list-units --type=service --state=running -o json-pretty” as a cron job and afterwards I do send it to the dashboard via mqtt.
Problem:
On one of my PI’s the command (“sudo systemctl list-units --type=service --state=running -o json-pretty”) gives me the same result back as “sudo systemctl list-units --type=service --state=running” which is not in json and looks pretty bad and I can’t use it in node-red.
I have two options here but I only need on solution for this problem, hopefully some can help here.
My thoughts:

  1. Because I like the overview of services in dietpi, which shows me the services I have installed and the status (“sudo dietpi-services”). Does anyone know the command behind it?
  2. Alternative: Does somebody knows the issue, why my command is not giving me back the result as json?

Informations:

  • I tried both (-o json and -o json-pretty)
  • All PI’s are at the same dietpi version: DietPi v8.7.1

Best regards
Ben

dietpi-services is not a single command. It is a script containing a couple of functions to display the status.

The -o option only has an effect on systemctl status for the shown journal logs, not for systemctl list-units.

Hi Joulinar,
If one or more commands doesn’t matter even if it is a script, this is fine as long as it is not running longer than a second. Is it possible to provide thoses scripts for all?
BR
Ben

I tried sudo systemctl list-units --type=service -o json-pretty and I get a pretty nice output, which looks different than without the -o json-pretty:

[
        {
                "unit" : "console-setup.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Set console font and keymap"
        },
        {
                "unit" : "cron.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "Regular background program processing daemon"
        },
        {
                "unit" : "dietpi-postboot.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "DietPi-PostBoot"
        },
        {
                "unit" : "dietpi-preboot.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "DietPi-PreBoot"
        },
        {
                "unit" : "dietpi-ramlog.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "DietPi-RAMlog"
        },
        {
                "unit" : "dropbear.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "LSB: Lightweight SSH server"
        },
        {
                "unit" : "fake-hwclock.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Restore / save the current clock"
        },
        {
                "unit" : "getty@tty1.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "Getty on tty1"
        },
        {
                "unit" : "ifup@eth0.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "ifup for eth0"
        },
        {
                "unit" : "ifupdown-pre.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Helper to synchronize boot up for ifupdown"
        },
        {
                "unit" : "keyboard-setup.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Set the console keyboard layout"
        },
        {
                "unit" : "kmod-static-nodes.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Create list of static device nodes for the current kernel"
        },
        {
                "unit" : "lighttpd.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "Lighttpd Daemon"
        },
        {
                "unit" : "mariadb.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "MariaDB 10.5.15 database server"
        },
        {
                "unit" : "netfilter-persistent.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "netfilter persistent configuration"
        },
        {
                "unit" : "networking.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Raise network interfaces"
        },
        {
                "unit" : "nmbd.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "Samba NMB Daemon"
        },
        {
                "unit" : "php7.4-fpm.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "The PHP 7.4 FastCGI Process Manager"
        },
        {
                "unit" : "pihole-FTL.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "LSB: pihole-FTL daemon"
        },
        {
                "unit" : "redis-server.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "Advanced key-value store"
        },
        {
                "unit" : "rngd.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "Start entropy gathering daemon (rngd)"
        },
        {
                "unit" : "rpcbind.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "RPC bind portmap service"
        },
        {
                "unit" : "rpimonitor.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "LSB: RPi-Monitor daemon"
        },
        {
                "unit" : "smbd.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "Samba SMB Daemon"
        },
        {
                "unit" : "systemd-fsck-root.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "File System Check on Root Device"
        },
        {
                "unit" : "systemd-fsck@dev-disk-by\\x2dpartuuid-9bcc366d\\x2d01.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "File System Check on /dev/disk/by-partuuid/9bcc366d-01"
        },
        {
                "unit" : "systemd-journal-flush.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Flush Journal to Persistent Storage"
        },
        {
                "unit" : "systemd-journald.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "Journal Service"
        },
        {
                "unit" : "systemd-modules-load.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Load Kernel Modules"
        },
        {
                "unit" : "systemd-random-seed.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Load/Save Random Seed"
        },
        {
                "unit" : "systemd-remount-fs.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Remount Root and Kernel File Systems"
        },
        {
                "unit" : "systemd-sysctl.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Apply Kernel Variables"
        },
        {
                "unit" : "systemd-sysusers.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Create System Users"
        },
        {
                "unit" : "systemd-tmpfiles-setup-dev.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Create Static Device Nodes in /dev"
        },
        {
                "unit" : "systemd-tmpfiles-setup.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Create Volatile Files and Directories"
        },
        {
                "unit" : "systemd-udev-trigger.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Coldplug All udev Devices"
        },
        {
                "unit" : "systemd-udevd.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "Rule-based Manager for Device Events and Files"
        },
        {
                "unit" : "systemd-update-utmp.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Update UTMP about System Boot/Shutdown"
        },
        {
                "unit" : "systemd-user-sessions.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "Permit User Sessions"
        },
        {
                "unit" : "unbound.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "running",
                "description" : "Unbound DNS server"
        },
        {
                "unit" : "wg-quick@wg0.service",
                "load" : "loaded",
                "active" : "active",
                "sub" : "exited",
                "description" : "WireGuard via wg-quick(8) for wg0"
        }
]

-o json-pretty formates it nicely (like in my example)
-o json removes just all spaces and empty lines (in comparison to json-pretty)
without the -o option it’s more like a table.

Yeah those are mine experience as well, but not on one PI which is strange. :slight_smile: