summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2016-07-08 02:03:37 (GMT)
committerChristian Pointner <equinox@anytun.org>2016-07-08 02:03:37 (GMT)
commitb9aa07cbcf584a2d5bc9f9f2bd74cca2057e0494 (patch)
treea90d25b462437a484d502841f45dc36ded44997e
parenta8b7ca024585a03a8aca7df554d101a68c58aa00 (diff)
added systemd generator
-rw-r--r--src/Makefile9
-rwxr-xr-xsrc/configure9
-rwxr-xr-xusr/lib/systemd/system-generator/anytun-generator23
3 files changed, 39 insertions, 2 deletions
diff --git a/src/Makefile b/src/Makefile
index ebd4f71..9d29cb5 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -311,12 +311,16 @@ install-etc:
install-systemd:
$(INSTALL) -d $(DESTDIR)$(SYSTEMDDIR)
$(INSTALL) -m 644 ../usr/lib/systemd/system/anytun.service $(DESTDIR)$(SYSTEMDDIR)/anytun.service
- @ sed -e 's#/usr/local/lib/#$(LIBDIR)/#' ../usr/lib/systemd/system/anytun@.service > ../usr/lib/systemd/system/anytun@.service.bak
- @ sed -e 's#/usr/local/lib/#$(LIBDIR)/#' ../usr/lib/systemd/system/anytun-controld@.service > ../usr/lib/systemd/system/anytun-controld@.service.bak
+ @ sed -e 's#/usr/local/lib#$(LIBDIR)#' ../usr/lib/systemd/system/anytun@.service > ../usr/lib/systemd/system/anytun@.service.bak
+ @ sed -e 's#/usr/local/lib#$(LIBDIR)#' ../usr/lib/systemd/system/anytun-controld@.service > ../usr/lib/systemd/system/anytun-controld@.service.bak
$(INSTALL) -m 644 ../usr/lib/systemd/system/anytun@.service.bak $(DESTDIR)$(SYSTEMDDIR)/anytun@.service
$(INSTALL) -m 644 ../usr/lib/systemd/system/anytun-controld@.service.bak $(DESTDIR)$(SYSTEMDDIR)/anytun-controld@.service
rm -f ../usr/lib/systemd/system/anytun@.service.bak
rm -f ../usr/lib/systemd/system/anytun-controld@.service.bak
+ $(INSTALL) -d $(DESTDIR)$(SYSTEMDGENERATORDIR)
+ @ sed -e 's#/usr/local/etc#$(ETCDIR)#' ../usr/lib/systemd/system-generator/anytun-generator > ../usr/lib/systemd/system-generator/anytun-generator.bak
+ $(INSTALL) -m 755 ../usr/lib/systemd/system-generator/anytun-generator.bak $(DESTDIR)$(SYSTEMDGENERATORDIR)/anytun-generator
+ rm -f ../usr/lib/systemd/system-generator/anytun-generator.bak
$(INSTALL) -d $(DESTDIR)$(TMPFILESDDIR)
$(INSTALL) -m 644 ../usr/lib/tmpfiles.d/anytun.conf $(DESTDIR)$(TMPFILESDDIR)/anytun.conf
@@ -373,6 +377,7 @@ remove-systemd:
rm -f $(DESTDIR)$(SYSTEMDDIR)/anytun.service
rm -f $(DESTDIR)$(SYSTEMDDIR)/anytun@.service
rm -f $(DESTDIR)$(SYSTEMDDIR)/anytun-controld@.service
+ rm -f $(DESTDIR)$(SYSTEMDGENERATORDIR)/anytun-generator
rm -f $(DESTDIR)$(TMPFILESDDIR)/anytun.conf
remove-examples:
diff --git a/src/configure b/src/configure
index 203a68c..082e523 100755
--- a/src/configure
+++ b/src/configure
@@ -66,6 +66,7 @@ INSTALLMANPAGE=1
EXAMPLESDIR=''
INSTALLEXAMPLES=1
SYSTEMDDIR=''
+SYSTEMDGENERATORDIR=''
TMPFILESDDIR=''
INSTALLSYSTEMD=1
@@ -87,6 +88,7 @@ print_usage() {
echo " --examplesdir=<DIR> the path to the examples files (default: $PREFIX/share/examples)"
echo " --no-examples don't install example files"
echo " --systemddir=<DIR> the path to the systemd service unit directory (default: from pkg-config)"
+ echo " --systemdgeneratordir=<DIR> the path to the systemd generator directory (default: from pkg-config)"
echo " --tmpfilesddir=<DIR> the path to the systemd tmpfiles.d configuration file (default: from pkg-config)"
echo " --no-systemd don't install systemd units"
echo " --use-gcrypt use libgcrypt (this is the default)"
@@ -144,6 +146,9 @@ do
--systemddir=*)
SYSTEMDDIR=${arg#--systemddir=}
;;
+ --systemdgeneratordir=*)
+ SYSTEMDGENERATORDIR=${arg#--systemdgeneratordir=}
+ ;;
--tmpfilesddir=*)
TMPFILESDDIR=${arg#--tmpfilesddir=}
;;
@@ -350,6 +355,9 @@ if [ $INSTALLSYSTEMD -eq 1 ]; then
if [ -z "$SYSTEMDDIR" ]; then
SYSTEMDDIR=`pkg-config systemd --variable=systemdsystemunitdir`
fi
+ if [ -z "$SYSTEMDGENERATORDIR" ]; then
+ SYSTEMDGENERATORDIR=`pkg-config systemd --variable=systemdsystemgeneratordir`
+ fi
if [ -z "$TMPFILESDDIR" ]; then
TMPFILESDDIR=`pkg-config systemd --variable=tmpfilesdir`
fi
@@ -395,6 +403,7 @@ fi
if [ $INSTALLSYSTEMD -eq 1 ]; then
echo "SYSTEMDDIR := $SYSTEMDDIR" >> include.mk
+ echo "SYSTEMDGENERATORDIR := $SYSTEMDGENERATORDIR" >> include.mk
echo "TMPFILESDDIR := $TMPFILESDDIR" >> include.mk
echo "installing systemd units"
else
diff --git a/usr/lib/systemd/system-generator/anytun-generator b/usr/lib/systemd/system-generator/anytun-generator
new file mode 100755
index 0000000..8e04ba9
--- /dev/null
+++ b/usr/lib/systemd/system-generator/anytun-generator
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+# This systemd generator creates dependency symlinks that make all anytun
+# tunnels listed in /etc/anytun/autostart be started/stopped/reloaded
+# when anytun.service is started/stopped/reloaded.
+
+set -eu
+
+GENDIR="$1"
+WANTDIR="$1/anytun.service.wants"
+SERVICEFILE="/lib/systemd/system/anytun@.service"
+AUTOSTART="all"
+CONFIG_DIR=/usr/local/etc/anytun
+
+mkdir -p "$WANTDIR"
+
+if [ -f $CONFIG_DIR/autostart ] ; then
+ for NAME in `sed 's/#.*//' < $CONFIG_DIR/autostart | grep -e '\w'`; do
+ ln -s "$SERVICEFILE" "$WANTDIR/anytun@$NAME.service"
+ done
+fi
+
+exit 0