-
Notifications
You must be signed in to change notification settings - Fork 126
Refactor slow activities from nm-dispatcher script into separate listener service #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lmagyar
wants to merge
6
commits into
hassio-addons:main
Choose a base branch
from
lmagyar:pr-nm-dispatcher
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
666141d
Refactor slow activities from nm-dispatcher script into separate list…
lmagyar 52a3525
delay the starting of the dependent services until listener queue is …
lmagyar 357b422
fine tune log mesage
lmagyar 76935e7
Graceful shutdown on SIGTERM caused by manual app stop
lmagyar d9efe40
use bashio::log.reinitialize_output
lmagyar 88ed8b6
use bashio::try
lmagyar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
1 change: 1 addition & 0 deletions
1
tailscale/rootfs/etc/s6-overlay/s6-rc.d/init-protect-subnets/down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /etc/s6-overlay/s6-rc.d/init-protect-subnets/finish |
9 changes: 9 additions & 0 deletions
9
tailscale/rootfs/etc/s6-overlay/s6-rc.d/init-protect-subnets/finish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/command/with-contenv bashio | ||
| # shellcheck shell=bash | ||
| export LOG_FD | ||
| # ============================================================================== | ||
| # Home Assistant Community App: Tailscale | ||
| # Remove subnet protection | ||
| # ============================================================================== | ||
|
|
||
| unprotect-subnet-routes |
9 changes: 9 additions & 0 deletions
9
tailscale/rootfs/etc/s6-overlay/s6-rc.d/init-protect-subnets/run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/command/with-contenv bashio | ||
| # shellcheck shell=bash | ||
| export LOG_FD | ||
| # ============================================================================== | ||
| # Home Assistant Community App: Tailscale | ||
| # Prevent local subnets to be routed toward the tailnet | ||
| # ============================================================================== | ||
|
|
||
| protect-subnet-routes |
1 change: 1 addition & 0 deletions
1
tailscale/rootfs/etc/s6-overlay/s6-rc.d/init-protect-subnets/type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| oneshot |
1 change: 1 addition & 0 deletions
1
tailscale/rootfs/etc/s6-overlay/s6-rc.d/init-protect-subnets/up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /etc/s6-overlay/s6-rc.d/init-protect-subnets/run |
Empty file.
32 changes: 32 additions & 0 deletions
32
tailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher-listener/finish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #!/command/with-contenv bashio | ||
| # shellcheck shell=bash | ||
| export LOG_FD | ||
| # ============================================================================== | ||
| # Home Assistant Community App: Tailscale | ||
| # Take down the S6 supervision tree when nm-dispatcher-listener fails | ||
| # ============================================================================== | ||
| readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode) | ||
| readonly exit_code_service="${1}" | ||
| readonly exit_code_signal="${2}" | ||
| readonly service="nm-dispatcher-listener" | ||
|
|
||
| readonly NM_DISPATCHER_LISTENER_QUEUE=/run/nm-dispatcher-listener-queue | ||
|
|
||
| exec 4>&- | ||
| rm -rf "${NM_DISPATCHER_LISTENER_QUEUE}" | ||
|
|
||
| bashio::log.info \ | ||
| "Service ${service} exited with code ${exit_code_service}" \ | ||
| "(by signal ${exit_code_signal})" | ||
|
|
||
| if [[ "${exit_code_service}" -eq 256 ]]; then | ||
| if [[ "${exit_code_signal}" -ne 15 && "${exit_code_container}" -eq 0 ]]; then | ||
| echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode | ||
| fi | ||
| [[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt | ||
| elif [[ "${exit_code_service}" -ne 0 ]]; then | ||
| if [[ "${exit_code_container}" -eq 0 ]]; then | ||
| echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode | ||
| fi | ||
| exec /run/s6/basedir/bin/halt | ||
| fi |
1 change: 1 addition & 0 deletions
1
tailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher-listener/notification-fd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 3 |
52 changes: 52 additions & 0 deletions
52
tailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher-listener/run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/command/with-contenv bashio | ||
| # shellcheck shell=bash | ||
| export LOG_FD | ||
| # ============================================================================== | ||
| # Home Assistant Community App: Tailscale | ||
| # Runs the nm-dispatcher-listener service | ||
| # ============================================================================== | ||
|
|
||
| readonly NM_DISPATCHER_LISTENER_QUEUE=/run/nm-dispatcher-listener-queue | ||
|
|
||
| declare action | ||
| declare subnet_routes_to_unprotect | ||
| declare subnet_routes_to_protect | ||
|
|
||
| mkfifo "${NM_DISPATCHER_LISTENER_QUEUE}" | ||
|
|
||
| # Pin it to prevent closing it by other processes | ||
| exec 4<>"${NM_DISPATCHER_LISTENER_QUEUE}" | ||
|
lmagyar marked this conversation as resolved.
|
||
|
|
||
| # We need to delay the starting of the dependent services until listener queue is created | ||
| echo "" >&3 | ||
| exec 3>&- | ||
|
|
||
| while IFS= read -r -u 4 action | ||
| do | ||
| case "${action}" in | ||
| *up|*down) | ||
| bashio::log.info "Handling Network Manager action ${action}" | ||
| unprotect-subnet-routes | ||
| bashio::try protect-subnet-routes | ||
| if bashio::try.failed; then | ||
| bashio::exit.nok "Failed to protect subnet routes. Halting app to prevent network loss." | ||
| fi | ||
| ;; | ||
| *dhcp4-change|*dhcp6-change) | ||
| # Do anything only when the addresses are really changed | ||
| subnet_routes_to_unprotect="$(unprotect-subnet-routes test)" | ||
| subnet_routes_to_protect="$(protect-subnet-routes test)" | ||
| if ! bashio::var.equals "${subnet_routes_to_unprotect}" "${subnet_routes_to_protect}"; then | ||
| bashio::log.info "Handling Network Manager action ${action}" | ||
| unprotect-subnet-routes | ||
| bashio::try protect-subnet-routes tested | ||
| if bashio::try.failed; then | ||
| bashio::exit.nok "Failed to protect subnet routes. Halting app to prevent network loss." | ||
| fi | ||
| fi | ||
| ;; | ||
| *) | ||
| bashio::exit.nok "Unknown Network Manager action ${action}" | ||
| ;; | ||
| esac | ||
| done | ||
1 change: 1 addition & 0 deletions
1
tailscale/rootfs/etc/s6-overlay/s6-rc.d/nm-dispatcher-listener/type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| longrun |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| longrun |
Empty file.
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| longrun | ||
| bundle |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.