Skip to content

Instantly share code, notes, and snippets.

@jzelinskie
Created May 25, 2021 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jzelinskie/86dff94f2659e0004acae2e3bbc37ceb to your computer and use it in GitHub Desktop.
Save jzelinskie/86dff94f2659e0004acae2e3bbc37ceb to your computer and use it in GitHub Desktop.
@tailscale EdgeOS `/config/scripts/post-config.d` script
#!/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