Skip to content

Conversation

@avrovulcanxh607
Copy link

Monitored unit active-states are now retained. To try & prevent invalid data getting "stuck" in the broker, we publish "unknown" as the status to every monitored unit on shutdown.

Copy link
Owner

@fphammerle fphammerle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Could you add a line to the # Unreleased section of the CHANGELOG.md?

Did you set the executable bit on setup.py intentionally?

Comment on lines +512 to +518

for monitored_system_unit in state.monitored_system_unit_names:
await mqtt_client.publish(
topic=state.get_system_unit_active_state_mqtt_topic(unit_name=monitored_system_unit),
payload="unknown",
retain=True,
)
Copy link
Owner

@fphammerle fphammerle Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for monitored_system_unit in state.monitored_system_unit_names:
await mqtt_client.publish(
topic=state.get_system_unit_active_state_mqtt_topic(unit_name=monitored_system_unit),
payload="unknown",
retain=True,
)

I am not sure whether we should report "unknown" on the shutdown of systemctl-mqtt, as consumers should always subscribe to the birth/last-will topic systemctl/[hostname]/status (c3533ee) to be notified when systemctl-mqtt becomes available or unavailable (so "unknown" seems redundant to me and somehow misleadingly suggests that systemd reports "unknown").
What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I was really aiming for was to clear the topic of stale services. As it stands, if you decided to change what services are monitored the retained topic stays there "forever" - this was an easy way to at least mark out topics that haven't changed since shutdown. Do you think we need to clear out stale topics or leave that as an exercise of due diligence for the user?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed your reply. Yes, I would leave clearing the topic to the user/subscriber as we can't guarantee that "unknown" will be sent (e.g. on sigkill).

@fphammerle fphammerle mentioned this pull request Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants