106 lines
3.3 KiB
Diff
106 lines
3.3 KiB
Diff
From 86f01db06f5c20416a17a88a207ffb012588d0d8 Mon Sep 17 00:00:00 2001
|
|
From: licunlong <licunlong1@huawei.com>
|
|
Date: Wed, 31 May 2023 11:17:52 +0800
|
|
Subject: [PATCH 7/9] fix: enable trigger() for socket, and use this interface
|
|
to check service state make socket reenter listening state when it triggered
|
|
service enters dead state.
|
|
|
|
---
|
|
coms/socket/src/mng.rs | 3 ++-
|
|
coms/socket/src/unit.rs | 16 ++++++++++++++++
|
|
core/bin/unit/entry/uentry.rs | 5 +++++
|
|
core/bin/unit/entry/unitx.rs | 4 +++-
|
|
core/lib/unit/base.rs | 3 +++
|
|
5 files changed, 29 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/coms/socket/src/mng.rs b/coms/socket/src/mng.rs
|
|
index 82fdcbe..0435827 100644
|
|
--- a/coms/socket/src/mng.rs
|
|
+++ b/coms/socket/src/mng.rs
|
|
@@ -341,8 +341,9 @@ impl SocketMng {
|
|
self.set_state(SocketState::StartPost);
|
|
}
|
|
|
|
- fn enter_listening(&self) {
|
|
+ pub(crate) fn enter_listening(&self) {
|
|
log::debug!("enter start listening state");
|
|
+ /* Seem logic as systemd's socket has configured FlushPending=yes */
|
|
if !self.config.config_data().borrow().Socket.Accept {
|
|
self.flush_ports();
|
|
}
|
|
diff --git a/coms/socket/src/unit.rs b/coms/socket/src/unit.rs
|
|
index 8e33ee8..d96c258 100644
|
|
--- a/coms/socket/src/unit.rs
|
|
+++ b/coms/socket/src/unit.rs
|
|
@@ -115,6 +115,22 @@ impl SubUnit for SocketUnit {
|
|
Ok(())
|
|
}
|
|
|
|
+ fn trigger(&self, other: &String) {
|
|
+ let um = self.comm.um();
|
|
+ let service_state = um.get_subunit_state(other);
|
|
+ if [
|
|
+ "dead".to_string(),
|
|
+ "failed".to_string(),
|
|
+ "finalsigterm".to_string(),
|
|
+ "finalsigkill".to_string(),
|
|
+ "autorestart".to_string(),
|
|
+ ]
|
|
+ .contains(&service_state)
|
|
+ {
|
|
+ self.mng.enter_listening();
|
|
+ }
|
|
+ }
|
|
+
|
|
fn sigchld_events(&self, wait_status: WaitStatus) {
|
|
self.mng.sigchld_event(wait_status)
|
|
}
|
|
diff --git a/core/bin/unit/entry/uentry.rs b/core/bin/unit/entry/uentry.rs
|
|
index 307240b..f6b4db4 100644
|
|
--- a/core/bin/unit/entry/uentry.rs
|
|
+++ b/core/bin/unit/entry/uentry.rs
|
|
@@ -545,6 +545,11 @@ impl Unit {
|
|
self.config.clone()
|
|
}
|
|
|
|
+ pub(super) fn trigger(&self, other: &Self) {
|
|
+ let other_unit_id = other.id();
|
|
+ self.sub.trigger(other_unit_id);
|
|
+ }
|
|
+
|
|
pub(super) fn in_load_queue(&self) -> bool {
|
|
self.load.in_load_queue()
|
|
}
|
|
diff --git a/core/bin/unit/entry/unitx.rs b/core/bin/unit/entry/unitx.rs
|
|
index d9878f4..92b4ebb 100644
|
|
--- a/core/bin/unit/entry/unitx.rs
|
|
+++ b/core/bin/unit/entry/unitx.rs
|
|
@@ -106,7 +106,9 @@ impl UnitX {
|
|
self.0.sigchld_events(wait_status)
|
|
}
|
|
|
|
- pub(crate) fn trigger(&self, _other: &Self) {}
|
|
+ pub(crate) fn trigger(&self, other: &Self) {
|
|
+ self.0.trigger(other);
|
|
+ }
|
|
pub(crate) fn in_load_queue(&self) -> bool {
|
|
self.0.in_load_queue()
|
|
}
|
|
diff --git a/core/lib/unit/base.rs b/core/lib/unit/base.rs
|
|
index d279295..8d76cab 100644
|
|
--- a/core/lib/unit/base.rs
|
|
+++ b/core/lib/unit/base.rs
|
|
@@ -127,6 +127,9 @@ pub trait SubUnit: ReStation + UnitMngUtil {
|
|
Vec::new()
|
|
}
|
|
|
|
+ ///
|
|
+ fn trigger(&self, _other: &String) {}
|
|
+
|
|
///Get the the unit state
|
|
///
|
|
/// Every sub unit can define self states and map to [`UnitActiveState`]
|
|
--
|
|
2.30.2
|
|
|