From 13767e5108b3e6136c71aabbc7db5c17e3416685 Mon Sep 17 00:00:00 2001 From: James Tucker Date: Fri, 6 Oct 2023 18:20:17 -0700 Subject: [PATCH] docs/sysv: add a sysv style init script The script depends on a sufficiently recent start-stop-daemon as to provide the `-m` and `--remove-pidfile` flags. Updates #9502 Signed-off-by: James Tucker --- docs/sysv/tailscale.init | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 docs/sysv/tailscale.init diff --git a/docs/sysv/tailscale.init b/docs/sysv/tailscale.init new file mode 100755 index 000000000..ca21033df --- /dev/null +++ b/docs/sysv/tailscale.init @@ -0,0 +1,63 @@ +#!/bin/sh +# Copyright (c) Tailscale Inc & AUTHORS +# SPDX-License-Identifier: BSD-3-Clause + +### BEGIN INIT INFO +# Provides: tailscaled +# Required-Start: +# Required-Stop: +# Default-Start: +# Default-Stop: +# Short-Description: Tailscale Mesh Wireguard VPN +### END INIT INFO + +set -e + +# /etc/init.d/tailscale: start and stop the Tailscale VPN service + +test -x /usr/sbin/tailscaled || exit 0 + +umask 022 + +. /lib/lsb/init-functions + +# Are we running from init? +run_by_init() { + ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ] +} + +export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" + +case "$1" in + start) + log_daemon_msg "Starting Tailscale VPN" "tailscaled" || true + if start-stop-daemon --start --oknodo --name tailscaled -m --pidfile /run/tailscaled.pid --background \ + --exec /usr/sbin/tailscaled -- \ + --state=/var/lib/tailscale/tailscaled.state \ + --socket=/run/tailscale/tailscaled.sock \ + --port 41641; + then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + ;; + stop) + log_daemon_msg "Stopping Tailscale VPN" "tailscaled" || true + if start-stop-daemon --stop --remove-pidfile --pidfile /run/tailscaled.pid --exec /usr/sbin/tailscaled; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + ;; + + status) + status_of_proc -p /run/tailscaled.pid /usr/sbin/tailscaled tailscaled && exit 0 || exit $? + ;; + + *) + log_action_msg "Usage: /etc/init.d/tailscaled {start|stop|status}" || true + exit 1 +esac + +exit 0