Skip to content

Instantly share code, notes, and snippets.

@mechinn
Last active August 14, 2024 02:00
Show Gist options
  • Save mechinn/2a23dadc574ca65ff5bdd4e7e781c3ed to your computer and use it in GitHub Desktop.
Save mechinn/2a23dadc574ca65ff5bdd4e7e781c3ed to your computer and use it in GitHub Desktop.
Tailscale batocera service
#!/bin/bash
set -a
source /userdata/tailscale/systemd/tailscaled.defaults
set +a
command="/userdata/tailscale/tailscaled"
command_args="--state /userdata/tailscale/state/tailscaled.state --port=${PORT} --socket=/var/run/tailscale/tailscaled.sock $FLAGS"
command_background=true
pidfile="/run/tailscaled.pid"
start_stop_daemon_args="-O /userdata/tailscale/log/tailscaled.log"
depend() {
need net
}
start_pre() {
mkdir -p /var/run/tailscale
mkdir -p /userdata/tailscale/log
mkdir -p /userdata/tailscale/state
$command --statedir /userdata/tailscale/state --cleanup
}
stop_post() {
$command --statedir /userdata/tailscale/state --cleanup
}
start() {
start_pre
if [ "$command_background" = true ]; then
start_stop_daemon_args="$start_stop_daemon_args -b --pidfile $pidfile --make-pidfile --remove-pidfile $start_stop_daemon_args"
fi
start-stop-daemon -S -q $start_stop_daemon_args -x $command -- $command_args
}
stop() {
start-stop-daemon -K -q -n $(basename $command)
RETVAL=$?
stop_post
return $RETVAL
}
restart() {
stop
start
}
status() {
/userdata/tailscale/tailscale status
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit $?
BSD 3-Clause License
Copyright (c) 2020 Tailscale Inc & AUTHORS.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment