From 9fe622b885cb3c5048dec61422f97b3aa3050c45 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Fri, 17 Apr 2026 11:46:23 +0100 Subject: [PATCH] Defer QNAP autorun until encrypted volume unlocks (Fixes #1422) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QNAP's autorun.sh fires well before encrypted data volumes are unlocked, so the previous one-line entry that invoked start-pulse-agent.sh on the encrypted volume failed immediately — the wrapper did not exist yet, and the agent never started after reboot. Replace the entry with a backgrounded waiter that polls for the wrapper (every 2 s, up to 30 min) and execs it once the volume comes up. On unencrypted volumes the loop exits on the first check, so behaviour is unchanged. A timeout message is logged to /var/log/pulse-agent.log if the volume never unlocks within the window. The block is uninstall-safe: no internal blank lines, so the existing sed marker-to-blank-line range still removes it cleanly. --- scripts/install.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index e94218831..e4ee0ebe6 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1705,7 +1705,22 @@ EOF cat >> "$AUTORUN_PATH" <> /var/log/${AGENT_NAME}.log 2>&1 & +( + _pulse_wrapper="${WRAPPER_SCRIPT}" + _pulse_log="/var/log/${AGENT_NAME}.log" + _pulse_waited=0 + _pulse_wait_max=1800 + while [ ! -x "\$_pulse_wrapper" ] && [ "\$_pulse_waited" -lt "\$_pulse_wait_max" ]; do + sleep 2 + _pulse_waited=\$((_pulse_waited + 2)) + done + if [ -x "\$_pulse_wrapper" ]; then + [ "\$_pulse_waited" -gt 0 ] && echo "\$(date '+%Y-%m-%d %H:%M:%S') [pulse-agent-autorun] data volume available after \${_pulse_waited}s" >> "\$_pulse_log" + "\$_pulse_wrapper" >> "\$_pulse_log" 2>&1 + else + echo "\$(date '+%Y-%m-%d %H:%M:%S') [pulse-agent-autorun] timed out after \${_pulse_wait_max}s waiting for \$_pulse_wrapper" >> "\$_pulse_log" + fi +) & AUTORUNEOF chmod +x "$AUTORUN_PATH" @@ -1726,7 +1741,8 @@ AUTORUNEOF if [[ "$AUTORUN_CONFIGURED" != true ]]; then log_warn "Could not configure autorun.sh automatically." log_warn "To persist across reboots, add the following to your QNAP autorun.sh:" - log_warn " ${WRAPPER_SCRIPT} >> /var/log/${AGENT_NAME}.log 2>&1 &" + log_warn " (w='${WRAPPER_SCRIPT}'; i=0; while [ ! -x \"\$w\" ] && [ \$i -lt 1800 ]; do sleep 2; i=\$((i+2)); done; [ -x \"\$w\" ] && \"\$w\" >> /var/log/${AGENT_NAME}.log 2>&1) &" + log_warn "The waiter accommodates encrypted data volumes that unlock after autorun." log_warn "See: https://wiki.qnap.com/wiki/Running_Your_Own_Application_at_Startup" fi