Created
May 25, 2021 03:44
-
-
Save jzelinskie/86dff94f2659e0004acae2e3bbc37ceb to your computer and use it in GitHub Desktop.
@tailscale EdgeOS `/config/scripts/post-config.d` script
This file contains 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
#!/bin/sh | |
name="tailscale" | |
exe="/config/tailscale/tailscaled" | |
cmd="$exe --state=/config/tailscale/tailscaled.state --port 41641" | |
is_running() { | |
sudo ifconfig tailscale0 > /dev/null 2>&1 | |
} | |
action=$1 | |
if [ -z "$action" ]; then | |
sleep 120 | |
action=start | |
fi | |
case "$action" in | |
start) | |
if is_running; then | |
echo "Already started" | |
else | |
echo "Starting $name" | |
$cmd & disown | |
for i in $(seq 1 10) | |
do | |
if is_running; then | |
break | |
fi | |
sleep 1 | |
done | |
if ! is_running; then | |
echo "Unable to start" | |
exit 1 | |
fi | |
fi | |
;; | |
stop) | |
if is_running; then | |
echo -n "Stopping $name.." | |
sudo pkill tailscaled | |
for i in $(seq 1 10) | |
do | |
if ! is_running; then | |
break | |
fi | |
echo -n "." | |
sleep 1 | |
done | |
echo | |
if is_running; then | |
echo "Not stopped; may still be shutting down or shutdown may have failed" | |
exit 1 | |
else | |
echo "Stopped" | |
fi | |
else | |
echo "Not running" | |
fi | |
;; | |
restart) | |
$0 stop | |
if is_running; then | |
echo "Unable to stop, will not attempt to start" | |
exit 1 | |
fi | |
$0 start | |
;; | |
status) | |
if is_running; then | |
echo "Running" | |
else | |
echo "Stopped" | |
exit 1 | |
fi | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart|status}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment