add systemd service file
PATCH 1/1 add systemd service file
Signed-off-by Jörg Thalheim <[email protected]>
--- 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
configure.ac +34 -0
@@ -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}"
files/Makefile.am +2 -1
@@ -1 +1,2 @@ -SUBDIRS = nftables +SUBDIRS = nftables \ + systemd
files/nftables/nftables.conf new file +0 -0
files/systemd/Makefile.am new file +12 -0
@@ -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
files/systemd/nftables-reload new file +16 -0
@@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +if [ ! -f @[email protected] ] +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 @[email protected] >> "$rules" +@sbindir@nft -f "$rules"
files/systemd/nftables.service new file +12 -0
@@ -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
Signature · 1 line
2.2.0
- fixes tempfile creation in the reload script
Anything left from your side?
This will be the first nftables init script with support for atomic reloading!
Pablo Neira Ayuso
maintainerQuoted 13 lines · Jörg Thalheim
Signed-off-by Jörg Thalheim <[email protected]>--- 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
I'd prefer if distributors take care of this instead, I think these scripts are glue integration code. Looking at what it happened to other userspace netfilter codebase, my experience is that they tend to get rotten unmaintained in the source code tree.
Thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html