[systemd-devel] hint to know the state of the service using function
Rajmohan. R
Rajmohan.R at kpit.com
Fri Aug 23 15:51:20 UTC 2024
Hi,
Below is the change related to logging of the units (service) while changing the state [in]active_[exit/enter].
I did not get any hint from source code, to know the state change using function, without querying the target system through CLI.
Could someone from the forum help in providing a hint on how to get the state of the services without querying through CLI.
Instead of below changes, is there any alternative modification i can do to know the state of the service.
diff --git a/src/core/unit.c b/src/core/unit.c
index c406bb7ab2..e6ad9b3fbf 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2497,15 +2497,31 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlag
if (!MANAGER_IS_RELOADING(m)) {
dual_timestamp_get(&u->state_change_timestamp);
- if (UNIT_IS_INACTIVE_OR_FAILED(os) && !UNIT_IS_INACTIVE_OR_FAILED(ns))
+ if (UNIT_IS_INACTIVE_OR_FAILED(os) && !UNIT_IS_INACTIVE_OR_FAILED(ns)) {
u->inactive_exit_timestamp = u->state_change_timestamp;
- else if (!UNIT_IS_INACTIVE_OR_FAILED(os) && UNIT_IS_INACTIVE_OR_FAILED(ns))
+ log_warning("sd: u=%s, inactive_exit="USEC_FMT,
+ u->id, u->inactive_exit_timestamp.monotonic);
+ }
+ else if (!UNIT_IS_INACTIVE_OR_FAILED(os) && UNIT_IS_INACTIVE_OR_FAILED(ns)) {
u->inactive_enter_timestamp = u->state_change_timestamp;
+ log_warning("sd: u=%s, inactive_enter="USEC_FMT,
+ u->id, u->inactive_enter_timestamp.monotonic);
+ }
- if (!UNIT_IS_ACTIVE_OR_RELOADING(os) && UNIT_IS_ACTIVE_OR_RELOADING(ns))
+ if (!UNIT_IS_ACTIVE_OR_RELOADING(os) && UNIT_IS_ACTIVE_OR_RELOADING(ns)) {
u->active_enter_timestamp = u->state_change_timestamp;
- else if (UNIT_IS_ACTIVE_OR_RELOADING(os) && !UNIT_IS_ACTIVE_OR_RELOADING(ns))
+ log_warning("sd: u=%s, active_enter="USEC_FMT,
+ u->id, u->active_enter_timestamp.monotonic);
+ if (unit_has_name(u, SPECIAL_BASIC_TARGET)) {
+ log_warning("sd: status changed: STARTING, t="USEC_FMT,
+ u->active_enter_timestamp.monotonic);
+ }
+ }
+ else if (UNIT_IS_ACTIVE_OR_RELOADING(os) && !UNIT_IS_ACTIVE_OR_RELOADING(ns)) {
u->active_exit_timestamp = u->state_change_timestamp;
+ log_warning("sd: u=%s, active_exit="USEC_FMT,
+ u->id, u->active_exit_timestamp.monotonic);
+ }
}
/* Keep track of failed units */
Thank you for your help
rajmohan
This message contains information that may be privileged or confidential and is the property of the KPIT Technologies Ltd. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. KPIT Technologies Ltd. does not accept any liability for virus infected mails.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20240823/105ba280/attachment-0001.htm>
More information about the systemd-devel
mailing list