Skip to content

Commit 7563cf5

Browse files
bors[bot]jfroche
andauthored
Merge #81
81: terraform/nixos-rebuild: do not ignore deploy errors by default r=jfroche a=jfroche Co-authored-by: Jean-François Roche <jfroche@pyxel.be>
2 parents 78a91e9 + a82a84d commit 7563cf5

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

terraform/nixos-rebuild/deploy.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
set -uex -o pipefail
44

5-
if [ "$#" -ne 4 ]; then
6-
echo "USAGE: $0 NIXOS_SYSTEM TARGET_USER TARGET_HOST TARGET_PORT" >&2
5+
if [ "$#" -ne 5 ]; then
6+
echo "USAGE: $0 NIXOS_SYSTEM TARGET_USER TARGET_HOST TARGET_PORT IGNORE_SYSTEMD_ERRORS" >&2
77
exit 1
88
fi
99

1010
NIXOS_SYSTEM=$1
1111
TARGET_USER=$2
1212
TARGET_HOST=$3
1313
TARGET_PORT=$4
14+
IGNORE_SYSTEMD_ERRORS=$5
1415
shift 3
1516

1617
TARGET="${TARGET_USER}@${TARGET_HOST}"
@@ -47,5 +48,10 @@ switchCommand="nix-env -p /nix/var/nix/profiles/system --set $(printf "%q" "$NIX
4748
if [[ $TARGET_USER != "root" ]]; then
4849
switchCommand="sudo bash -c '$switchCommand'"
4950
fi
51+
deploy_status=0
5052
# shellcheck disable=SC2029
51-
ssh "${sshOpts[@]}" "$TARGET" "$switchCommand"
53+
ssh "${sshOpts[@]}" "$TARGET" "$switchCommand" || deploy_status="$?"
54+
if [[ $IGNORE_SYSTEMD_ERRORS == "true" && $deploy_status == "4" ]]; then
55+
exit 0
56+
fi
57+
exit "$deploy_status"

terraform/nixos-rebuild/main.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ resource "null_resource" "nixos-rebuild" {
66
environment = {
77
SSH_KEY = var.ssh_private_key
88
}
9-
10-
command = "${path.module}/deploy.sh ${var.nixos_system} ${var.target_user} ${var.target_host} ${var.target_port}"
9+
command = "${path.module}/deploy.sh ${var.nixos_system} ${var.target_user} ${var.target_host} ${var.target_port} ${var.ignore_systemd_errors}"
1110
}
1211
}

terraform/nixos-rebuild/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ variable "ssh_private_key" {
2525
description = "Content of private key used to connect to the target_host. If set to - no key is passed to openssh and ssh will back to its own configuration"
2626
default = "-"
2727
}
28+
29+
variable "ignore_systemd_errors" {
30+
type = bool
31+
description = "Ignore systemd errors happening during deploy"
32+
default = false
33+
}

0 commit comments

Comments
 (0)