aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornotgne22021-01-29 05:22:07 -0700
committernotgne22021-02-09 02:55:26 -0700
commite798bb7d834cd786a49041a61c1a222ecdc96483 (patch)
treec2702aee8dad6aad3f1b3979bb4cd14e1a963396 /src
parentc32d25ec28adafec90c43eb19dc0ecd635f4b746 (diff)
Still wait for activation command to end even in cases of errors
Diffstat (limited to 'src')
-rw-r--r--src/deploy.rs113
1 files changed, 70 insertions, 43 deletions
diff --git a/src/deploy.rs b/src/deploy.rs
index 00c97f4..aba41f2 100644
--- a/src/deploy.rs
+++ b/src/deploy.rs
@@ -138,6 +138,57 @@ fn test_wait_command_builder() {
}
#[derive(Error, Debug)]
+pub enum ConfirmProfileError {
+ #[error("Failed to run confirmation command over SSH (the server should roll back): {0}")]
+ SSHConfirmError(std::io::Error),
+ #[error(
+ "Confirming activation over SSH resulted in a bad exit code (the server should roll back): {0:?}"
+ )]
+ SSHConfirmExitError(Option<i32>),
+}
+
+pub async fn confirm_profile(
+ deploy_data: &super::DeployData<'_>,
+ deploy_defs: &super::DeployDefs,
+ hostname: &str,
+ temp_path: Cow<'_, str>,
+) -> Result<(), ConfirmProfileError> {
+ let mut c = Command::new("ssh");
+ let mut ssh_confirm_command = c.arg(format!("ssh://{}@{}", deploy_defs.ssh_user, hostname));
+
+ for ssh_opt in &deploy_data.merged_settings.ssh_opts {
+ ssh_confirm_command = ssh_confirm_command.arg(ssh_opt);
+ }
+
+ let lock_path = super::make_lock_path(&temp_path, &deploy_data.profile.profile_settings.path);
+
+ let mut confirm_command = format!("rm {}", lock_path);
+ if let Some(sudo_cmd) = &deploy_defs.sudo {
+ confirm_command = format!("{} {}", sudo_cmd, confirm_command);
+ }
+
+ debug!(
+ "Attempting to run command to confirm deployment: {}",
+ confirm_command
+ );
+
+ let ssh_confirm_exit_status = ssh_confirm_command
+ .arg(confirm_command)
+ .status()
+ .await
+ .map_err(ConfirmProfileError::SSHConfirmError)?;
+
+ match ssh_confirm_exit_status.code() {
+ Some(0) => (),
+ a => return Err(ConfirmProfileError::SSHConfirmExitError(a)),
+ };
+
+ info!("Deployment confirmed.");
+
+ Ok(())
+}
+
+#[derive(Error, Debug)]
pub enum DeployProfileError {
#[error("Failed to spawn activation command over SSH: {0}")]
SSHSpawnActivateError(std::io::Error),
@@ -152,12 +203,8 @@ pub enum DeployProfileError {
#[error("Waiting over SSH resulted in a bad exit code: {0:?}")]
SSHWaitExitError(Option<i32>),
- #[error("Failed to run confirmation command over SSH (the server should roll back): {0}")]
- SSHConfirmError(std::io::Error),
- #[error(
- "Confirming activation over SSH resulted in a bad exit code (the server should roll back): {0:?}"
- )]
- SSHConfirmExitError(Option<i32>),
+ #[error("Error confirming deployment: {0}")]
+ ConfirmError(#[from] ConfirmProfileError),
}
pub async fn deploy_profile(
@@ -250,22 +297,33 @@ pub async fn deploy_profile(
let (send_activated, recv_activated) = tokio::sync::oneshot::channel();
tokio::spawn(async move {
- send_activate
- .send(ssh_activate.wait_with_output().await)
- .unwrap();
+ let o = ssh_activate.wait_with_output().await;
+
+ // Don't event unless somethis is bad
+ // TODO: maybe replace the structure with our own
+ match o {
+ Ok(ref x) => match x.status.code() {
+ Some(0) => (),
+ _ => send_activate.send(o).unwrap(),
+ },
+ _ => send_activate.send(o).unwrap(),
+ };
+
send_activated.send(()).unwrap();
});
tokio::select! {
x = ssh_wait_command.arg(self_wait_command).status() => {
+ debug!("Wait command ended");
match x.map_err(DeployProfileError::SSHWaitError)?.code() {
Some(0) => (),
a => return Err(DeployProfileError::SSHWaitExitError(a)),
};
},
x = recv_activate => {
+ debug!("Activate command exited with an error");
match x.unwrap().map_err(DeployProfileError::SSHActivateError)?.status.code() {
- Some(0) => (),
+ Some(0) => unreachable!(), // We know it is an error, see a comment above
a => return Err(DeployProfileError::SSHActivateExitError(a)),
};
},
@@ -273,40 +331,9 @@ pub async fn deploy_profile(
info!("Success activating, attempting to confirm activation");
- let mut c = Command::new("ssh");
- let mut ssh_confirm_command = c.arg(format!("ssh://{}@{}", deploy_defs.ssh_user, hostname));
-
- for ssh_opt in &deploy_data.merged_settings.ssh_opts {
- ssh_confirm_command = ssh_confirm_command.arg(ssh_opt);
- }
-
- let lock_path =
- super::make_lock_path(&temp_path, &deploy_data.profile.profile_settings.path);
-
- let mut confirm_command = format!("rm {}", lock_path);
- if let Some(sudo_cmd) = &deploy_defs.sudo {
- confirm_command = format!("{} {}", sudo_cmd, confirm_command);
- }
-
- debug!(
- "Attempting to run command to confirm deployment: {}",
- confirm_command
- );
-
- let ssh_confirm_exit_status = ssh_confirm_command
- .arg(confirm_command)
- .status()
- .await
- .map_err(DeployProfileError::SSHConfirmError)?;
-
- match ssh_confirm_exit_status.code() {
- Some(0) => (),
- a => return Err(DeployProfileError::SSHConfirmExitError(a)),
- };
-
- info!("Deployment confirmed.");
-
+ let c = confirm_profile(deploy_data, deploy_defs, hostname, temp_path).await;
recv_activated.await.unwrap();
+ c?;
}
Ok(())