github.com/yggdrasil-network/yggdrasil-go@v0.5.6/contrib/busybox-init/S42yggdrasil (about)

     1  #!/bin/sh
     2  
     3  CONFFILE="/etc/yggdrasil.conf"
     4  
     5  genconf() {
     6  	/usr/bin/yggdrasil -genconf > "$1"
     7  	return $?
     8  }
     9  
    10  probetun() {
    11  	modprobe tun
    12  	return $?
    13  }
    14  
    15  start() {
    16  	if [ ! -f "$CONFFILE" ]; then
    17  		printf 'Generating configuration file: '
    18  		if genconf "$CONFFILE"; then
    19  			echo "OK"
    20  		else
    21  			echo "FAIL"
    22  			return 1
    23  		fi
    24  	fi
    25  
    26  	if [ ! -e /dev/net/tun ]; then
    27  		printf 'Inserting TUN module: '
    28  		if probetun; then
    29  			echo "OK"
    30  		else
    31  			echo "FAIL"
    32  			return 1
    33  		fi
    34  	fi
    35  
    36  	printf 'Starting yggdrasil: '
    37  	if start-stop-daemon -S -q -b -x /usr/bin/yggdrasil \
    38  		-- -useconffile "$CONFFILE"; then
    39  		echo "OK"
    40  	else
    41  		echo "FAIL"
    42  	fi
    43  }
    44  
    45  stop() {
    46  	printf "Stopping yggdrasil: "
    47  	if start-stop-daemon -K -q -x /usr/bin/yggdrasil; then
    48  		echo "OK"
    49  	else
    50  		echo "FAIL"
    51  	fi
    52  }
    53  
    54  reload() {
    55  	printf "Reloading yggdrasil: "
    56  	if start-stop-daemon -K -q -s HUP -x /usr/bin/yggdrasil; then
    57  		echo "OK"
    58  	else
    59  		echo "FAIL"
    60  		start
    61  	fi
    62  }
    63  
    64  restart() {
    65  	stop
    66  	start
    67  }
    68  
    69  case "$1" in
    70  	start|stop|restart|reload)
    71  		"$1";;
    72  	*)
    73  		echo "Usage: $0 {start|stop|restart|reload}"
    74  		exit 1
    75  esac
    76  
    77  exit 0