Skip to content

Conversation

@dkaser
Copy link
Collaborator

@dkaser dkaser commented Nov 15, 2025

Summary by CodeRabbit

  • New Features

    • Startup now performs a verification step and will skip launching if checks fail.
    • Taildrop link is created automatically during startup when a valid location is available.
  • Bug Fixes

    • Installer now cleans up an existing legacy symlink before upgrading.
    • Removed redundant wrapper scripts to simplify scheduled maintenance.
  • Refactor

    • Restart and startup flows reorganized; shared utility code consolidated and restart timing adjusted.

@coderabbitai
Copy link

coderabbitai bot commented Nov 15, 2025

Walkthrough

Adds a pre-upgrade cleanup to remove an existing rc.tailscale symlink during install, centralizes utility scripts under /usr/local/php/unraid-tailscale-utils, removes legacy wrapper and update-settings scripts, moves cron and event symlinks to the new utility paths, and introduces a pre-startup PHP validation that creates the Taildrop link and gates daemon start.

Changes

Cohort / File(s) Summary
Installer / plugin template
plugin/plugin.j2
Adds logic to detect and force-remove an existing symlink /etc/rc.d/rc.tailscale (using -L) before running upgrade/install steps.
Install script adjustments
src/install/doinst.sh
Removes creation of the rc.tailscale symlink; updates etc/cron.daily/tailscale-daily to point to /usr/local/php/unraid-tailscale-utils/daily.sh; adds/updates event stopped symlink to point to ../restart.sh.
Removed legacy wrapper
src/usr/local/emhttp/plugins/tailscale/daily.sh
Deleted shell wrapper that executed daily.php; functionality moved to centralized utility location.
Restart behavior
src/usr/local/emhttp/plugins/tailscale/restart.sh
Changes sourced log helper to /usr/local/php/unraid-tailscale-utils/log.sh; schedules rc.tailscale restart via at instead of calling update-settings.sh.
Deleted configuration updater
src/usr/local/emhttp/plugins/tailscale/update-settings.sh
Script fully removed; prior Taildrop setup and pre-startup invocation migrated into centralized utilities.
Daemon init with validation
src/usr/local/etc/rc.d/rc.tailscale
Sources centralized log helper; invokes /usr/local/php/unraid-tailscale-utils/pre-startup.php before starting tailscaled and aborts start if the check fails.
Centralized utilities added/changed
src/usr/local/php/unraid-tailscale-utils/daily.sh, src/usr/local/php/unraid-tailscale-utils/pre-startup.php, src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php
Adds daily.sh wrapper calling daily.php; pre-startup.php now calls System::createTaildropLink() and returns exit codes (0 to allow start, 1 to abort); adds System::createTaildropLink(Config $config) to validate Taildrop dir, ensure parent exists, remove stale link, create symlink, and log outcomes.

Sequence Diagram(s)

sequenceDiagram
    participant Installer
    participant rc.tailscale
    participant preStartup as pre-startup.php
    participant System
    participant tailscaled

    rect rgb(250,250,240)
    note over Installer: Install-time cleanup
    Installer->>Installer: if -L /etc/rc.d/rc.tailscale then rm -f symlink
    end

    rect rgb(230,245,255)
    note over rc.tailscale: Runtime startup with validation
    rc.tailscale->>preStartup: invoke pre-startup.php
    preStartup->>System: createTaildropLink(config)
    System->>System: validate dir, ensure parent, unlink old, symlink Taildrop
    alt Validation passes (Enable true)
        preStartup-->>rc.tailscale: exit(0)
        rc.tailscale->>tailscaled: start tailscaled
    else Validation fails (Enable false)
        preStartup-->>rc.tailscale: exit(1)
        rc.tailscale->>rc.tailscale: abort start
    end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Files meriting extra attention:
    • plugin/plugin.j2 — verify symlink removal condition and that no unintended files are removed.
    • src/install/doinst.sh — ensure cron and event symlink targets are correct and paths exist after install.
    • src/usr/local/etc/rc.d/rc.tailscale — confirm pre-startup exit codes are handled correctly and do not leave partial state.
    • src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php — review symlink creation, parent directory creation, permission checks, and robust error/logging paths.
    • src/usr/local/php/unraid-tailscale-utils/pre-startup.php — validate the changed control flow (exit(0)/exit(1)) matches rc script expectations.

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of the PR: moving startup logic into rc.d for consistency, which is supported by multiple file changes consolidating initialization logic.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/startup

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d004ae1 and 5d2099b.

📒 Files selected for processing (1)
  • src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/install/doinst.sh (1)

1-7: Consider adding error handling for cd commands.

The static analysis tool flags that cd commands could fail without error handling. While unlikely in a controlled install environment, adding || exit would make the script more robust and prevent commands from executing in the wrong directory.

Apply this pattern to all cd commands:

-( cd etc/cron.daily ; rm -rf tailscale-daily )
+( cd etc/cron.daily || exit ; rm -rf tailscale-daily )
-( cd etc/cron.daily ; rm -rf check-tailscale-key )
+( cd etc/cron.daily || exit ; rm -rf check-tailscale-key )
-( cd etc/cron.daily ; ln -sf /usr/local/php/unraid-tailscale-utils/daily.sh tailscale-daily )
+( cd etc/cron.daily || exit ; ln -sf /usr/local/php/unraid-tailscale-utils/daily.sh tailscale-daily )

And similarly for the other cd commands on lines 4-7.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2d431f and d004ae1.

📒 Files selected for processing (9)
  • plugin/plugin.j2 (1 hunks)
  • src/install/doinst.sh (1 hunks)
  • src/usr/local/emhttp/plugins/tailscale/daily.sh (0 hunks)
  • src/usr/local/emhttp/plugins/tailscale/restart.sh (1 hunks)
  • src/usr/local/emhttp/plugins/tailscale/update-settings.sh (0 hunks)
  • src/usr/local/etc/rc.d/rc.tailscale (1 hunks)
  • src/usr/local/php/unraid-tailscale-utils/daily.sh (1 hunks)
  • src/usr/local/php/unraid-tailscale-utils/pre-startup.php (1 hunks)
  • src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php (1 hunks)
💤 Files with no reviewable changes (2)
  • src/usr/local/emhttp/plugins/tailscale/update-settings.sh
  • src/usr/local/emhttp/plugins/tailscale/daily.sh
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-15T03:15:08.212Z
Learnt from: dkaser
Repo: unraid/unraid-tailscale PR: 68
File: src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php:371-373
Timestamp: 2025-11-15T03:15:08.212Z
Learning: In the unraid-tailscale project, tailscaled accepts both single-dash and double-dash formats for command-line flags (e.g., both `-port` and `--port` are valid). The project uses single-dash format for consistency across daemon parameters in the System.php file.

Applied to files:

  • src/usr/local/etc/rc.d/rc.tailscale
🧬 Code graph analysis (2)
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php (2)
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Config.php (1)
  • Config (22-66)
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Utils.php (2)
  • Utils (22-184)
  • logwrap (66-73)
src/usr/local/emhttp/plugins/tailscale/restart.sh (1)
src/usr/local/php/unraid-tailscale-utils/log.sh (1)
  • log (3-7)
🪛 Shellcheck (0.11.0)
src/install/doinst.sh

[warning] 3-3: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

🔇 Additional comments (5)
src/usr/local/php/unraid-tailscale-utils/daily.sh (1)

1-3: LGTM - Simple and appropriate for cron.

The script correctly wraps the PHP daily maintenance task with output suppression, which is standard for cron jobs. The silent execution is appropriate since logging is presumably handled within daily.php itself.

plugin/plugin.j2 (1)

85-88: Good migration cleanup logic.

The pre-upgrade removal of the legacy /etc/rc.d/rc.tailscale symlink ensures a clean transition to the new architecture where startup logic is consolidated in rc.d. The -L test correctly identifies symlinks, and -f flag prevents errors if the file doesn't exist.

src/usr/local/php/unraid-tailscale-utils/pre-startup.php (1)

37-42: Clean pre-startup gate implementation.

The addition of Taildrop link creation and the use of exit codes to control daemon startup is a clean pattern. Exit 0 signals readiness to start, while exit 1 prevents startup when disabled. This aligns well with the refactored startup flow in rc.tailscale.

src/usr/local/emhttp/plugins/tailscale/restart.sh (1)

1-6: LGTM - Clean migration to centralized paths.

The updates correctly point to the centralized log helper and use the refactored rc.tailscale restart command instead of the deprecated update-settings.sh. The delayed restart via at is appropriate to avoid race conditions.

src/usr/local/etc/rc.d/rc.tailscale (1)

8-19: Well-structured pre-startup validation gate.

The introduction of the pre-startup check creates a clean separation between validation/preparation and daemon startup. The exit code pattern correctly gates daemon startup based on configuration state, and the custom params sourcing is now properly structured with an else clause for initialization.

@dkaser dkaser changed the title refactor: move all startup logic into rc.d for consistency with other apps fix: move all startup logic into rc.d for consistency with other apps Nov 15, 2025
@dkaser dkaser added fix and removed refactor labels Nov 15, 2025
@dkaser dkaser merged commit c672d32 into trunk Nov 15, 2025
7 checks passed
@dkaser dkaser deleted the refactor/startup branch November 15, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants