1#!/sbin/openrc-run 2 3description="An experiment in scalable routing as an encrypted IPv6 overlay network." 4 5CONFFILE="/etc/yggdrasil.conf" 6pidfile="/run/${RC_SVCNAME}.pid" 7 8command="/usr/bin/yggdrasil" 9extra_started_commands="reload" 10 11depend() { 12 use net dns logger 13} 14 15start_pre() { 16 if [ ! -f "${CONFFILE}" ]; then 17 ebegin "Generating new configuration file into ${CONFFILE}" 18 if ! eval ${command} -genconf > ${CONFFILE}; then 19 eerror "Failed to generate configuration file" 20 exit 1 21 fi 22 fi 23 24 if [ ! -e /dev/net/tun ]; then 25 ebegin "Inserting TUN module" 26 if ! modprobe tun; then 27 eerror "Failed to insert TUN kernel module" 28 exit 1 29 fi 30 fi 31} 32 33start() { 34 ebegin "Starting ${RC_SVCNAME}" 35 start-stop-daemon --start --quiet \ 36 --pidfile "${pidfile}" \ 37 --make-pidfile \ 38 --background \ 39 --stdout /var/log/yggdrasil.stdout.log \ 40 --stderr /var/log/yggdrasil.stderr.log \ 41 --exec "${command}" -- -useconffile "${CONFFILE}" 42 eend $? 43} 44 45reload() { 46 ebegin "Reloading ${RC_SVCNAME}" 47 start-stop-daemon --signal HUP --pidfile "${pidfile}" 48 eend $? 49} 50 51stop() { 52 ebegin "Stopping ${RC_SVCNAME}" 53 start-stop-daemon --stop --pidfile "${pidfile}" --exec "${command}" 54 eend $? 55} 56