Merge branch 'main' into hoverbear/ds-411-install-should-detect-existing

This commit is contained in:
Ana Hobden 2022-11-09 15:23:45 -08:00
commit 6ff452420b
6 changed files with 85 additions and 14 deletions

View file

@ -82,6 +82,33 @@ jobs:
path: | path: |
result/bin/harmonic result/bin/harmonic
RunX86Linux:
runs-on: ubuntu-latest
needs: BuildX86Linux
steps:
- uses: actions/download-artifact@v3
with:
name: harmonic-x86_64-linux
- name: Set executable
run: chmod +x ./harmonic
- name: Initial install
run: sudo RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic install linux-multi --no-confirm
- name: Test run
run: |
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
nix run nixpkgs#fortune
- name: Initial uninstall
run: sudo RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic uninstall --no-confirm
- name: Repeated install
run: sudo RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic install linux-multi --no-confirm
- name: Repeated test run
run: |
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
nix run nixpkgs#fortune
- name: Repeated uninstall
run: sudo RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic uninstall --no-confirm
BuildX86Darwin: BuildX86Darwin:
runs-on: macos-latest runs-on: macos-latest
steps: steps:
@ -99,3 +126,30 @@ jobs:
name: harmonic-x86_64-darwin name: harmonic-x86_64-darwin
path: | path: |
result/bin/harmonic result/bin/harmonic
RunX86Darwin:
runs-on: macos-latest
needs: BuildX86Darwin
steps:
- uses: actions/download-artifact@v3
with:
name: harmonic-x86_64-darwin
- name: Set executable
run: chmod +x ./harmonic
- name: Initial install
run: sudo RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic install darwin-multi --no-confirm
- name: Test run
run: |
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
nix run nixpkgs#fortune
- name: Initial uninstall
run: sudo RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic uninstall --no-confirm
- name: Repeated install
run: sudo RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic install darwin-multi --no-confirm
- name: Repeated test run
run: |
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
nix run nixpkgs#fortune
- name: Repeated uninstall
run: sudo RUST_LOG=harmonic=trace RUST_BACKTRACE=full ./harmonic uninstall --no-confirm

View file

@ -132,6 +132,15 @@ impl Action for ConfigureNixDaemonService {
execute_command(Command::new("systemctl").arg("daemon-reload")) execute_command(Command::new("systemctl").arg("daemon-reload"))
.await .await
.map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?;
execute_command(
Command::new("systemctl")
.arg("enable")
.arg("--now")
.arg("nix-daemon.socket"),
)
.await
.map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?;
}, },
}; };
@ -181,11 +190,11 @@ impl Action for ConfigureNixDaemonService {
.map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?;
}, },
_ => { _ => {
execute_command(Command::new("systemctl").args(["disable", SOCKET_SRC])) execute_command(Command::new("systemctl").args(["disable", SOCKET_SRC, "--now"]))
.await .await
.map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?;
execute_command(Command::new("systemctl").args(["disable", SERVICE_SRC])) execute_command(Command::new("systemctl").args(["disable", SERVICE_SRC, "--now"]))
.await .await
.map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?; .map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?;

View file

@ -90,9 +90,13 @@ impl Action for StartSystemdUnit {
tracing::debug!("Stopping systemd unit"); tracing::debug!("Stopping systemd unit");
// TODO(@Hoverbear): Handle proxy vars // TODO(@Hoverbear): Handle proxy vars
execute_command(Command::new("systemctl").arg("stop").arg(format!("{unit}"))) execute_command(
.await Command::new("systemctl")
.map_err(|e| StartSystemdUnitError::Command(e).boxed())?; .arg("disable")
.arg(format!("{unit}")),
)
.await
.map_err(|e| StartSystemdUnitError::Command(e).boxed())?;
tracing::trace!("Stopped systemd unit"); tracing::trace!("Stopped systemd unit");
*action_state = ActionState::Completed; *action_state = ActionState::Completed;

View file

@ -101,11 +101,16 @@ impl CommandExecute for Install {
} }
if let Err(err) = install_plan.install().await { if let Err(err) = install_plan.install().await {
tracing::error!("{:?}", eyre!(err)); let error = eyre!(err).wrap_err("Install failure");
if !interaction::confirm(install_plan.describe_revert(explain)).await? { if !no_confirm {
interaction::clean_exit_with_message("Okay, didn't do anything! Bye!").await; tracing::error!("{:?}", error);
if !interaction::confirm(install_plan.describe_revert(explain)).await? {
interaction::clean_exit_with_message("Okay, didn't do anything! Bye!").await;
}
install_plan.revert().await?
} else {
return Err(error);
} }
install_plan.revert().await?
} }
Ok(ExitCode::SUCCESS) Ok(ExitCode::SUCCESS)

View file

@ -9,19 +9,19 @@ use crate::cli::CommandExecute;
/// Plan an install that can be repeated on an identical host later /// Plan an install that can be repeated on an identical host later
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
#[command(multicall = true)] #[command(args_conflicts_with_subcommands = true, arg_required_else_help = true)]
pub struct Plan { pub struct Plan {
#[clap(subcommand)] #[clap(subcommand)]
pub planner: Option<BuiltinPlanner>, pub planner: Option<BuiltinPlanner>,
#[clap(env = "HARMONIC_PLAN")] #[clap(env = "HARMONIC_PLAN")]
pub plan: PathBuf, pub output: PathBuf,
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl CommandExecute for Plan { impl CommandExecute for Plan {
#[tracing::instrument(skip_all, fields())] #[tracing::instrument(skip_all, fields())]
async fn execute(self) -> eyre::Result<ExitCode> { async fn execute(self) -> eyre::Result<ExitCode> {
let Self { planner, plan } = self; let Self { planner, output } = self;
let planner = match planner { let planner = match planner {
Some(planner) => planner, Some(planner) => planner,
@ -33,7 +33,7 @@ impl CommandExecute for Plan {
let install_plan = planner.plan().await.map_err(|e| eyre::eyre!(e))?; let install_plan = planner.plan().await.map_err(|e| eyre::eyre!(e))?;
let json = serde_json::to_string_pretty(&install_plan)?; let json = serde_json::to_string_pretty(&install_plan)?;
tokio::fs::write(plan, json) tokio::fs::write(output, json)
.await .await
.wrap_err("Writing plan")?; .wrap_err("Writing plan")?;

View file

@ -31,7 +31,6 @@ impl Planner for LinuxMulti {
Box::new(CreateDirectory::plan("/nix", None, None, 0o0755, true).await?), Box::new(CreateDirectory::plan("/nix", None, None, 0o0755, true).await?),
Box::new(ProvisionNix::plan(self.settings.clone()).await?), Box::new(ProvisionNix::plan(self.settings.clone()).await?),
Box::new(ConfigureNix::plan(self.settings).await?), Box::new(ConfigureNix::plan(self.settings).await?),
Box::new(StartSystemdUnit::plan("nix-daemon.socket".into()).await?),
], ],
}) })
} }