diff options
author | Bernhard Tittelbach <service-anytun@tittelbach.org> | 2015-01-16 00:13:27 +0000 |
---|---|---|
committer | Bernhard Tittelbach <service-anytun@tittelbach.org> | 2015-01-16 00:13:27 +0000 |
commit | 3de5d986dc5cebf31287d1c41388a1004976df7d (patch) | |
tree | d3acbf5aaf350354fd11ca833c85ae2b315f671b /usr | |
parent | version output now includes compiler version (diff) |
systemd support (--with-systemd) (config/install script untested)
Diffstat (limited to 'usr')
-rwxr-xr-x | usr/bin/anytun-launcher.sh | 56 | ||||
-rw-r--r-- | usr/lib/systemd/system/anytun-control@.service | 13 | ||||
-rw-r--r-- | usr/lib/systemd/system/anytun@.service | 12 |
3 files changed, 81 insertions, 0 deletions
diff --git a/usr/bin/anytun-launcher.sh b/usr/bin/anytun-launcher.sh new file mode 100755 index 0000000..8103f91 --- /dev/null +++ b/usr/bin/anytun-launcher.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +NAME="${NAME:-$2}" + +DAEMON=/usr/sbin/anytun +ANYTUNCONFIG=/usr/bin/anytun-config +CONTROLDAEMON=/usr/bin/anytun-controld +CONFIG_DIR=/etc/anytun +VARCONFIG_DIR=/run/anytun-controld +VARRUN_DIR=/run/anytun + +test -x $DAEMON || exit 0 +test -z $NAME && exit 1 + +start_vpn () { + if [ -f $CONFIG_DIR/$NAME/config ] ; then + POSTUP='' + test -f $CONFIG_DIR/$NAME/post-up.sh && POSTUP="-x $CONFIG_DIR/$NAME/post-up.sh" + CHROOTDIR=`grep '^chroot' < $CONFIG_DIR/$NAME/config | sed 's/chroot\s*//'` + if [ -n "$CHROOTDIR" ] ; then + test -d $CHROOTDIR || mkdir -p $CHROOTDIR + fi + test -d $VARRUN_DIR || mkdir -p $VARRUN_DIR + DAEMONARG=`sed 's/#.*//' < $CONFIG_DIR/$NAME/config | grep -e '\w' | sed 's/^/--/' | tr '\n' ' '` + $DAEMON --write-pid $VARRUN_DIR/$NAME.pid $POSTUP $DAEMONOPTS $DAEMONARG + else + echo "no config found" >&2 + return 1 + fi +} + +start_configd () { + if [ -d $CONFIG_DIR/$NAME/conf.d ] ; then + test -d $VARCONFIG_DIR || mkdir -p $VARCONFIG_DIR + chmod 700 $VARCONFIG_DIR + rm -f $VARCONFIG_DIR/$NAME 2>/dev/null + KDPRF=`sed 's/#.*//' < $CONFIG_DIR/$NAME/config | grep -e 'kd-prf' | sed 's/^/ --/' | xargs echo` + for CLIENTNAME in `ls $CONFIG_DIR/$NAME/conf.d`; do + echo -n " ($CLIENTNAME)" + DAEMONARG=`sed 's/#.*//' < $CONFIG_DIR/$NAME/conf.d/$CLIENTNAME | grep -e '\w' | sed 's/^/ --/' | xargs echo` + $ANYTUNCONFIG $DAEMONARG $CIPHER $AUTHALGO $KDPRF >> $VARCONFIG_DIR/$NAME + done + CONTROLHOST=`sed 's/#.*//' < $CONFIG_DIR/$NAME/config | grep -e 'control-host' | sed 's/^/ --/' | xargs echo` + $CONTROLDAEMON -f $VARCONFIG_DIR/$NAME $DAEMONOPTS $CONTROLHOST \ + --write-pid $VARCONFIG_DIR/$NAME.pid + else + echo "no conf.d directory found (maybe $NAME is an anytun client not a server?)" >&2 + return 1 + fi +} + +case $1 in +(vpn) start_vpn ;; +(configd) start_configd ;; +(*) exit 2;; +esac diff --git a/usr/lib/systemd/system/anytun-control@.service b/usr/lib/systemd/system/anytun-control@.service new file mode 100644 index 0000000..ec857e9 --- /dev/null +++ b/usr/lib/systemd/system/anytun-control@.service @@ -0,0 +1,13 @@ +[Unit] +Description=AnyTun Server Config Control Daemon +After=syslog.target network.target +Requires=anytun@%i.service + +[Service] +Type=simple +PIDFile=/run/anytun-controld/%i.pid +Environment="NAME=%i" "DAEMONOPTS=-D -L stdout:3" +ExecStart=/usr/bin/anytun-launcher.sh configd + +[Install] +WantedBy=multi-user.target diff --git a/usr/lib/systemd/system/anytun@.service b/usr/lib/systemd/system/anytun@.service new file mode 100644 index 0000000..2b7fa72 --- /dev/null +++ b/usr/lib/systemd/system/anytun@.service @@ -0,0 +1,12 @@ +[Unit] +Description=AnyTun secure anycast tunneling +After=syslog.target network.target + +[Service] +Type=simple +PIDFile=/run/anytun/%i.pid +Environment="NAME=%i" "DAEMONOPTS=-D -L stdout:3" +ExecStart=/usr/bin/anytun-launcher.sh vpn + +[Install] +WantedBy=multi-user.target |