Skip to content

Commit 8c7ff8d

Browse files
committed
refactor(agent): use restart_webserver for post-sync restart
Utilize the restart_webserver method to handle post-synchronization actions for restarting both httpd and nginx. Signed-off-by: Erdem Meydanli <[email protected]>
1 parent ea0b9c0 commit 8c7ff8d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/vtok_agent/src/agent/mngtok.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ impl ManagedToken {
477477
httpd::HttpdService::write_tls_entries(
478478
&path, uid, gid, &key_uri, cert_path,
479479
)?;
480-
None
480+
481+
restart_hint.then(|| PostSyncAction::RestartHttpd)
481482
}
482483
};
483484
Ok(post_action)

src/vtok_agent/src/agent/mod.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use crate::config;
99
use crate::gdata;
1010
use crate::imds;
1111
use crate::util::{
12-
interruptible_sleep, is_service_running, service_restart, service_start,
13-
SystemdError,
12+
interruptible_sleep, is_service_running, service_restart, service_start, SystemdError,
1413
};
1514
use crate::{enclave, enclave::P11neEnclave};
1615
use log::{debug, error, info, warn};
@@ -43,6 +42,7 @@ pub struct Agent {
4342

4443
#[derive(Debug, Hash, Eq, PartialEq)]
4544
pub enum PostSyncAction {
45+
RestartHttpd,
4646
RestartNginx,
4747
}
4848

@@ -162,15 +162,18 @@ impl PostSyncAction {
162162
options.sync_interval_secs
163163
);
164164
match self {
165-
Self::RestartNginx => Self::restart_nginx(options.reload_wait_ms),
165+
Self::RestartNginx => Self::restart_webserver("nginx.service", options.reload_wait_ms),
166+
Self::RestartHttpd => Self::restart_webserver("httpd.service", options.reload_wait_ms),
166167
}
167168
}
168169

169-
fn restart_nginx(wait_ms: u64) {
170-
info!("Restarting NGINX.");
170+
fn restart_webserver(service_name: &str, wait_ms: u64) {
171+
info!("Restarting {}.", service_name);
171172

172-
if let Ok(pid) = is_service_running("nginx.service") {
173+
if let Ok(pid) = is_service_running(service_name) {
173174
debug!("Sending SIGWINCH to PID={}", pid);
175+
//http://nginx.org/en/docs/control.html
176+
//https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop
174177
signal::kill(unistd::Pid::from_raw(pid), signal::Signal::SIGWINCH).unwrap_or_else(
175178
|err| {
176179
error!("Error sending SIGWINCH: {:?}", err);
@@ -179,11 +182,11 @@ impl PostSyncAction {
179182

180183
std::thread::sleep(Duration::from_millis(wait_ms));
181184
} else {
182-
info!("NGINX service is not running");
185+
info!("{} service is not running", service_name);
183186
}
184187

185-
service_restart("nginx.service").unwrap_or_else(|err| {
186-
error!("Unable to restart NGINX: {:?}", err);
188+
service_restart(service_name).unwrap_or_else(|err| {
189+
error!("Unable to restart {}: {:?}", service_name, err);
187190
});
188191
}
189-
}
192+
}

0 commit comments

Comments
 (0)