Skip to content

Commit 19abe0a

Browse files
committed
Bump version and improve shadow sync robustness
1 parent 81e137e commit 19abe0a

4 files changed

Lines changed: 21 additions & 11 deletions

File tree

ansible/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# defaults for unifi-on-boot ansible role
33

44
# Version of unifi-on-boot to install
5-
unifi_on_boot_version: "1.1.2"
5+
unifi_on_boot_version: "1.1.3"
66

77
# GitHub release download URL
88
unifi_on_boot_github_repo: "unredacted/unifi-on-boot"

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: unifi-on-boot
2-
Version: 1.1.2
2+
Version: 1.1.3
33
Architecture: all
44
Maintainer: Unredacted <contact@unredacted.org>
55
Depends: bash, systemd

debian/unifi-on-boot

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ LOG_FILE="/var/log/unifi-on-boot.log"
1111
SERVICE_NAME="unifi-on-boot"
1212
SHADOW_CONF="/data/unifi-on-boot/shadow.conf"
1313
SKIP_SHADOW=false
14+
SSH_OPTS="-o ConnectTimeout=5 -o StrictHostKeyChecking=no -o BatchMode=yes"
15+
SYNC_TIMEOUT=120 # hard deadline for each remote operation (seconds)
1416

1517
# Parse command line arguments
1618
while [[ $# -gt 0 ]]; do
@@ -61,6 +63,12 @@ sync_shadow_gateway() {
6163
return 0
6264
fi
6365

66+
# Verify SSH connectivity before committing to a full sync
67+
if ! timeout 10 ssh $SSH_OPTS "${shadow_user}@${shadow_ip}" true >/dev/null 2>&1; then
68+
log "WARNING: Shadow gateway at ${shadow_ip} is reachable but SSH failed (skipping sync)"
69+
return 0
70+
fi
71+
6472
log "Shadow gateway detected at ${shadow_ip}, starting sync..."
6573

6674
# Ensure rsync is installed locally
@@ -73,9 +81,9 @@ sync_shadow_gateway() {
7381
fi
7482

7583
# Ensure rsync is installed on shadow
76-
if ! ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "${shadow_user}@${shadow_ip}" "command -v rsync" >/dev/null 2>&1; then
84+
if ! timeout "$SYNC_TIMEOUT" ssh $SSH_OPTS "${shadow_user}@${shadow_ip}" "command -v rsync" >/dev/null 2>&1; then
7785
log "Installing rsync on shadow gateway..."
78-
if ! ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "${shadow_user}@${shadow_ip}" \
86+
if ! timeout "$SYNC_TIMEOUT" ssh $SSH_OPTS "${shadow_user}@${shadow_ip}" \
7987
"DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1 && apt-get install -y rsync >/dev/null 2>&1"; then
8088
log "ERROR: Failed to install rsync on shadow gateway, cannot sync"
8189
return 1
@@ -84,7 +92,7 @@ sync_shadow_gateway() {
8492

8593
# Sync /data/on_boot.d/ to shadow (--delete ensures exact mirror)
8694
log "Syncing /data/on_boot.d/ to shadow gateway..."
87-
if rsync -avz --delete -e "ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no" \
95+
if timeout "$SYNC_TIMEOUT" rsync -avz --delete -e "ssh $SSH_OPTS" \
8896
"${BOOT_DIR}/" "${shadow_user}@${shadow_ip}:${BOOT_DIR}/" 2>&1 | tee -a "$LOG_FILE"; then
8997
log "Successfully synced /data/on_boot.d/ to shadow gateway"
9098
else
@@ -93,15 +101,15 @@ sync_shadow_gateway() {
93101
fi
94102

95103
# Ensure unifi-on-boot is installed on shadow
96-
if ! ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "${shadow_user}@${shadow_ip}" \
104+
if ! timeout "$SYNC_TIMEOUT" ssh $SSH_OPTS "${shadow_user}@${shadow_ip}" \
97105
"dpkg -l unifi-on-boot 2>/dev/null | grep -q '^ii'" 2>/dev/null; then
98106
log "Installing unifi-on-boot on shadow gateway..."
99107

100108
local deb_path="/data/unifi-on-boot/unifi-on-boot.deb"
101109
if [ -f "$deb_path" ]; then
102-
if scp -o ConnectTimeout=5 -o StrictHostKeyChecking=no \
110+
if timeout "$SYNC_TIMEOUT" scp $SSH_OPTS \
103111
"$deb_path" "${shadow_user}@${shadow_ip}:/tmp/unifi-on-boot.deb" 2>/dev/null && \
104-
ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "${shadow_user}@${shadow_ip}" \
112+
timeout "$SYNC_TIMEOUT" ssh $SSH_OPTS "${shadow_user}@${shadow_ip}" \
105113
"dpkg -i /tmp/unifi-on-boot.deb && rm -f /tmp/unifi-on-boot.deb" 2>&1 | tee -a "$LOG_FILE"; then
106114
log "Successfully installed unifi-on-boot on shadow gateway"
107115
else
@@ -116,7 +124,7 @@ sync_shadow_gateway() {
116124
# Run unifi-on-boot on shadow with --skip-shadow to prevent recursion
117125
# Note: we invoke the script directly (not via systemctl) so we can pass --skip-shadow
118126
log "Triggering unifi-on-boot on shadow gateway..."
119-
if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "${shadow_user}@${shadow_ip}" \
127+
if timeout "$SYNC_TIMEOUT" ssh $SSH_OPTS "${shadow_user}@${shadow_ip}" \
120128
"/usr/sbin/unifi-on-boot --skip-shadow" 2>&1 | tee -a "$LOG_FILE"; then
121129
log "Shadow gateway sync completed successfully"
122130
else
@@ -183,7 +191,8 @@ if [ "$fail_count" -gt 0 ]; then
183191
log "WARNING: ${fail_count} script(s) failed. Check log for details."
184192
fi
185193

186-
# Sync to shadow gateway after all scripts have run
187-
sync_shadow_gateway || log "WARNING: Shadow gateway sync encountered errors"
194+
# Sync to shadow gateway in the background — not boot-critical
195+
(sync_shadow_gateway || log "WARNING: Shadow gateway sync encountered errors") &
196+
disown
188197

189198
exit 0

debian/unifi-on-boot.service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ StartLimitBurst=3
99
Type=oneshot
1010
ExecStart=/usr/sbin/unifi-on-boot
1111
RemainAfterExit=yes
12+
TimeoutStartSec=300
1213
KillMode=mixed
1314
KillSignal=SIGTERM
1415
TimeoutStopSec=10

0 commit comments

Comments
 (0)