Skip to content

Commit 9d271eb

Browse files
authored
Merge pull request #1033 from kernelkit/yang-add-services
Add new operational support for services Signed-off-by: Joachim Wiberg <[email protected]>
2 parents b72fb8f + b6d7e4f commit 9d271eb

File tree

12 files changed

+893
-1
lines changed

12 files changed

+893
-1
lines changed

src/confd/yang/confd.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ MODULES=(
3232
3333
3434
35-
"infix-system@2025-01-25.yang"
35+
"infix-system@2025-04-29.yang"
3636
3737
3838

src/confd/yang/confd/infix-system.yang

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ module infix-system {
2828
contact "[email protected]";
2929
description "Infix augments and deviations to ietf-system.";
3030

31+
revision 2025-04-29 {
32+
description "Add services status.";
33+
reference "internal";
34+
}
35+
3136
revision 2025-01-25 {
3237
description "Add DNS resolver status.";
3338
reference "internal";
@@ -412,6 +417,98 @@ module infix-system {
412417
}
413418
}
414419
}
420+
421+
container services {
422+
description "List of monitored system services (processes)";
423+
config false;
424+
425+
list service {
426+
description "Tracked system service processes.";
427+
428+
leaf pid {
429+
type uint32;
430+
description "Process ID (PID) of the service.";
431+
}
432+
433+
leaf name {
434+
type string;
435+
description "Name of the service or process.";
436+
}
437+
438+
leaf description {
439+
type string;
440+
description
441+
"Short description of the service.";
442+
}
443+
444+
leaf status {
445+
type enumeration {
446+
enum halted {
447+
description "Service is halted.";
448+
}
449+
enum missing {
450+
description "Service files or dependencies are missing.";
451+
}
452+
enum crashed {
453+
description "Service has crashed.";
454+
}
455+
enum stopped {
456+
description "Service has been manually stopped.";
457+
}
458+
enum busy {
459+
description "Service is busy.";
460+
}
461+
enum restart {
462+
description "Service is restarting.";
463+
}
464+
enum conflict {
465+
description "Service has a conflict preventing start.";
466+
}
467+
enum unknown {
468+
description "Service is in an unknown state.";
469+
}
470+
enum done {
471+
description "Service task has completed.";
472+
}
473+
enum failed {
474+
description "Service task has failed.";
475+
}
476+
enum active {
477+
description "Run/task type service is active.";
478+
}
479+
enum stopping {
480+
description "Service is in the process of stopping.";
481+
}
482+
enum teardown {
483+
description "Service is performing teardown operations.";
484+
}
485+
enum setup {
486+
description "Service is setting up.";
487+
}
488+
enum cleanup {
489+
description "Service is cleaning up.";
490+
}
491+
enum paused {
492+
description "Service is paused.";
493+
}
494+
enum waiting {
495+
description "Service is waiting for conditions.";
496+
}
497+
enum starting {
498+
description "Service is starting.";
499+
}
500+
enum running {
501+
description "Service is running.";
502+
}
503+
enum dead {
504+
description "Service process is dead.";
505+
}
506+
}
507+
description
508+
"Detailed current status of the process.";
509+
}
510+
}
511+
}
415512
}
416513

417514
deviation "/sys:system/sys:hostname" {
File renamed without changes.

src/klish-plugin-infix/xml/infix.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@
336336
</SWITCH>
337337
</COMMAND>
338338

339+
<COMMAND name="services" help="Show system services">
340+
<ACTION sym="script">
341+
show services
342+
</ACTION>
343+
</COMMAND>
344+
339345
<COMMAND name="software" help="Show software info">
340346
<SWITCH name="optional" min="0" max="1">
341347
<COMMAND name="name" help="Show detailed info about a partition">

src/show/show.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ def software(args: List[str]) -> None:
142142
else:
143143
print("Too many arguments provided. Only one name is expected.")
144144

145+
def services(args: List[str]) -> None:
146+
data = run_sysrepocfg("/ietf-system:system-state/infix-system:services")
147+
if not data:
148+
print("No service data retrieved.")
149+
return
150+
151+
if RAW_OUTPUT:
152+
print(json.dumps(data, indent=2))
153+
return
154+
155+
cli_pretty(data, f"show-services")
156+
145157
def routes(args: List[str]):
146158
ip_version = args[0] if args and args[0] in ["ipv4", "ipv6"] else "ipv4"
147159

@@ -186,6 +198,7 @@ def execute_command(command: str, args: List[str]):
186198
'ntp': ntp,
187199
'routes': routes,
188200
'lldp': lldp,
201+
'services' : services,
189202
'software' : software,
190203
'stp': stp,
191204
'wifi': wifi

src/statd/python/cli_pretty/cli_pretty.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ class PadNtpSource:
172172
poll = 14
173173

174174

175+
class PadService:
176+
name = 16
177+
status = 8
178+
pid = 8
179+
description = 40
180+
181+
175182
class PadWifiScan:
176183
ssid = 40
177184
encryption = 30
@@ -1507,6 +1514,42 @@ def show_software(json, name):
15071514
slot.print()
15081515

15091516

1517+
def show_services(json):
1518+
if not json.get("ietf-system:system-state", "infix-system:services"):
1519+
print("Error, cannot find infix-system:services")
1520+
sys.exit(1)
1521+
1522+
services_data = get_json_data({}, json, 'ietf-system:system-state', 'infix-system:services')
1523+
services = services_data.get("service", [])
1524+
1525+
hdr = (f"{'NAME':<{PadService.name}}"
1526+
f"{'STATUS':<{PadService.status}}"
1527+
f"{'PID':>{PadService.pid -1}}"
1528+
f" {'DESCRIPTION'}")
1529+
print(Decore.invert(hdr))
1530+
1531+
for svc in services:
1532+
name = svc.get('name', '')
1533+
status = svc.get('status', '')
1534+
pid = svc.get('pid', 0)
1535+
description = svc.get('description', '')
1536+
1537+
if status in ('running', 'active', 'done'):
1538+
status_str = Decore.green(status)
1539+
elif status in ('crashed', 'failed', 'halted', 'missing', 'dead', 'conflict'):
1540+
status_str = Decore.red(status)
1541+
else:
1542+
status_str = Decore.yellow(status)
1543+
1544+
pid_str = str(pid) if pid > 0 else '-'
1545+
1546+
row = f"{name:<{PadService.name}}"
1547+
row += f"{status_str:<{PadService.status + 9}}"
1548+
row += f"{pid_str:>{PadService.pid}}"
1549+
row += f" {description}"
1550+
print(row)
1551+
1552+
15101553
def show_hardware(json):
15111554
if not json.get("ietf-hardware:hardware"):
15121555
print("Error, top level \"ietf-hardware:component\" missing")
@@ -2496,6 +2539,8 @@ def main():
24962539
subparsers.add_parser('show-routing-table', help='Show the routing table') \
24972540
.add_argument('-i', '--ip', required=True, help='IPv4 or IPv6 address')
24982541

2542+
subparsers.add_parser('show-services', help='Show system services')
2543+
24992544
subparsers.add_parser('show-software', help='Show software versions') \
25002545
.add_argument('-n', '--name', help='Slotname')
25012546

@@ -2528,6 +2573,8 @@ def main():
25282573
show_routing_table(json_data, args.ip)
25292574
elif args.command == "show-software":
25302575
show_software(json_data, args.name)
2576+
elif args.command == "show-services":
2577+
show_services(json_data)
25312578

25322579
else:
25332580
print(f"Error, unknown command '{args.command}'")

src/statd/python/yanger/ietf_system.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,24 @@ def add_platform(out):
177177

178178
insert(out, "platform", platform)
179179

180+
def add_services(out):
181+
data = HOST.run_json(["initctl", "-j"], [])
182+
services = []
183+
184+
for d in data:
185+
if "pid" not in d or "status" not in d or "identity" not in d or "description" not in d:
186+
continue
187+
188+
entry = {
189+
"pid": d["pid"],
190+
"name": d["identity"],
191+
"status": d["status"],
192+
"description": d["description"]
193+
}
194+
services.append(entry)
195+
196+
insert(out, "infix-system:services", "service", services)
197+
180198
def add_software(out):
181199
software = {}
182200
try:
@@ -291,5 +309,6 @@ def operational():
291309
add_dns(out_state)
292310
add_clock(out_state)
293311
add_platform(out_state)
312+
add_services(out_state)
294313

295314
return out
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
NAME STATUS PID DESCRIPTION
2+
udevd running 1185 Device event daemon (udev)
3+
dbus running 2248 D-Bus message bus daemon
4+
confd running 3039 Configuration daemon
5+
netopeer running 3548 NETCONF server
6+
dnsmasq running 2249 DHCP/DNS proxy
7+
tty:hvc0 running 3559 Getty on hvc0
8+
iitod running 2340 LED daemon
9+
klishd running 3560 CLI backend daemon
10+
mdns-alias running 3617 mDNS alias advertiser
11+
mstpd stopped - Spanning Tree daemon
12+
rauc running 3564 Software update service
13+
resolvconf done - Update DNS configuration
14+
statd running 3472 Status daemon
15+
staticd running 3653 Static routing daemon
16+
syslogd running 2241 System log daemon
17+
watchdogd running 2242 System watchdog daemon
18+
zebra running 3587 Zebra routing daemon
19+
mdns running 3616 Avahi mDNS-SD daemon
20+
chronyd running 3618 Chrony NTP v3/v4 daemon
21+
lldpd running 3633 LLDP daemon (IEEE 802.1ab)
22+
nginx running 3635 Web server
23+
rousette running 3636 RESTCONF server
24+
sshd running 3641 OpenSSH daemon

0 commit comments

Comments
 (0)