Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 26, 2025

When Tailscale restarts during script execution, SSH sessions are terminated, leaving the update incomplete. This is particularly problematic when enabling Tailscale SSH or running over unstable connections.

Implementation

New --background flag detaches script execution from SSH session:

  • Copies script to /tmp/update-tailscale-wrapper.sh for execution independence
  • Persists user preferences and flags to /tmp/tailscale-update.env
  • Re-invokes with --wrapped flag via nohup/setsid
  • Logs to /tmp/tailscale-update.log for monitoring

Execution flow:

./update-tailscale.sh --background --ssh --force
# Script saves state, backgrounds itself, exits
# Wrapper continues in background, loads state, completes update
# Cleanup removes wrapper files on success

# Monitor from another session:
tail -f /tmp/tailscale-update.log

Modified behavior in wrapped mode:

  • Skips interactive prompts (uses saved preferences)
  • Skips script update check (already running from copy)
  • Adds cleanup of wrapper files in invoke_outro()

Security & Compatibility

  • Path validation via case patterns prevents traversal attacks
  • Portable script path detection with BusyBox fallback
  • POSIX sh compatible (OpenWrt ash)
  • No external dependencies beyond nohup/setsid

Documentation

  • Added flag to help and arguments table
  • Usage example in README
  • Recommendation in Tailscale SSH section
Original prompt

We need an wrapper to make sure that the script wont terminate when Tailscale restarts (and the SSH session is killed). Maybe the script can copy itself to temp and load a previous created env file with all variables given by user? The wrapper needs to work on OpenWrt.

Create a new branch "add-background-exec"


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add wrapper script to ensure execution on Tailscale restart Add background execution wrapper to prevent SSH disconnection during Tailscale restarts Oct 26, 2025
Copilot AI requested a review from Admonstrator October 26, 2025 15:19
Copilot finished work on behalf of Admonstrator October 26, 2025 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants