Skip to content

Commit

Permalink
feat: node registry refresh searches for pids
Browse files Browse the repository at this point in the history
The node registry refresh is changed to determine if each service process is running by searching
for processes that have a binary running at a particular path. Since each node service has its own
copy of the binary, it is uniquely identified by the location of that binary.

The refresh is split into partial or full. In the partial case, we will only attempt to find the PID
by searching for a process by its binary path. If it is found, we set the new PID for the service
and set its status to `RUNNING`; if it's not found, we set the status to `STOPPED`. This mechanism
should be robust against user interference, e.g., if they manually start/stop processes by whatever
means. For a full refresh, we also connect to the node's RPC service to get information about
connected peers and listeners.

We will use partial refresh for commands like `start` and `stop`, to help us determine whether we
should attempt to start/stop services that were already running or not. These commands will
potentially operate over lots of services so we will avoid the RPC connections here.

Full refresh will be used when the `status` command runs.

Finally, I have also reassigned the connected peers data, and added/updated some of the log
information which I found useful to have during my testing.
  • Loading branch information
jacderida authored and joshuef committed Jun 23, 2024
1 parent 5d5c649 commit 30bfd66
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 215 deletions.
9 changes: 7 additions & 2 deletions node-launchpad/src/components/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ impl Home {
let now = Instant::now();
debug!("Refreshing node registry states on startup");
let mut node_registry = NodeRegistry::load(&get_node_registry_path()?)?;
sn_node_manager::refresh_node_registry(&mut node_registry, &ServiceController {}, false)
.await?;
sn_node_manager::refresh_node_registry(
&mut node_registry,
&ServiceController {},
false,
true,
)
.await?;
node_registry.save()?;
debug!("Node registry states refreshed in {:?}", now.elapsed());
home.load_node_registry_and_update_states()?;
Expand Down
3 changes: 1 addition & 2 deletions sn_node_manager/src/add_services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pub async fn add_node(
}

if !added_service_data.is_empty() {
info!("{} services has been added", added_service_data.len());
info!("Added {} services", added_service_data.len());
} else if !failed_service_data.is_empty() {
error!("Failed to add {} service(s)", failed_service_data.len());
}
Expand All @@ -316,7 +316,6 @@ pub async fn add_node(
println!("Services Added:");
for install in added_service_data.iter() {
println!(" {} {}", "✓".green(), install.0);

println!(" - Safenode path: {}", install.1);
println!(" - Data path: {}", install.2);
println!(" - Log path: {}", install.3);
Expand Down
1 change: 0 additions & 1 deletion sn_node_manager/src/add_services/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ mock! {
fn get_available_port(&self) -> ServiceControlResult<u16>;
fn install(&self, install_ctx: ServiceInstallCtx, user_mode: bool) -> ServiceControlResult<()>;
fn get_process_pid(&self, bin_path: &Path) -> ServiceControlResult<u32>;
fn is_service_process_running(&self, pid: u32) -> bool;
fn start(&self, service_name: &str, user_mode: bool) -> ServiceControlResult<()>;
fn stop(&self, service_name: &str, user_mode: bool) -> ServiceControlResult<()>;
fn uninstall(&self, service_name: &str, user_mode: bool) -> ServiceControlResult<()>;
Expand Down
1 change: 1 addition & 0 deletions sn_node_manager/src/bin/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,7 @@ async fn main() -> Result<()> {

fn get_log_builder(level: Level) -> Result<LogBuilder> {
let logging_targets = vec![
("sn_peers_acquisition".to_string(), level),
("sn_node_manager".to_string(), level),
("safenode_manager".to_string(), level),
("safenodemand".to_string(), level),
Expand Down
7 changes: 6 additions & 1 deletion sn_node_manager/src/cmd/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ pub async fn balance(
&mut node_registry,
&ServiceController {},
verbosity != VerbosityLevel::Minimal,
false,
)
.await?;

Expand Down Expand Up @@ -225,6 +226,7 @@ pub async fn remove(
&mut node_registry,
&ServiceController {},
verbosity != VerbosityLevel::Minimal,
false,
)
.await?;

Expand Down Expand Up @@ -309,12 +311,13 @@ pub async fn start(
&mut node_registry,
&ServiceController {},
verbosity != VerbosityLevel::Minimal,
false,
)
.await?;

let service_indices = get_services_for_ops(&node_registry, peer_ids, service_names)?;
if service_indices.is_empty() {
info!("Service indices is empty, no services were eligible to be started");
info!("No services are eligible to be started");
// This could be the case if all services are at `Removed` status.
if verbosity != VerbosityLevel::Minimal {
println!("No services were eligible to be started");
Expand Down Expand Up @@ -386,6 +389,7 @@ pub async fn stop(
&mut node_registry,
&ServiceController {},
verbosity != VerbosityLevel::Minimal,
false,
)
.await?;

Expand Down Expand Up @@ -459,6 +463,7 @@ pub async fn upgrade(
&mut node_registry,
&ServiceController {},
verbosity != VerbosityLevel::Minimal,
false,
)
.await?;

Expand Down
Loading

0 comments on commit 30bfd66

Please sign in to comment.