Skip to content

Commit

Permalink
Fix main process upgrade and shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi DEMOLIS <eloi.demolis@clever-cloud.com>
  • Loading branch information
Wonshtrum committed Sep 5, 2022
1 parent ca8fd82 commit e5f9b1d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
16 changes: 8 additions & 8 deletions bin/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,14 @@ impl CommandServer {
request_identifier,
response,
} => {
self.notify_advancement_to_client(request_identifier, response)
.await
let success_result = self.notify_advancement_to_client(request_identifier, response.clone())
.await;
if let Response::Ok(Success::UpgradeMain(_)) = response {
std::thread::sleep(std::time::Duration::from_secs(2));
info!("shutting down old main");
std::process::exit(0);
};
success_result
}
CommandMessage::MasterStop => {
info!("stopping main process");
Expand All @@ -361,12 +367,6 @@ impl CommandServer {

// perform shutdowns
match order_success {
Success::UpgradeMain(_) => {
// the main process has to shutdown after the other has launched successfully
//FIXME: should do some cleanup before exiting
std::thread::sleep(std::time::Duration::from_secs(2));
std::process::exit(0);
}
Success::MasterStop => {
// breaking the loop brings run() to return and ends Sōzu
// shouldn't we have the same break for both shutdowns?
Expand Down
6 changes: 3 additions & 3 deletions bin/src/command/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,12 @@ impl CommandServer {

let upgrade_data = self.generate_upgrade_data();

let (new_main_pid, mut channel) =
let (new_main_pid, mut fork_confirmation_channel) =
fork_main_into_new_main(self.executable_path.clone(), upgrade_data)
.with_context(|| "Could not start a new main process")?;

channel.set_blocking(true);
let received_ok_from_new_process = channel.read_message();
fork_confirmation_channel.set_blocking(true);
let received_ok_from_new_process = fork_confirmation_channel.read_message();
debug!("upgrade channel sent {:?}", received_ok_from_new_process);

// signaling the accept loop that it should stop
Expand Down
5 changes: 2 additions & 3 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
sync::mpsc,
sync::{Arc, Mutex},
thread,
time::Duration,
};

use anyhow::{self, bail, Context};
Expand Down Expand Up @@ -298,8 +297,8 @@ impl CommandManager {

// Reconnect to the new main
println!("Reconnecting to new main process...");
// self.channel = create_channel(&self.config)
// .with_context(|| "could not reconnect to the command unix socket")?;
self.channel = create_channel(&self.config)
.with_context(|| "could not reconnect to the command unix socket")?;

// Do a rolling restart of the workers
let running_workers = workers
Expand Down

0 comments on commit e5f9b1d

Please sign in to comment.