From: "Jörg Thalheim" <joerg@higgsboson.tk>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH] add systemd service file
Date: Fri, 19 Dec 2014 14:02:58 +0100 [thread overview]
Message-ID: <20141219140258.787a4c4e@turingmachine> (raw)
[-- Attachment #1: Type: text/plain, Size: 4823 bytes --]
Signed-off-by: Jörg Thalheim <joerg@higgsboson.tk>
---
configure.ac | 34 ++++++++++++++++++++++++++++++++++
files/Makefile.am | 3 ++-
files/nftables/nftables.conf | 0
files/systemd/Makefile.am | 12 ++++++++++++
files/systemd/nftables-reload | 16 ++++++++++++++++
files/systemd/nftables.service | 12 ++++++++++++
6 files changed, 76 insertions(+), 1 deletion(-)
create mode 100644 files/nftables/nftables.conf
create mode 100644 files/systemd/Makefile.am
create mode 100755 files/systemd/nftables-reload
create mode 100644 files/systemd/nftables.service
diff --git a/configure.ac b/configure.ac
index 57ea99d..5adb223 100644
--- a/configure.ac
+++ b/configure.ac
@@ -13,6 +13,8 @@ AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([-Wall foreign subdir-objects
tar-pax no-dist-gzip dist-bzip2 1.6])
+AC_PATH_TOOL(PKGCONFIG, pkg-config)
+
dnl kernel style compile messages
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@@ -112,6 +114,36 @@ AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
+AC_ARG_WITH(systemd, [ --with-systemd set directory for systemd service files],
+ [systemd_unitdir="$withval"; with_systemd=yes],
+ [systemd_unitdir=""; with_systemd=no])
+AC_SUBST(systemd_unitdir)
+
+AC_ARG_WITH(systemdutildir, [ --with-systemdutildir set directory for systemd helper scripts],
+ [systemd_utildir="$withval"], [systemd_utildir=""])
+AC_SUBST(systemd_utildir)
+
+AM_CONDITIONAL([INSTALL_SYSTEMD], [test "x$with_systemd" != xno])
+AM_COND_IF([INSTALL_SYSTEMD],
+ [AS_IF([test "x$PKGCONFIG" = "x"],
+ [AC_MSG_ERROR(Need pkg-config to enable systemd support.)],
+
+ [AC_MSG_CHECKING(for systemd)
+ AS_IF([$PKGCONFIG --exists systemd],
+ [AC_MSG_RESULT(yes)
+ AS_IF([$PKGCONFIG --exists systemd],
+ [AS_IF([test "x$systemd_unit_dir" = "x"],
+ [ systemd_unitdir="`$PKGCONFIG --variable=systemdsystemunitdir systemd`"])
+ AS_IF([test "x$systemd_util_dir" = "x"],
+ [ systemd_utildir="`$PKGCONFIG --variable=systemdutildir systemd`"])
+ ])
+ ]
+ [AC_MSG_RESULT(no)])
+ ]
+
+ )]
+)
+
# Checks for library functions.
AC_CHECK_FUNCS([memmove memset strchr strdup strerror strtoull])
@@ -124,10 +156,12 @@ AC_CONFIG_FILES([ \
doc/Makefile \
files/Makefile \
files/nftables/Makefile \
+ files/systemd/Makefile \
])
AC_OUTPUT
echo "
nft configuration:
cli support: ${with_cli}
+ systemd support: ${with_systemd}
enable debugging: ${with_debug}"
diff --git a/files/Makefile.am b/files/Makefile.am
index a8394c0..4dc0027 100644
--- a/files/Makefile.am
+++ b/files/Makefile.am
@@ -1 +1,2 @@
-SUBDIRS = nftables
+SUBDIRS = nftables \
+ systemd
diff --git a/files/nftables/nftables.conf b/files/nftables/nftables.conf
new file mode 100644
index 0000000..e69de29
diff --git a/files/systemd/Makefile.am b/files/systemd/Makefile.am
new file mode 100644
index 0000000..c0a56c8
--- /dev/null
+++ b/files/systemd/Makefile.am
@@ -0,0 +1,12 @@
+
+if INSTALL_SYSTEMD
+systemd_unit_DATA = nftables.service
+
+systemd_scriptsdir = ${systemd_utildir}/scripts
+systemd_scripts_SCRIPTS = nftables-reload
+
+install-data-hook:
+ ${SED} -i 's|@sbindir[@]|${sbindir}/|g;s|@sysconfdir[@]|${sysconfdir}/|g;s|@systemd_scriptsdir[@]|${systemd_scriptsdir}/|g' \
+ ${DESTDIR}${systemd_scriptsdir}/nftables-reload \
+ ${DESTDIR}${systemd_unitdir}/nftables.service
+endif
diff --git a/files/systemd/nftables-reload b/files/systemd/nftables-reload
new file mode 100755
index 0000000..0fcc2ad
--- /dev/null
+++ b/files/systemd/nftables-reload
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+set -e
+
+if [ ! -f @sysconfdir@nftables.conf ]
+then
+ echo "/etc/nftables.conf does not exist" >&2
+ exit 1
+fi
+
+tmp=${TMPDIR-/tmp}
+rules=`mktemp "$tmp/nftables.XXXXXXX"`
+trap "rm -f $tmpfile" 0 1 2 3 15
+echo "flush ruleset" > "$rules"
+cat @sysconfdir@nftables.conf >> "$rules"
+@sbindir@nft -f "$rules"
diff --git a/files/systemd/nftables.service b/files/systemd/nftables.service
new file mode 100644
index 0000000..f958bfc
--- /dev/null
+++ b/files/systemd/nftables.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=nftables
+Documentation=man:nft(8)
+
+[Service]
+RemainAfterExit=yes
+ExecStart=@sbindir@nft -I /etc/nftables -f /etc/nftables.conf
+ExecStop=@sbindir@nft flush ruleset
+ExecReload=@systemd_scriptsdir@nftables-reload
+
+[Install]
+WantedBy=multi-user.target
--
2.2.0
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next reply other threads:[~2014-12-19 13:03 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-19 13:02 Jörg Thalheim [this message]
2014-12-19 13:08 ` [PATCH] add systemd service file Jörg Thalheim
2014-12-23 14:20 ` Pablo Neira Ayuso
-- strict thread matches above, loose matches on Subject: below --
2014-12-18 20:10 Jörg Thalheim
2014-12-18 20:12 ` Jörg Thalheim
[not found] <20141218133524.4d6e2539@turingmachine>
2014-12-18 12:47 ` Jörg Thalheim
2014-12-18 12:51 ` Pablo Neira Ayuso
2014-12-18 12:47 Jörg Thalheim
2014-12-18 12:56 ` Jan Engelhardt
2014-12-18 13:02 ` Jörg Thalheim
2014-12-18 13:14 ` Jan Engelhardt
2014-12-17 19:54 Jörg Thalheim
2014-12-17 20:37 ` Arturo Borrero Gonzalez
2014-12-17 20:40 ` Jörg Thalheim
2014-12-17 20:55 ` Jan Engelhardt
2014-12-17 21:02 ` Jörg Thalheim
2014-12-17 20:50 ` Arturo Borrero Gonzalez
2014-12-17 20:55 ` Jan Engelhardt
2014-12-17 20:57 ` Jörg Thalheim
2014-12-17 21:10 ` Arturo Borrero Gonzalez
2014-12-17 21:36 ` Jörg Thalheim
2014-12-18 7:50 ` Jörg Thalheim
2014-12-17 21:12 ` Jörg Thalheim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141219140258.787a4c4e@turingmachine \
--to=joerg@higgsboson.tk \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).