From ab8b174eff2ec4a17bc45f63b5d1cbdcf88c0196 Mon Sep 17 00:00:00 2001 From: Richard Alpe Date: Tue, 29 Apr 2025 13:39:12 +0200 Subject: [PATCH] confd: augment new services container to ietf-system This patch adds operational data support for system services. The data is in a generic format but is intended to be able to represent finit information (initctl) nicely. The reason for augmenting this to ietf-system and not to infix-services is that we consider this generic system information which is totally disconnected from what ever services infix might provide. In this first state we only support pid, name, description and state. Making the data look something like: "infix-system:services": { "service": [ { "pid": 1185, "name": "udevd", "status": "running", "description": "Device event daemon (udev)" }] Signed-off-by: Richard Alpe --- src/confd/yang/confd.inc | 2 +- src/confd/yang/confd/infix-system.yang | 98 +++++ ...1-25.yang => infix-system@2025-04-29.yang} | 0 src/statd/python/yanger/ietf_system.py | 19 + test/case/statd/system/ietf-system.json | 142 +++++++ test/case/statd/system/system/run/initctl_-j | 401 ++++++++++++++++++ 6 files changed, 661 insertions(+), 1 deletion(-) rename src/confd/yang/confd/{infix-system@2025-01-25.yang => infix-system@2025-04-29.yang} (100%) create mode 100644 test/case/statd/system/system/run/initctl_-j diff --git a/src/confd/yang/confd.inc b/src/confd/yang/confd.inc index 9aab145f9..49c55a319 100644 --- a/src/confd/yang/confd.inc +++ b/src/confd/yang/confd.inc @@ -30,7 +30,7 @@ MODULES=( "infix-dhcp-client@2025-01-29.yang" "infix-dhcp-server@2025-01-29.yang" "infix-meta@2024-10-18.yang" - "infix-system@2025-01-25.yang" + "infix-system@2025-04-29.yang" "infix-services@2024-12-03.yang" "ieee802-ethernet-interface@2019-06-21.yang" "infix-ethernet-interface@2024-02-27.yang" diff --git a/src/confd/yang/confd/infix-system.yang b/src/confd/yang/confd/infix-system.yang index dc651ca7d..6b1364e6e 100644 --- a/src/confd/yang/confd/infix-system.yang +++ b/src/confd/yang/confd/infix-system.yang @@ -28,6 +28,11 @@ module infix-system { contact "kernelkit@googlegroups.com"; description "Infix augments and deviations to ietf-system."; + revision 2025-04-29 { + description "Add services status."; + reference "internal"; + } + revision 2025-01-25 { description "Add DNS resolver status."; reference "internal"; @@ -412,6 +417,99 @@ module infix-system { } } } + + container services { + description "List of monitored system services (processes)"; + config false; + + list service { + key "pid"; + description "Tracked system service processes."; + + leaf pid { + type uint32; + description "Process ID (PID) of the service."; + } + + leaf name { + type string; + description "Name of the service or process."; + } + + leaf description { + type string; + description + "Short description of the service."; + } + + leaf status { + type enumeration { + enum halted { + description "Service is halted."; + } + enum missing { + description "Service files or dependencies are missing."; + } + enum crashed { + description "Service has crashed."; + } + enum stopped { + description "Service has been manually stopped."; + } + enum busy { + description "Service is busy."; + } + enum restart { + description "Service is restarting."; + } + enum conflict { + description "Service has a conflict preventing start."; + } + enum unknown { + description "Service is in an unknown state."; + } + enum done { + description "Service task has completed."; + } + enum failed { + description "Service task has failed."; + } + enum active { + description "Run/task type service is active."; + } + enum stopping { + description "Service is in the process of stopping."; + } + enum teardown { + description "Service is performing teardown operations."; + } + enum setup { + description "Service is setting up."; + } + enum cleanup { + description "Service is cleaning up."; + } + enum paused { + description "Service is paused."; + } + enum waiting { + description "Service is waiting for conditions."; + } + enum starting { + description "Service is starting."; + } + enum running { + description "Service is running."; + } + enum dead { + description "Service process is dead."; + } + } + description + "Detailed current status of the process."; + } + } + } } deviation "/sys:system/sys:hostname" { diff --git a/src/confd/yang/confd/infix-system@2025-01-25.yang b/src/confd/yang/confd/infix-system@2025-04-29.yang similarity index 100% rename from src/confd/yang/confd/infix-system@2025-01-25.yang rename to src/confd/yang/confd/infix-system@2025-04-29.yang diff --git a/src/statd/python/yanger/ietf_system.py b/src/statd/python/yanger/ietf_system.py index f7a1bac3f..bc032a13f 100644 --- a/src/statd/python/yanger/ietf_system.py +++ b/src/statd/python/yanger/ietf_system.py @@ -177,6 +177,24 @@ def add_platform(out): insert(out, "platform", platform) +def add_services(out): + data = HOST.run_json(["initctl", "-j"], []) + services = [] + + for d in data: + if "pid" not in d or "status" not in d or "identity" not in d or "description" not in d: + continue + + entry = { + "pid": d["pid"], + "name": d["identity"], + "status": d["status"], + "description": d["description"] + } + services.append(entry) + + insert(out, "infix-system:services", "service", services) + def add_software(out): software = {} try: @@ -291,5 +309,6 @@ def operational(): add_dns(out_state) add_clock(out_state) add_platform(out_state) + add_services(out_state) return out diff --git a/test/case/statd/system/ietf-system.json b/test/case/statd/system/ietf-system.json index 70cefb81c..02b31b19e 100644 --- a/test/case/statd/system/ietf-system.json +++ b/test/case/statd/system/ietf-system.json @@ -128,6 +128,148 @@ "os-version": "v25.04.0-rc1-3-g8daf1571-dirty", "os-release": "v25.04.0-rc1-3-g8daf1571-dirty", "machine": "x86_64" + }, + "infix-system:services": { + "service": [ + { + "pid": 1185, + "name": "udevd", + "status": "running", + "description": "Device event daemon (udev)" + }, + { + "pid": 2248, + "name": "dbus", + "status": "running", + "description": "D-Bus message bus daemon" + }, + { + "pid": 3039, + "name": "confd", + "status": "running", + "description": "Configuration daemon" + }, + { + "pid": 3548, + "name": "netopeer", + "status": "running", + "description": "NETCONF server" + }, + { + "pid": 2249, + "name": "dnsmasq", + "status": "running", + "description": "DHCP/DNS proxy" + }, + { + "pid": 3559, + "name": "tty:hvc0", + "status": "running", + "description": "Getty on hvc0" + }, + { + "pid": 2340, + "name": "iitod", + "status": "running", + "description": "LED daemon" + }, + { + "pid": 3560, + "name": "klishd", + "status": "running", + "description": "CLI backend daemon" + }, + { + "pid": 3617, + "name": "mdns-alias", + "status": "running", + "description": "mDNS alias advertiser " + }, + { + "pid": 0, + "name": "mstpd", + "status": "stopped", + "description": "Spanning Tree daemon" + }, + { + "pid": 3564, + "name": "rauc", + "status": "running", + "description": "Software update service" + }, + { + "pid": 0, + "name": "resolvconf", + "status": "done", + "description": "Update DNS configuration" + }, + { + "pid": 3472, + "name": "statd", + "status": "running", + "description": "Status daemon" + }, + { + "pid": 3653, + "name": "staticd", + "status": "running", + "description": "Static routing daemon" + }, + { + "pid": 2241, + "name": "syslogd", + "status": "running", + "description": "System log daemon" + }, + { + "pid": 2242, + "name": "watchdogd", + "status": "running", + "description": "System watchdog daemon" + }, + { + "pid": 3587, + "name": "zebra", + "status": "running", + "description": "Zebra routing daemon" + }, + { + "pid": 3616, + "name": "mdns", + "status": "running", + "description": "Avahi mDNS-SD daemon" + }, + { + "pid": 3618, + "name": "chronyd", + "status": "running", + "description": "Chrony NTP v3/v4 daemon" + }, + { + "pid": 3633, + "name": "lldpd", + "status": "running", + "description": "LLDP daemon (IEEE 802.1ab)" + }, + { + "pid": 3635, + "name": "nginx", + "status": "running", + "description": "Web server" + }, + { + "pid": 3636, + "name": "rousette", + "status": "running", + "description": "RESTCONF server" + }, + { + "pid": 3641, + "name": "sshd", + "status": "running", + "description": "OpenSSH daemon" + } + ] } } } diff --git a/test/case/statd/system/system/run/initctl_-j b/test/case/statd/system/system/run/initctl_-j new file mode 100644 index 000000000..4e9bf0100 --- /dev/null +++ b/test/case/statd/system/system/run/initctl_-j @@ -0,0 +1,401 @@ +[ + { + "identity": "udevd", + "description": "Device event daemon (udev)", + "type": "service", + "forking": false, + "status": "running", + "origin": "/usr/lib/finit/system/10-hotplug.conf", + "command": "udevd $UDEVD_ARGS", + "environment": "-/etc/default/udevd", + "restarts": 0, + "pidfile": "/run/udevd.pid", + "pid": 1185, + "user": "root", + "group": "root", + "uptime": 1390, + "runlevels": [ "S", 1, 2, 3, 4, 5, 7, 8, 9 ] + }, + { + "identity": "dbus", + "description": "D-Bus message bus daemon", + "type": "service", + "forking": true, + "status": "running", + "origin": "/etc/finit.d/dbus.conf", + "command": "/usr/bin/dbus-daemon --nofork --system --syslog-only", + "condition": [ "+pid/syslogd" ], + "restarts": 0, + "pidfile": "/run/messagebus.pid", + "pid": 2248, + "user": "root", + "group": "root", + "uptime": 1390, + "runlevels": [ "S", 1, 2, 3, 4, 5, 6, 7, 8, 9 ] + }, + { + "identity": "confd", + "description": "Configuration daemon", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/confd.conf", + "command": "sysrepo-plugind -f -p /run/confd.pid -n -v warning", + "condition": [ "+run/bootstrap/success" ], + "restarts": 0, + "pidfile": "/run/confd.pid", + "pid": 3039, + "user": "root", + "group": "root", + "uptime": 1390, + "runlevels": [ "S", 1, 2, 3, 4, 5 ] + }, + { + "identity": "netopeer", + "description": "NETCONF server", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/confd.conf", + "command": "netopeer2-server -F -t $CONFD_TIMEOUT -v 1", + "environment": "/etc/default/confd", + "condition": [ "+pid/confd" ], + "restarts": 0, + "pidfile": "/run/netopeer2-server.pid", + "pid": 3548, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 1, 2, 3, 4, 5 ] + }, + { + "identity": "dnsmasq", + "description": "DHCP/DNS proxy", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/dnsmasq.conf", + "command": "dnsmasq -k -u root", + "condition": [ "+pid/syslogd" ], + "restarts": 0, + "pidfile": "/run/dnsmasq.pid", + "pid": 2249, + "user": "root", + "group": "root", + "uptime": 1390, + "runlevels": [ "S", 1, 2, 3, 4, 5 ] + }, + { + "identity": "tty:hvc0", + "description": "Getty on hvc0", + "type": "tty", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/getty.conf", + "command": "/usr/libexec/finit/getty -p hvc0 0 xterm", + "restarts": 0, + "pidfile": "none", + "pid": 3559, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 1, 2, 3, 4, 5, 7, 8, 9 ] + }, + { + "identity": "iitod", + "description": "LED daemon", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/iitod.conf", + "command": "iitod", + "condition": [ "+usr/product", "+usr/led" ], + "restarts": 0, + "pidfile": "none", + "pid": 2340, + "user": "root", + "group": "root", + "uptime": 1390, + "runlevels": [ "S", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] + }, + { + "identity": "klishd", + "description": "CLI backend daemon", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/klish.conf", + "command": "/usr/bin/klishd -d", + "restarts": 0, + "pidfile": "none", + "pid": 3560, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 2, 3, 4, 5 ] + }, + { + "identity": "mdns-alias", + "description": "mDNS alias advertiser ", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/mdns-alias.conf", + "command": "mdns-alias $MDNS_ALIAS_ARGS", + "environment": "-/etc/default/mdns-alias", + "condition": [ "+service/mdns/running" ], + "restarts": 0, + "pidfile": "none", + "pid": 3617, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 2, 3, 4, 5 ] + }, + { + "identity": "mstpd", + "description": "Spanning Tree daemon", + "type": "service", + "forking": false, + "status": "stopped", + "exit": { "code": 0 }, + "origin": "/etc/finit.d/enabled/mstpd.conf", + "command": "mstpd $MSTPD_ARGS", + "environment": "-/etc/default/mstpd", + "starts": 0, + "restarts": 0, + "pidfile": "none", + "pid": 0, + "user": "root", + "group": "root", + "uptime": 0, + "runlevels": [ "S", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] + }, + { + "identity": "rauc", + "description": "Software update service", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/rauc.conf", + "command": "rauc service $RAUC_ARGS", + "environment": "-/etc/default/rauc", + "condition": [ "+service/dbus/running" ], + "restarts": 0, + "pidfile": "none", + "pid": 3564, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 2, 3, 4, 5 ] + }, + { + "identity": "resolvconf", + "description": "Update DNS configuration", + "type": "task", + "forking": false, + "status": "done", + "exit": { "code": 0 }, + "origin": "/etc/finit.d/enabled/resolvconf.conf", + "command": "resolvconf -u", + "condition": [ "+usr/bootstrap" ], + "restarts": 2, + "pidfile": "none", + "pid": 0, + "user": "root", + "group": "root", + "uptime": 0, + "runlevels": [ "S", 1, 2, 3, 4, 5 ] + }, + { + "identity": "statd", + "description": "Status daemon", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/statd.conf", + "command": "statd -f -p /run/statd.pid -n", + "condition": [ "+pid/confd" ], + "restarts": 0, + "pidfile": "/run/statd.pid", + "pid": 3472, + "user": "root", + "group": "root", + "uptime": 1389, + "runlevels": [ "S", 1, 2, 3, 4, 5 ] + }, + { + "identity": "staticd", + "description": "Static routing daemon", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/staticd.conf", + "command": "staticd -A 127.0.0.1 -u frr -g frr -f /etc/frr/staticd.conf", + "condition": [ "+pid/zebra" ], + "restarts": 0, + "pidfile": "/run/frr/staticd.pid", + "pid": 3653, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 2, 3, 4, 5 ] + }, + { + "identity": "syslogd", + "description": "System log daemon", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/sysklogd.conf", + "command": "syslogd -F $SYSLOGD_ARGS", + "environment": "-/etc/default/sysklogd", + "condition": [ "+run/udevadm:post/success" ], + "restarts": 0, + "pidfile": "/run/syslogd.pid", + "pid": 2241, + "user": "root", + "group": "root", + "uptime": 1390, + "runlevels": [ "S", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] + }, + { + "identity": "watchdogd", + "description": "System watchdog daemon", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/watchdogd.conf", + "command": "watchdogd -xns $WATCHDOGD_ARGS", + "environment": "-/etc/default/watchdogd", + "restarts": 0, + "pidfile": "/run/watchdogd/pid", + "pid": 2242, + "user": "root", + "group": "root", + "uptime": 1390, + "runlevels": [ "S", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] + }, + { + "identity": "zebra", + "description": "Zebra routing daemon", + "type": "service", + "forking": true, + "status": "running", + "origin": "/etc/finit.d/enabled/zebra.conf", + "command": "zebra $ZEBRA_ARGS", + "environment": "-/etc/default/zebra", + "restarts": 0, + "pidfile": "/run/frr/zebra.pid", + "pid": 3587, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 2, 3, 4, 5 ] + }, + { + "identity": "mdns", + "description": "Avahi mDNS-SD daemon", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/avahi.conf", + "command": "avahi-daemon -s $AVAHI_ARGS", + "environment": "-/etc/default/avahi", + "restarts": 0, + "pidfile": "none", + "pid": 3616, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 2, 3, 4, 5 ] + }, + { + "identity": "chronyd", + "description": "Chrony NTP v3/v4 daemon", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/chronyd.conf", + "command": "chronyd -n $CHRONY_ARGS", + "environment": "-/etc/default/chronyd", + "restarts": 0, + "pidfile": "/run/chrony/chronyd.pid", + "pid": 3618, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 2, 3, 4, 5 ] + }, + { + "identity": "lldpd", + "description": "LLDP daemon (IEEE 802.1ab)", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/lldpd.conf", + "command": "lldpd -d $LLDPD_ARGS", + "environment": "-/etc/default/lldpd", + "restarts": 0, + "pidfile": "none", + "pid": 3633, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 2, 3, 4, 5 ] + }, + { + "identity": "nginx", + "description": "Web server", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/nginx.conf", + "command": "nginx -g 'daemon off;' $NGINX_ARGS", + "environment": "-/etc/default/nginx", + "condition": [ "+usr/mkcert" ], + "restarts": 0, + "pidfile": "/run/nginx.pid", + "pid": 3635, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 2, 3, 4, 5 ] + }, + { + "identity": "rousette", + "description": "RESTCONF server", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/restconf.conf", + "command": "rousette --syslog -t $CONFD_TIMEOUT", + "environment": "/etc/default/confd", + "condition": [ "+pid/confd" ], + "restarts": 0, + "pidfile": "none", + "pid": 3636, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 1, 2, 3, 4, 5 ] + }, + { + "identity": "sshd", + "description": "OpenSSH daemon", + "type": "service", + "forking": false, + "status": "running", + "origin": "/etc/finit.d/enabled/sshd.conf", + "command": "/usr/sbin/sshd -D $SSHD_OPTS", + "environment": "-/etc/default/sshd", + "condition": [ "+pid/syslogd" ], + "restarts": 0, + "pidfile": "/run/sshd.pid", + "pid": 3641, + "user": "root", + "group": "root", + "uptime": 1388, + "runlevels": [ 2, 3, 4, 5 ] + } +]