mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 14:15:06 +03:00
64 lines
2 KiB
Bash
64 lines
2 KiB
Bash
#!/bin/sh
|
|
#
|
|
# Put the yggdrasil and yggdrasilctl binaries into /usr/local/bin
|
|
# Then copy this script into /usr/local/etc/rc.d/yggdrasil
|
|
# yggdrasil_syslog.conf into /usr/local/etc/syslog.d/yggdrasil.conf
|
|
# and yggdrasil_newsyslog.conf into /usr/local/etc/newsyslog.conf.d/yggdrasil.conf
|
|
# Finally, run:
|
|
# 1. chmod +x /etc/rc.d/yggdrasil /usr/local/bin/{yggdrasil,yggdrasilctl}
|
|
# 2. sysrc yggdrasil_enable=YES
|
|
# 3. service yggdrasil start
|
|
#
|
|
# PROVIDE: yggdrasil
|
|
# REQUIRE: networking
|
|
# KEYWORD:
|
|
|
|
. /etc/rc.subr
|
|
|
|
name="yggdrasil"
|
|
rcvar="yggdrasil_enable"
|
|
|
|
start_cmd="${name}_start"
|
|
stop_cmd="${name}_stop"
|
|
|
|
yggdrasil_command="/usr/local/bin/yggdrasil"
|
|
pidfile="/var/run/yggdrasil/${name}.pid"
|
|
command="/usr/sbin/daemon"
|
|
command_args="-P ${pidfile} -r -S -m 3 -s info -T yggdrasil ${yggdrasil_command}"
|
|
|
|
yggdrasil_start()
|
|
{
|
|
test ! -x /usr/local/bin/yggdrasil && (
|
|
logger -s -t yggdrasil "Warning: /usr/local/bin/yggdrasil is missing or not executable"
|
|
logger -s -t yggdrasil "Copy the yggdrasil binary into /usr/local/bin and then chmod +x /usr/local/bin/yggdrasil"
|
|
return 1
|
|
)
|
|
|
|
test ! -f /usr/local/etc/yggdrasil.conf && (
|
|
logger -s -t yggdrasil "Generating new configuration file into /usr/local/etc/yggdrasil.conf"
|
|
/usr/local/bin/yggdrasil -genconf > /usr/local/etc/yggdrasil.conf
|
|
)
|
|
|
|
mkdir -p /var/run/yggdrasil
|
|
|
|
logger -s -t yggdrasil "Starting yggdrasil"
|
|
${command} ${command_args} -useconffile /usr/local/etc/yggdrasil.conf &
|
|
}
|
|
|
|
yggdrasil_stop()
|
|
{
|
|
logger -s -t yggdrasil "Stopping yggdrasil"
|
|
test -f /var/run/yggdrasil/${name}.pid && kill -TERM $(cat /var/run/yggdrasil/${name}.pid)
|
|
|
|
tap_name="$(egrep '^[ \t]+IfName:' /usr/local/etc/yggdrasil.conf | sed 's/[ \t]*IfName:[ \t]*//')"
|
|
|
|
/sbin/ifconfig ${tap_name} >/dev/null 2>&1 && (
|
|
logger -s -t yggdrasil "Destroying ${tap_name} adapter"
|
|
/sbin/ifconfig ${tap_name} destroy || logger -s -t yggdrasil "Failed to destroy ${tap_name} adapter"
|
|
)
|
|
}
|
|
|
|
load_rc_config $name
|
|
: ${yggdrasil_enable:=no}
|
|
|
|
run_rc_command "$1"
|