forked from nginx/unit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools/unitctl: Enable Multi Socket Support
This commit refactors the CLI code to accept multiple instances of the control socket flag. All subcommands except for edit and save now support being run against multiple specified instances of unitd. * control_socket_addresses CLI field is now a vector * centralize error related logic into the error module * wait_for_socket now returns a vector of sockets. all sockets in vector are waited upon and validated * extraneous code is removed * applications, execute, import, listeners, and status commands all run against N control sockets now * edit and save commands return error when run against a single control socket Signed-off-by: Ava Hahn <[email protected]>
- Loading branch information
Showing
12 changed files
with
282 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,46 @@ | ||
use crate::unitctl::{ApplicationArgs, ApplicationCommands, UnitCtl}; | ||
use crate::{wait, UnitctlError}; | ||
use crate::{wait, UnitctlError, eprint_error}; | ||
use crate::requests::send_empty_body_deserialize_response; | ||
use unit_client_rs::unit_client::UnitClient; | ||
|
||
pub(crate) async fn cmd(cli: &UnitCtl, args: &ApplicationArgs) -> Result<(), UnitctlError> { | ||
let control_socket = wait::wait_for_socket(cli).await?; | ||
let client = UnitClient::new(control_socket); | ||
let clients: Vec<UnitClient> = wait::wait_for_sockets(cli) | ||
.await? | ||
.into_iter() | ||
.map(|sock| UnitClient::new(sock)) | ||
.collect(); | ||
|
||
match &args.command { | ||
ApplicationCommands::Reload { ref name } => client | ||
.restart_application(name) | ||
.await | ||
.map_err(|e| UnitctlError::UnitClientError { source: *e }) | ||
.and_then(|r| args.output_format.write_to_stdout(&r)), | ||
for client in clients { | ||
let _ = match &args.command { | ||
ApplicationCommands::Reload { ref name } => client | ||
.restart_application(name) | ||
.await | ||
.map_err(|e| UnitctlError::UnitClientError { source: *e }) | ||
.and_then(|r| args.output_format.write_to_stdout(&r)), | ||
|
||
/* we should be able to use this but the openapi generator library | ||
* is fundamentally incorrect and provides a broken API for the | ||
* applications endpoint. | ||
ApplicationCommands::List {} => client | ||
.applications() | ||
.await | ||
.map_err(|e| UnitctlError::UnitClientError { source: *e }) | ||
.and_then(|response| args.output_format.write_to_stdout(&response)),*/ | ||
/* we should be able to use this but the openapi generator library | ||
* is fundamentally incorrect and provides a broken API for the | ||
* applications endpoint. | ||
ApplicationCommands::List {} => client | ||
.applications() | ||
.await | ||
.map_err(|e| UnitctlError::UnitClientError { source: *e }) | ||
.and_then(|response| args.output_format.write_to_stdout(&response)),*/ | ||
|
||
ApplicationCommands::List {} => { | ||
args.output_format.write_to_stdout( | ||
&send_empty_body_deserialize_response( | ||
&client, | ||
"GET", | ||
"/config/applications", | ||
).await? | ||
) | ||
}, | ||
ApplicationCommands::List {} => { | ||
args.output_format.write_to_stdout( | ||
&send_empty_body_deserialize_response( | ||
&client, | ||
"GET", | ||
"/config/applications", | ||
).await? | ||
) | ||
}, | ||
}.map_err(|error| { | ||
eprint_error(&error); | ||
std::process::exit(error.exit_code()); | ||
}); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
use crate::unitctl::UnitCtl; | ||
use crate::wait; | ||
use crate::{OutputFormat, UnitctlError}; | ||
use crate::{OutputFormat, UnitctlError, eprint_error}; | ||
use unit_client_rs::unit_client::UnitClient; | ||
|
||
pub async fn cmd(cli: &UnitCtl, output_format: OutputFormat) -> Result<(), UnitctlError> { | ||
let control_socket = wait::wait_for_socket(cli).await?; | ||
let client = UnitClient::new(control_socket); | ||
client | ||
.listeners() | ||
.await | ||
.map_err(|e| UnitctlError::UnitClientError { source: *e }) | ||
.and_then(|response| output_format.write_to_stdout(&response)) | ||
let socks = wait::wait_for_sockets(cli) | ||
.await?; | ||
let clients = socks.iter() | ||
.map(|sock| UnitClient::new(sock.clone())); | ||
|
||
for client in clients { | ||
let _ = client.listeners() | ||
.await | ||
.map_err(|e| { | ||
let err = UnitctlError::UnitClientError { source: *e }; | ||
eprint_error(&err); | ||
std::process::exit(err.exit_code()); | ||
}) | ||
.and_then(|response| output_format.write_to_stdout(&response)); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
use crate::unitctl::UnitCtl; | ||
use crate::wait; | ||
use crate::{OutputFormat, UnitctlError}; | ||
use crate::{OutputFormat, UnitctlError, eprint_error}; | ||
use unit_client_rs::unit_client::UnitClient; | ||
|
||
pub async fn cmd(cli: &UnitCtl, output_format: OutputFormat) -> Result<(), UnitctlError> { | ||
let control_socket = wait::wait_for_socket(cli).await?; | ||
let client = UnitClient::new(control_socket); | ||
client | ||
.status() | ||
.await | ||
.map_err(|e| UnitctlError::UnitClientError { source: *e }) | ||
.and_then(|response| output_format.write_to_stdout(&response)) | ||
let socks = wait::wait_for_sockets(cli) | ||
.await?; | ||
let clients = socks.iter() | ||
.map(|sock| UnitClient::new(sock.clone())); | ||
|
||
for client in clients { | ||
let _ = client.status() | ||
.await | ||
.map_err(|e| { | ||
let err = UnitctlError::UnitClientError { source: *e }; | ||
eprint_error(&err); | ||
std::process::exit(err.exit_code()); | ||
}) | ||
.and_then(|response| output_format.write_to_stdout(&response)); | ||
} | ||
Ok(()) | ||
} |
Oops, something went wrong.