Skip to content

Commit d1b347c

Browse files
committed
revert reload feature
1 parent c82733e commit d1b347c

16 files changed

Lines changed: 23 additions & 260 deletions

File tree

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ horustctl --uds-folder-path /tmp stop myapp.toml
136136
137137
# Restart a service (stop then start)
138138
horustctl --uds-folder-path /tmp restart myapp.toml
139-
140-
# Reload service directories to pick up new service definitions
141-
horustctl --uds-folder-path /tmp reload
142139
```
143140

144141
## Quick tutorial

commands/src/client.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::proto::messages::horust_msg_message::MessageType;
22
use crate::proto::messages::{
3-
HorustMsgAllServicesStatusRequest, HorustMsgMessage, HorustMsgReloadRequest, HorustMsgRequest,
4-
HorustMsgRestartRequest, HorustMsgServiceChangeRequest, HorustMsgServiceStatusRequest,
5-
horust_msg_request, horust_msg_response,
3+
HorustMsgAllServicesStatusRequest, HorustMsgMessage, HorustMsgRequest, HorustMsgRestartRequest,
4+
HorustMsgServiceChangeRequest, HorustMsgServiceStatusRequest, horust_msg_request,
5+
horust_msg_response,
66
};
77
use crate::{HorustMsgServiceStatus, UdsConnectionHandler};
88
use anyhow::{Context, anyhow};
@@ -106,18 +106,6 @@ impl ClientHandler {
106106
}
107107
}
108108

109-
pub fn send_reload_request(&mut self) -> Result<(bool, Vec<String>)> {
110-
let msg = new_request(horust_msg_request::Request::ReloadRequest(
111-
HorustMsgReloadRequest {},
112-
));
113-
let response = send_and_receive(&mut self.uds_connection_handler, msg)?;
114-
if let horust_msg_response::Response::ReloadResponse(resp) = response {
115-
Ok((resp.accepted, resp.new_services))
116-
} else {
117-
bail!("Invalid response received: {:?}", response);
118-
}
119-
}
120-
121109
pub fn send_all_status_request(&mut self) -> Result<Vec<(String, HorustMsgServiceStatus)>> {
122110
let msg = new_request(horust_msg_request::Request::AllStatusRequest(
123111
HorustMsgAllServicesStatusRequest {},

commands/src/commands.proto

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ message HorustMsgRequest {
1212
HorustMsgServiceStatusRequest status_request = 1;
1313
HorustMsgServiceChangeRequest change_request = 2;
1414
HorustMsgRestartRequest restart_request = 3;
15-
HorustMsgReloadRequest reload_request = 4;
1615
HorustMsgAllServicesStatusRequest all_status_request = 5;
1716
}
1817
}
@@ -22,8 +21,7 @@ message HorustMsgResponse {
2221
HorustMsgServiceStatusResponse status_response = 2;
2322
HorustMsgServiceChangeResponse change_response = 3;
2423
HorustMsgRestartResponse restart_response = 4;
25-
HorustMsgReloadResponse reload_response = 5;
26-
HorustMsgAllServicesStatusResponse all_status_response = 6;
24+
HorustMsgAllServicesStatusResponse all_status_response = 5;
2725
}
2826
}
2927

@@ -61,15 +59,6 @@ message HorustMsgRestartResponse {
6159
bool accepted = 2;
6260
}
6361

64-
// Reload service directories for new service definitions.
65-
message HorustMsgReloadRequest {
66-
}
67-
68-
message HorustMsgReloadResponse {
69-
bool accepted = 1;
70-
repeated string new_services = 2;
71-
}
72-
7362
// Request status of all services.
7463
message HorustMsgAllServicesStatusRequest {
7564
}

commands/src/proto/messages.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub mod horust_msg_message {
1616
}
1717
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
1818
pub struct HorustMsgRequest {
19-
#[prost(oneof = "horust_msg_request::Request", tags = "1, 2, 3, 4, 5")]
19+
#[prost(oneof = "horust_msg_request::Request", tags = "1, 2, 3, 5")]
2020
pub request: ::core::option::Option<horust_msg_request::Request>,
2121
}
2222
/// Nested message and enum types in `HorustMsgRequest`.
@@ -29,15 +29,13 @@ pub mod horust_msg_request {
2929
ChangeRequest(super::HorustMsgServiceChangeRequest),
3030
#[prost(message, tag = "3")]
3131
RestartRequest(super::HorustMsgRestartRequest),
32-
#[prost(message, tag = "4")]
33-
ReloadRequest(super::HorustMsgReloadRequest),
3432
#[prost(message, tag = "5")]
3533
AllStatusRequest(super::HorustMsgAllServicesStatusRequest),
3634
}
3735
}
3836
#[derive(Clone, PartialEq, ::prost::Message)]
3937
pub struct HorustMsgResponse {
40-
#[prost(oneof = "horust_msg_response::Response", tags = "1, 2, 3, 4, 5, 6")]
38+
#[prost(oneof = "horust_msg_response::Response", tags = "1, 2, 3, 4, 5")]
4139
pub response: ::core::option::Option<horust_msg_response::Response>,
4240
}
4341
/// Nested message and enum types in `HorustMsgResponse`.
@@ -53,8 +51,6 @@ pub mod horust_msg_response {
5351
#[prost(message, tag = "4")]
5452
RestartResponse(super::HorustMsgRestartResponse),
5553
#[prost(message, tag = "5")]
56-
ReloadResponse(super::HorustMsgReloadResponse),
57-
#[prost(message, tag = "6")]
5854
AllStatusResponse(super::HorustMsgAllServicesStatusResponse),
5955
}
6056
}
@@ -103,16 +99,6 @@ pub struct HorustMsgRestartResponse {
10399
#[prost(bool, tag = "2")]
104100
pub accepted: bool,
105101
}
106-
/// Reload service directories for new service definitions.
107-
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
108-
pub struct HorustMsgReloadRequest {}
109-
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
110-
pub struct HorustMsgReloadResponse {
111-
#[prost(bool, tag = "1")]
112-
pub accepted: bool,
113-
#[prost(string, repeated, tag = "2")]
114-
pub new_services: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
115-
}
116102
/// Request status of all services.
117103
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
118104
pub struct HorustMsgAllServicesStatusRequest {}

commands/src/server.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::UdsConnectionHandler;
22
use crate::proto::messages::horust_msg_message::MessageType::Request;
33
use crate::proto::messages::{
4-
HorustMsgAllServicesStatusResponse, HorustMsgError, HorustMsgMessage, HorustMsgReloadResponse,
5-
HorustMsgRequest, HorustMsgResponse, HorustMsgRestartResponse, HorustMsgServiceChangeResponse,
4+
HorustMsgAllServicesStatusResponse, HorustMsgError, HorustMsgMessage, HorustMsgRequest,
5+
HorustMsgResponse, HorustMsgRestartResponse, HorustMsgServiceChangeResponse,
66
HorustMsgServiceStatus, HorustMsgServiceStatusEntry, HorustMsgServiceStatusResponse,
77
horust_msg_message, horust_msg_request, horust_msg_response,
88
};
@@ -100,15 +100,6 @@ pub trait CommandsHandlerTrait {
100100
)),
101101
}
102102
}
103-
horust_msg_request::Request::ReloadRequest(_) => {
104-
info!("Requested service reload");
105-
match self.reload_services() {
106-
Ok(new_services) => new_horust_msg_reload_response(true, new_services),
107-
Err(err) => new_horust_msg_error_response(format!(
108-
"Error from reload handler: {err}"
109-
)),
110-
}
111-
}
112103
horust_msg_request::Request::AllStatusRequest(_) => {
113104
info!("Requested all services status");
114105
let statuses = self.get_all_service_statuses();
@@ -129,7 +120,6 @@ pub trait CommandsHandlerTrait {
129120
new_status: HorustMsgServiceStatus,
130121
) -> Result<()>;
131122
fn restart_service(&self, service_name: &str) -> Result<()>;
132-
fn reload_services(&self) -> Result<Vec<String>>;
133123
fn get_all_service_statuses(&self) -> Vec<(String, HorustMsgServiceStatus)>;
134124
}
135125

@@ -179,15 +169,6 @@ fn new_horust_msg_restart_response(service_name: String, accepted: bool) -> Horu
179169
))
180170
}
181171

182-
fn new_horust_msg_reload_response(accepted: bool, new_services: Vec<String>) -> HorustMsgMessage {
183-
wrap_response(horust_msg_response::Response::ReloadResponse(
184-
HorustMsgReloadResponse {
185-
accepted,
186-
new_services,
187-
},
188-
))
189-
}
190-
191172
fn new_horust_msg_all_status_response(
192173
statuses: Vec<(String, HorustMsgServiceStatus)>,
193174
) -> HorustMsgMessage {

commands/tests/simple.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ impl CommandsHandlerTrait for MockCommandsHandler {
5555
Ok(())
5656
}
5757

58-
fn reload_services(&self) -> Result<Vec<String>> {
59-
Ok(vec!["new-service.toml".to_string()])
60-
}
61-
6258
fn get_all_service_statuses(&self) -> Vec<(String, HorustMsgServiceStatus)> {
6359
vec![
6460
("Running".to_string(), HorustMsgServiceStatus::Running),
@@ -162,35 +158,6 @@ fn test_restart_request() -> Result<()> {
162158
Ok(())
163159
}
164160

165-
#[test]
166-
fn test_reload_request() -> Result<()> {
167-
init();
168-
let socket_path: PathBuf = "/tmp/test_reload.sock".into();
169-
if socket_path.exists() {
170-
std::fs::remove_file(&socket_path)?;
171-
}
172-
let socket_path2 = socket_path.clone();
173-
let barrier = Arc::new(Barrier::new(2));
174-
let barrier2 = Arc::clone(&barrier);
175-
176-
let s_handle = thread::spawn(move || {
177-
let mut uds = MockCommandsHandler::new(socket_path2);
178-
barrier.wait();
179-
uds.accept().unwrap();
180-
});
181-
182-
let c_handle = thread::spawn(move || {
183-
barrier2.wait();
184-
let mut client = ClientHandler::new_client(&socket_path).unwrap();
185-
let (accepted, new_services) = client.send_reload_request().unwrap();
186-
assert!(accepted);
187-
assert_eq!(new_services, vec!["new-service.toml"]);
188-
});
189-
s_handle.join().unwrap();
190-
c_handle.join().unwrap();
191-
Ok(())
192-
}
193-
194161
#[test]
195162
fn test_all_status_request() -> Result<()> {
196163
init();

docs/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,6 @@ horustctl --uds-folder-path /tmp stop myapp.toml
339339

340340
# Restart a service (stop then start)
341341
horustctl --uds-folder-path /tmp restart myapp.toml
342-
343-
# Reload service directories to pick up new service definitions
344-
horustctl --uds-folder-path /tmp reload
345342
```
346343

347344
### Permissions

horust/src/horust/commands_handler.rs

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::horust::Event;
22
use crate::horust::bus::BusConnector;
3-
use crate::horust::formats::{Service, ServiceName, ServiceStatus, User};
3+
use crate::horust::formats::{ServiceName, ServiceStatus, User};
44
use anyhow::{Result, anyhow, bail};
55
use horust_commands_lib::{CommandsHandlerTrait, HorustMsgServiceStatus, UdsConnectionHandler};
66
use std::collections::HashMap;
@@ -14,10 +14,9 @@ pub fn spawn(
1414
bus: BusConnector<Event>,
1515
uds_path: PathBuf,
1616
services: Vec<(ServiceName, User)>,
17-
services_paths: Vec<PathBuf>,
1817
) -> JoinHandle<()> {
1918
thread::spawn(move || {
20-
let mut commands_handler = CommandsHandler::new(bus, uds_path, services, services_paths);
19+
let mut commands_handler = CommandsHandler::new(bus, uds_path, services);
2120
commands_handler.run();
2221
})
2322
}
@@ -28,7 +27,6 @@ struct CommandsHandler {
2827
service_users: HashMap<ServiceName, User>,
2928
uds_listener: UnixListener,
3029
uds_path: PathBuf,
31-
services_paths: Vec<PathBuf>,
3230
/// Peer UID of the current connection being handled (set during accept).
3331
current_peer_uid: Option<u32>,
3432
}
@@ -38,7 +36,6 @@ impl CommandsHandler {
3836
bus: BusConnector<Event>,
3937
uds_path: PathBuf,
4038
services: Vec<(ServiceName, User)>,
41-
services_paths: Vec<PathBuf>,
4239
) -> Self {
4340
let uds_listener = UnixListener::bind(&uds_path).unwrap();
4441
uds_listener.set_nonblocking(true).unwrap();
@@ -50,7 +47,6 @@ impl CommandsHandler {
5047
bus,
5148
uds_path,
5249
uds_listener,
53-
services_paths,
5450
service_users,
5551
current_peer_uid: None,
5652
services: services
@@ -69,12 +65,6 @@ impl CommandsHandler {
6965
*k = status;
7066
}
7167
}
72-
Event::ServiceAdded(ref service) => {
73-
self.services
74-
.insert(service.name.clone(), ServiceStatus::Initial);
75-
self.service_users
76-
.insert(service.name.clone(), service.user.clone());
77-
}
7868
Event::ShuttingDownInitiated(_) => {
7969
fs::remove_file(&self.uds_path).unwrap();
8070
return;
@@ -87,51 +77,6 @@ impl CommandsHandler {
8777
}
8878
}
8979

90-
fn load_services_from_paths(paths: &[PathBuf]) -> Result<Vec<Service>> {
91-
let mut services = Vec::new();
92-
for path in paths {
93-
if !path.exists() {
94-
continue;
95-
}
96-
let entries = if path.is_file() {
97-
vec![path.to_path_buf()]
98-
} else {
99-
fs::read_dir(path)?
100-
.filter_map(Result::ok)
101-
.map(|e| e.path())
102-
.filter(|p| {
103-
p.is_file()
104-
&& p.extension()
105-
.and_then(|ext| ext.to_str())
106-
.is_some_and(|ext| ext == "toml")
107-
})
108-
.collect()
109-
};
110-
for entry in entries {
111-
match Service::from_file(&entry) {
112-
Ok(mut svc) => {
113-
if svc.name.is_empty() {
114-
svc.name = entry
115-
.file_name()
116-
.unwrap_or_default()
117-
.to_string_lossy()
118-
.into_owned();
119-
}
120-
if svc.name.is_empty() {
121-
error!("Skipping service with empty name from {:?}", entry);
122-
continue;
123-
}
124-
services.push(svc);
125-
}
126-
Err(err) => {
127-
error!("Failed to load service from {:?}: {}", entry, err);
128-
}
129-
}
130-
}
131-
}
132-
Ok(services)
133-
}
134-
13580
/// Validate that a service exists and the peer has permission to manage it.
13681
fn validate_and_authorize(&self, service_name: &str) -> Result<()> {
13782
if !self.services.contains_key(service_name) {
@@ -262,18 +207,6 @@ impl CommandsHandlerTrait for CommandsHandler {
262207
.send_event(Event::Restart(service_name.to_string()));
263208
Ok(())
264209
}
265-
fn reload_services(&self) -> Result<Vec<String>> {
266-
let all_on_disk = Self::load_services_from_paths(&self.services_paths)?;
267-
let new_services: Vec<Service> = all_on_disk
268-
.into_iter()
269-
.filter(|s| !self.services.contains_key(&s.name))
270-
.collect();
271-
let new_names: Vec<String> = new_services.iter().map(|s| s.name.clone()).collect();
272-
for service in new_services {
273-
self.bus.send_event(Event::ServiceAdded(service));
274-
}
275-
Ok(new_names)
276-
}
277210
fn get_all_service_statuses(&self) -> Vec<(String, HorustMsgServiceStatus)> {
278211
let mut statuses: Vec<(String, HorustMsgServiceStatus)> = self
279212
.services
@@ -334,7 +267,6 @@ mod tests {
334267
service_users,
335268
uds_listener,
336269
uds_path: socket_path,
337-
services_paths: vec![],
338270
current_peer_uid: peer_uid,
339271
};
340272
handler

horust/src/horust/formats/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ pub enum Event {
2828
HealthCheck(ServiceName, HealthinessStatus),
2929
/// Request to restart a specific service (kill if alive, then set to Initial).
3030
Restart(ServiceName),
31-
/// A new service definition to add at runtime (consumed by supervisor, healthcheck, commands_handler).
32-
ServiceAdded(Service),
3331
}
3432

3533
impl Event {

0 commit comments

Comments
 (0)