Last active
February 13, 2021 03:25
-
-
Save akhilman/b1749f564a2b043579447a1e237ab448 to your computer and use it in GitHub Desktop.
Yggdrasil init script for SystemV
This file contains hidden or 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 | |
### BEGIN INIT INFO | |
# Provides: yggdrasil | |
# Required-Start: $local_fs | |
# Required-Stop: | |
# Should-Start: $network $portmap | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: | |
# Short-Description: Overlay network | |
# Description: Overlay network | |
### END INIT INFO | |
. /lib/lsb/init-functions | |
[ -f /etc/default/rcS ] && . /etc/default/rcS | |
PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
DAEMON=/usr/bin/yggdrasil | |
CONFIG_FILE="/etc/yggdrasil.conf" | |
DAEMON_OPTS="-useconffile $CONFIG_FILE" | |
NAME=yggdrasil | |
DESC="overlay network" | |
CONFFILE="/etc/yggdrasil.conf" | |
gen_conf() { | |
$DAEMON -genconf $CONFIG_FILE | |
return $? | |
} | |
probe_tun() { | |
modprobe tun | |
return $? | |
} | |
probe_ipv6() { | |
modprobe ipv6 | |
return $? | |
} | |
pre_start() { | |
if [ ! -f "$CONFFILE" ]; then | |
log_daemon_msg 'Generating configuration file: ' | |
if gen_conf; then | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
exit 1 | |
fi | |
fi | |
if [ -d /sys/module/ipv6/ ]; then | |
log_daemon_msg 'Inserting ipv6 module: ' | |
if probe_ipv6; then | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
exit 1 | |
fi | |
fi | |
if [ ! -e /dev/net/tun ]; then | |
log_daemon_msg 'Inserting TUN module: ' | |
if probe_tun; then | |
log_end_msg 0 | |
else | |
log_end_msg 1 | |
exit 1 | |
fi | |
fi | |
if [ "$(cat /sys/module/ipv6/parameters/disable)" != "0" ]; then | |
echo "ipv6 is disabled" | |
exit 1 | |
fi | |
} | |
test -x $DAEMON || exit 0 | |
set -e | |
case "$1" in | |
start) | |
pre_start | |
log_daemon_msg "Starting $DESC" "$NAME" | |
start-stop-daemon --start --background --quiet \ | |
--pidfile /var/run/$NAME.pid --make-pidfile \ | |
--exec $DAEMON -- $DAEMON_OPTS | |
log_end_msg $? | |
;; | |
stop) | |
log_daemon_msg "Stopping $DESC" "$NAME" | |
start-stop-daemon --stop --oknodo --quiet --pidfile /var/run/$NAME.pid \ | |
--retry 10 --exec $DAEMON | |
log_end_msg $? | |
;; | |
force-reload) | |
# check whether $DAEMON is running. If so, restart | |
start-stop-daemon --stop --test --quiet --pidfile \ | |
/var/run/$NAME.pid --exec $DAEMON \ | |
&& $0 restart \ | |
|| exit 0 | |
;; | |
restart) | |
log_daemon_msg "Restarting $DESC" "$NAME" | |
$0 stop | |
$0 start | |
;; | |
status) | |
if [ -s /var/run/$NAME.pid ]; then | |
RUNNING=$(cat /var/run/$NAME.pid) | |
if [ -d /proc/$RUNNING ]; then | |
if [ $(readlink /proc/$RUNNING/exe) = $DAEMON ]; then | |
log_success_msg "$NAME is running" | |
exit 0 | |
fi | |
fi | |
# No such PID, or executables don't match | |
log_failure_msg "$NAME is not running, but pidfile existed" | |
rm /var/run/$NAME.pid | |
exit 1 | |
else | |
rm -f /var/run/$NAME.pid | |
log_failure_msg "$NAME not running" | |
exit 1 | |
fi | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
log_failure_msg "Usage: $N {start|stop|restart|force-reload}" | |
exit 1 | |
;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment