Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
feat: provide remove command
Browse files Browse the repository at this point in the history
Removes an added node, which will delete its data and log directories. The node is marked as
removed rather than actually being removed from the node registry just because the service number is
incremented by one each time a new node is added, so it might be a little odd if numbers were
missing in the sequence.
  • Loading branch information
jacderida committed Dec 5, 2023
1 parent 167c6dc commit 9bbeea6
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 56 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ clap = { version = "4.4.6", features = ["derive", "env"]}
colored = "2.0.4"
color-eyre = "~0.6"
indicatif = { version = "0.17.5", features = ["tokio"] }
libp2p = { version="0.53" , features = [] }
libp2p = { version = "0.53", features = [] }
libp2p-identity = { version="0.2.7", features = ["rand"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
service-manager = "0.5.1"
sn_node_rpc_client = "0.1.43"
sn_peers_acquisition = "0.1.10"
sn_peers_acquisition = { version = "0.1.10", features = ["network-contacts"] }
sn-releases = "0.1.1"
sysinfo = "0.29.10"
tokio = { version = "1.26", features = ["full"] }
Expand Down
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,33 @@ The command can run as many times as you like to repeatedly add more nodes.
### Start

- Command: `start`
- Description: Starts an installed `safenode` service.
- Description: Starts a `safenode` service.
- Options:
- `--peer-id`: Peer ID of the service to start. Optional.
- `--service-name`: Name of the service to start. Optional.
- Usage: `safenode-manager start [OPTIONS]`

This command must run as the root user on Linux/macOS and the Administrator user on Windows.

Running the command with no arguments will start every installed node that is not already running. The peer ID or service name can be used to start a specific service.
Running the command with no arguments will start every node that is not already running. The peer ID or service name can be used to start a specific service.

A peer ID will be assigned to a node after it is started for the first time.

### Status

- Command: `status`
- Description: Displays the status of installed services.
- Description: Displays the status of `safenode` services.
- Options:
- `--details`: Displays more detailed information. Boolean flag.
- Usage: `safenode-manager status [OPTIONS]`

### Stop

- Command: `stop`
- Description: Stops an installed `safenode` service.
- Description: Stops a `safenode` service.
- Options:
- `--peer_id`: Peer ID of the service to stop. Optional.
- `--service_name`: Name of the service to stop. Optional.
- `--peer-id`: Peer ID of the service to stop. Optional.
- `--service-name`: Name of the service to stop. Optional.
- Usage: `safenode-manager stop [OPTIONS]`

This command must run as the root user on Linux/macOS and the Administrator user on Windows.
Expand All @@ -69,6 +69,20 @@ Running the command with no arguments will stop every installed node that is not

If started again, the node's data and peer ID will be retained.

### Remove

- Command: `remove`
- Description: Removes a `safenode` service.
- Options:
- `--peer-id`: Peer ID of the service to remove. Optional.
- `--service-name`: Name of the service to remove. Optional.
- `--keep-directories`: Set this flag to keep the node's data and log directories. Optional.
- Usage: `safenode-manager remove [OPTIONS]`

This command must run as the root user on Linux/macOS and the Administrator user on Windows.

Removes the node and its data/log directories. The node must be stopped before running this command.

## License

This Safe Network repository is licensed under the General Public License (GPL), version 3 ([LICENSE](LICENSE) http://www.gnu.org/licenses/gpl-3.0.en.html).
Expand Down
32 changes: 16 additions & 16 deletions src/add_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ pub async fn add(
status: NodeStatus::Added,
pid: None,
peer_id: None,
log_dir_path: service_log_dir_path.clone(),
data_dir_path: service_data_dir_path.clone(),
log_dir_path: Some(service_log_dir_path.clone()),
data_dir_path: Some(service_data_dir_path.clone()),
});

node_number += 1;
Expand Down Expand Up @@ -295,11 +295,11 @@ mod tests {
assert_eq!(node_registry.nodes[0].rpc_port, 8081);
assert_eq!(
node_registry.nodes[0].log_dir_path,
node_logs_dir.to_path_buf().join("safenode1")
Some(node_logs_dir.to_path_buf().join("safenode1"))
);
assert_eq!(
node_registry.nodes[0].data_dir_path,
node_data_dir.to_path_buf().join("safenode1")
Some(node_data_dir.to_path_buf().join("safenode1"))
);
assert_matches!(node_registry.nodes[0].status, NodeStatus::Added);

Expand Down Expand Up @@ -471,11 +471,11 @@ mod tests {
assert_eq!(node_registry.nodes[0].rpc_port, 8081);
assert_eq!(
node_registry.nodes[0].log_dir_path,
node_logs_dir.to_path_buf().join("safenode1")
Some(node_logs_dir.to_path_buf().join("safenode1"))
);
assert_eq!(
node_registry.nodes[0].data_dir_path,
node_data_dir.to_path_buf().join("safenode1")
Some(node_data_dir.to_path_buf().join("safenode1"))
);
assert_matches!(node_registry.nodes[0].status, NodeStatus::Added);
assert_eq!(node_registry.nodes[1].version, latest_version);
Expand All @@ -486,11 +486,11 @@ mod tests {
assert_eq!(node_registry.nodes[1].rpc_port, 8083);
assert_eq!(
node_registry.nodes[1].log_dir_path,
node_logs_dir.to_path_buf().join("safenode2")
Some(node_logs_dir.to_path_buf().join("safenode2"))
);
assert_eq!(
node_registry.nodes[1].data_dir_path,
node_data_dir.to_path_buf().join("safenode2")
Some(node_data_dir.to_path_buf().join("safenode2"))
);
assert_matches!(node_registry.nodes[1].status, NodeStatus::Added);
assert_eq!(node_registry.nodes[2].version, latest_version);
Expand All @@ -501,11 +501,11 @@ mod tests {
assert_eq!(node_registry.nodes[2].rpc_port, 8085);
assert_eq!(
node_registry.nodes[2].log_dir_path,
node_logs_dir.to_path_buf().join("safenode3")
Some(node_logs_dir.to_path_buf().join("safenode3"))
);
assert_eq!(
node_registry.nodes[2].data_dir_path,
node_data_dir.to_path_buf().join("safenode3")
Some(node_data_dir.to_path_buf().join("safenode3"))
);
assert_matches!(node_registry.nodes[2].status, NodeStatus::Added);

Expand Down Expand Up @@ -614,11 +614,11 @@ mod tests {
assert_eq!(node_registry.nodes[0].rpc_port, 8081);
assert_eq!(
node_registry.nodes[0].log_dir_path,
node_logs_dir.to_path_buf().join("safenode1")
Some(node_logs_dir.to_path_buf().join("safenode1"))
);
assert_eq!(
node_registry.nodes[0].data_dir_path,
node_data_dir.to_path_buf().join("safenode1")
Some(node_data_dir.to_path_buf().join("safenode1"))
);
assert_matches!(node_registry.nodes[0].status, NodeStatus::Added);

Expand All @@ -642,8 +642,8 @@ mod tests {
status: NodeStatus::Added,
pid: None,
peer_id: None,
log_dir_path: PathBuf::from("/var/log/safenode/safenode1"),
data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"),
log_dir_path: Some(PathBuf::from("/var/log/safenode/safenode1")),
data_dir_path: Some(PathBuf::from("/var/safenode-manager/services/safenode1")),
}],
};
let temp_dir = assert_fs::TempDir::new()?;
Expand Down Expand Up @@ -746,11 +746,11 @@ mod tests {
assert_eq!(node_registry.nodes[1].rpc_port, 8083);
assert_eq!(
node_registry.nodes[1].log_dir_path,
node_logs_dir.to_path_buf().join("safenode2")
Some(node_logs_dir.to_path_buf().join("safenode2"))
);
assert_eq!(
node_registry.nodes[1].data_dir_path,
node_data_dir.to_path_buf().join("safenode2")
Some(node_data_dir.to_path_buf().join("safenode2"))
);
assert_matches!(node_registry.nodes[0].status, NodeStatus::Added);

Expand Down
Loading

0 comments on commit 9bbeea6

Please sign in to comment.