From 40c644fc2ceed5ec149f84a57269440fae392331 Mon Sep 17 00:00:00 2001 From: Dmitry Nezhevenko Date: Mon, 23 Dec 2024 10:22:57 +0100 Subject: [PATCH] Add STARTUP_SCRIPT option to execute extra script during container start --- README.md | 9 +++++++++ tailscale.sh | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index a3557bc..8fd7baa 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ This section follows the Mikrotik Container documentation with additional steps | UPDATE_TAILSCALE | Update tailscale on container startup | | | TAILSCALE_ARGS | Additional arguments passed to tailscale | Optional. Note ```---accept-routes``` is required to accept the advertised routes of the other subnet routers | | TAILSCALED_ARGS | Additional arguments passed to tailscaled | Optional | +| STARTUP_SCRIPT | Extra script to execute in container before tailscaled | Optional | Example Tailscale control server configuration: ``` @@ -105,6 +106,14 @@ Define the the mount as per below. add name="tailscale" src="/tailscale" dst="/var/lib/tailscale" ``` +It's possible to execute extra script during container startup. To do this, firstly make sure that script is accessible inside +container. For example put it to `/var/lib/tailscale` folder and then add `STARTUP_SCRIPT` environment variable: + +``` +/container/envs +add name="tailscale" key="STARTUP_SCRIPT" value="/var/lib/tailscale/startup.sh" +``` + 6. Create the container The container can be created via the container registry (Step 6a) or using the `tailscale.tar` file generated by building the Docker image locally (Step 6b or 6c). diff --git a/tailscale.sh b/tailscale.sh index ef1f19f..3422ac9 100755 --- a/tailscale.sh +++ b/tailscale.sh @@ -34,6 +34,10 @@ if [[ -z "$LOGIN_SERVER" ]]; then LOGIN_SERVER=https://controlplane.tailscale.com fi +if [[ -n "$STARTUP_SCRIPT" ]]; then + bash "$STARTUP_SCRIPT" || exit $? +fi + # Start tailscaled and bring tailscale up /usr/local/bin/tailscaled ${TAILSCALED_ARGS} & until /usr/local/bin/tailscale up \