Last active
May 4, 2024 00:20
-
-
Save gomasy/ff9133db93339d1b7bf54272e84d2b21 to your computer and use it in GitHub Desktop.
Test implementation of /etc/init.d/tailscaled
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/bash | |
# | |
# tailscaled Start up the Tailscale server daemon | |
# | |
# description: A mesh VPN that makes it easy to connect your devices, wherever they are. | |
# | |
# processname: tailscaled | |
### BEGIN INIT INFO | |
# Provides: tailscaled | |
# Required-Start: $local_fs $network $syslog | |
# Required-Stop: $local_fs $syslog | |
# Should-Start: $syslog | |
# Should-Stop: $network $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start up the Tailscale server daemon | |
# Description: A mesh VPN that makes it easy to connect your devices, wherever they are. | |
### END INIT INFO | |
# source function library | |
. /etc/rc.d/init.d/functions | |
RETVAL=0 | |
prog="tailscaled" | |
lockfile=/var/lock/subsys/$prog | |
WORKDIR=/var/lib/tailscale | |
RUNDIR=/var/run/tailscale | |
STATE=$WORKDIR/tailscaled.state | |
SOCKET=$RUNDIR/tailscaled.sock | |
TAILSCALED=/usr/local/bin/tailscaled | |
CONFIG=/etc/default/tailscaled | |
runlevel=$(set -- $(runlevel); eval "echo \$$#" ) | |
start() | |
{ | |
[ ! -x $TAILSCALED ] && exit 5 | |
echo -n $"Starting $prog: " | |
[ ! -x $WORKDIR ] && mkdir $WORKDIR | |
[ ! -x $RUNDIR ] && mkdir $RUNDIR | |
if [ -e $CONFIG ]; then | |
. $CONFIG | |
daemon "$TAILSCALED --state $STATE --socket=$SOCKET --port=$PORT $FLAGS &" 2>/dev/null 1>&2 && \ | |
success || failure $"$prog start" | |
else | |
daemon "$TAILSCALED --state $STATE --socket=$SOCKET &" 2>/dev/null 1>&2 && \ | |
success || failure $"$prog start" | |
fi | |
RETVAL=$? | |
[ $RETVAL -eq 0 ] && touch $lockfile | |
echo | |
return $RETVAL | |
} | |
stop() | |
{ | |
echo -n $"Stopping $prog: " | |
killproc $TAILSCALED 2>/dev/null 1>&2 && \ | |
$TAILSCALED --cleanup 2>/dev/null 1>&2 && \ | |
success || failure $"$prog stop" | |
RETVAL=$? | |
# if we are in halt or reboot runlevel kill all running sessions | |
# so the TCP connections are closed cleanly | |
if [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; then | |
trap '' TERM | |
killall $prog 2>/dev/null | |
trap TERM | |
fi | |
[ $RETVAL -eq 0 ] && rm -f $lockfile | |
echo | |
} | |
restart() { | |
stop | |
start | |
} | |
rh_status() { | |
status $prog | |
} | |
rh_status_q() { | |
rh_status >/dev/null 2>&1 | |
} | |
case "$1" in | |
start) | |
rh_status_q && exit 0 | |
start | |
;; | |
stop) | |
if ! rh_status_q; then | |
rm -f $lockfile | |
exit 0 | |
fi | |
stop | |
;; | |
restart) | |
restart | |
;; | |
status) | |
rh_status | |
RETVAL=$? | |
if [ $RETVAL -eq 3 -a -f $lockfile ] ; then | |
RETVAL=2 | |
fi | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart|status}" | |
RETVAL=2 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment