From f7f1468cb4f456e3c021889151f7e41ecf68317d Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 16 Dec 2022 11:46:51 +0100 Subject: [PATCH] :hammer: Migrate old-style S6 scripts to s6-rc.d --- .../s6-rc.d/init-tor/dependencies.d/base | 0 .../s6-rc.d/init-tor/run} | 1 + .../etc/s6-overlay/s6-rc.d/init-tor/type | 1 + tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/up | 1 + .../s6-rc.d/tor/dependencies.d/init-tor | 0 tor/rootfs/etc/s6-overlay/s6-rc.d/tor/finish | 27 +++++++++++++++++++ .../s6-rc.d}/tor/run | 1 + tor/rootfs/etc/s6-overlay/s6-rc.d/tor/type | 1 + .../s6-rc.d/user/contents.d/init-tor | 0 .../s6-overlay/s6-rc.d/user/contents.d/tor | 0 tor/rootfs/etc/services.d/tor/finish | 11 -------- 11 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/dependencies.d/base rename tor/rootfs/etc/{cont-init.d/prepare.sh => s6-overlay/s6-rc.d/init-tor/run} (99%) create mode 100644 tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/type create mode 100644 tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/up create mode 100644 tor/rootfs/etc/s6-overlay/s6-rc.d/tor/dependencies.d/init-tor create mode 100755 tor/rootfs/etc/s6-overlay/s6-rc.d/tor/finish rename tor/rootfs/etc/{services.d => s6-overlay/s6-rc.d}/tor/run (93%) create mode 100644 tor/rootfs/etc/s6-overlay/s6-rc.d/tor/type create mode 100644 tor/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-tor create mode 100644 tor/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/tor delete mode 100755 tor/rootfs/etc/services.d/tor/finish diff --git a/tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/dependencies.d/base b/tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/dependencies.d/base new file mode 100644 index 0000000..e69de29 diff --git a/tor/rootfs/etc/cont-init.d/prepare.sh b/tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/run similarity index 99% rename from tor/rootfs/etc/cont-init.d/prepare.sh rename to tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/run index 9832e46..564eb07 100755 --- a/tor/rootfs/etc/cont-init.d/prepare.sh +++ b/tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/run @@ -1,4 +1,5 @@ #!/command/with-contenv bashio +# shellcheck shell=bash # ============================================================================== # Home Assistant Community Add-on: Tor # Prepares the add-on for startup diff --git a/tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/type b/tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/type @@ -0,0 +1 @@ +oneshot diff --git a/tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/up b/tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/up new file mode 100644 index 0000000..49d18ae --- /dev/null +++ b/tor/rootfs/etc/s6-overlay/s6-rc.d/init-tor/up @@ -0,0 +1 @@ +/etc/s6-overlay/s6-rc.d/init-tor/run diff --git a/tor/rootfs/etc/s6-overlay/s6-rc.d/tor/dependencies.d/init-tor b/tor/rootfs/etc/s6-overlay/s6-rc.d/tor/dependencies.d/init-tor new file mode 100644 index 0000000..e69de29 diff --git a/tor/rootfs/etc/s6-overlay/s6-rc.d/tor/finish b/tor/rootfs/etc/s6-overlay/s6-rc.d/tor/finish new file mode 100755 index 0000000..f7b99aa --- /dev/null +++ b/tor/rootfs/etc/s6-overlay/s6-rc.d/tor/finish @@ -0,0 +1,27 @@ +#!/command/with-contenv bashio +# shellcheck shell=bash +# ============================================================================== +# Home Assistant Community Add-on: Tor +# Take down the S6 supervision tree when the Tor daemon fails +# ============================================================================== +declare exit_code +readonly exit_code_container=$( /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 diff --git a/tor/rootfs/etc/services.d/tor/run b/tor/rootfs/etc/s6-overlay/s6-rc.d/tor/run similarity index 93% rename from tor/rootfs/etc/services.d/tor/run rename to tor/rootfs/etc/s6-overlay/s6-rc.d/tor/run index 89b4ca9..a82250d 100755 --- a/tor/rootfs/etc/services.d/tor/run +++ b/tor/rootfs/etc/s6-overlay/s6-rc.d/tor/run @@ -1,4 +1,5 @@ #!/command/with-contenv bashio +# shellcheck shell=bash # ============================================================================== # Home Assistant Community Add-on: Tor # Runs the Tor daemon diff --git a/tor/rootfs/etc/s6-overlay/s6-rc.d/tor/type b/tor/rootfs/etc/s6-overlay/s6-rc.d/tor/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/tor/rootfs/etc/s6-overlay/s6-rc.d/tor/type @@ -0,0 +1 @@ +longrun diff --git a/tor/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-tor b/tor/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-tor new file mode 100644 index 0000000..e69de29 diff --git a/tor/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/tor b/tor/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/tor new file mode 100644 index 0000000..e69de29 diff --git a/tor/rootfs/etc/services.d/tor/finish b/tor/rootfs/etc/services.d/tor/finish deleted file mode 100755 index 4eb7d26..0000000 --- a/tor/rootfs/etc/services.d/tor/finish +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/with-contenv bashio -# ============================================================================== -# Home Assistant Community Add-on: Tor -# Take down the S6 supervision tree when the Tor daemon fails -# ============================================================================== -if [[ "${1}" -ne 0 ]] && [[ "${1}" -ne 256 ]]; then - bashio::log.warning "Tor crashed, halting add-on" - /run/s6/basedir/bin/halt -fi - -bashio::log.info "Tor stopped, restarting..."