ebuilds/net-p2p/yggdrasil-rootless/files/yggdrasil-rootless.initd

66 lines
1.6 KiB
Text

#!/sbin/openrc-run
description="An experiment in scalable routing as an encrypted IPv6 overlay network."
CONFFILE="/etc/yggdrasil.conf"
pidfile="/run/${RC_SVCNAME}.pid"
supervisor="supervise-daemon"
command="/usr/bin/yggdrasil"
command_user="yggdrasil:yggdrasil"
extra_started_commands="reload"
capabilities="^cap_net_admin,^cap_net_bind_service"
depend() {
use net dns logger
}
start_pre() {
if [ ! -f "${CONFFILE}" ]; then
ebegin "Generating new configuration file into ${CONFFILE}"
if ! eval ${command} -genconf > ${CONFFILE}; then
eerror "Failed to generate configuration file"
exit 1
else
chown yggdrasil:yggdrasil "${CONFFILE}"
chmod 640 "${CONFFILE}"
fi
fi
if [ ! -e /dev/net/tun ]; then
ebegin "Inserting TUN module"
if ! modprobe tun; then
eerror "Failed to insert TUN kernel module"
exit 1
fi
fi
}
start() {
ebegin "Starting ${RC_SVCNAME}"
# touch "/var/run/yggdrasil.sock"
# chown yggdrasil:yggdrasil "/var/run/yggdrasil.sock"
# chmod 750 "/var/run/yggdrasil.sock"
install -d -m 750 -o yggdrasil -g yggdrasil "/var/run/yggdrasil"
start-stop-daemon --start --quiet \
--pidfile "${pidfile}" \
--make-pidfile \
--background \
--stdout /var/log/yggdrasil/stdout.log \
--stderr /var/log/yggdrasil/stderr.log \
-u "${command_user}" \
--exec "${command}" -- -useconffile "${CONFFILE}"
eend $?
}
reload() {
ebegin "Reloading ${RC_SVCNAME}"
start-stop-daemon --signal HUP --pidfile "${pidfile}"
eend $?
}
stop() {
ebegin "Stopping ${RC_SVCNAME}"
start-stop-daemon --stop --pidfile "${pidfile}" --exec "${command}"
eend $?
}