Package: xorp
Version: 1.8.5-4.1
Severity: normal
Tags: patch
Usertags: systemd-units
X-Debbugs-CC: [email protected]

Dear Maintainer,

The attached patch incorporates systemd integration and notifications
via sd_notify to xorp_rtrmgr. It has been tested in a production router,
the tests were limited to the start, stop, restart and logging behaviour.

The patch also routes the log to the journal via stderr, therefore
eliminating the weekly restart performed by logrotate. That restart was
failing in a somewhat loaded router until the proposed changes where
applied. It was also found that the default output log setup was failing
to work with systemd and it was changed to a simple one which, as far as
I know, should be very portable.

The unit file was sent to the systemd maintainers for review and their
helpful directions have been followed.

I hope this patch can be useful.

Regards,


-- System Information:
Debian Release: 8.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.16.0-4-amd64 (SMP w/1 CPU core)
Locale: LANG=es_VE.UTF-8, LC_CTYPE=es_VE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages xorp depends on:
ii  adduser              3.113+nmu3
ii  init-system-helpers  1.22
ii  libc6                2.19-18+deb8u1
ii  libgcc1              1:4.9.2-10
ii  libncurses5          5.9+20140913-1+b1
ii  libpcap0.8           1.6.2-2
ii  libssl1.0.0          1.0.1k-3+deb8u1
ii  libstdc++6           4.9.2-10
ii  libsystemd0          215-17+deb8u2
ii  libtinfo5            5.9+20140913-1+b1

Versions of packages xorp recommends:
ii  iputils-ping       3:20121221-5+b2
ii  iputils-tracepath  3:20121221-5+b2
ii  traceroute         1:2.0.20-2+b1

xorp suggests no packages.

-- Configuration Files:
/etc/default/xorp changed [not included]
/etc/xorp/config.boot changed [not included]

-- no debconf information



-- 
Dhionel Díaz
Centro Nacional de Desarrollo e Investigación en Tecnologías Libres
Ministerio del Poder Popular para
Educación Universitaria, Ciencia y Tecnología
diff -u xorp-1.8.5/debian/control xorp-1.8.5/debian/control
--- xorp-1.8.5/debian/control
+++ xorp-1.8.5/debian/control
@@ -7,6 +7,7 @@
  scons, libboost-dev,
  autotools-dev, quilt, libssl-dev, 
  libncurses5-dev | ncurses-dev, docbook-to-man, libpcap0.8-dev,
+ dh-systemd, libsystemd-dev, pkg-config,
 Build-Conflicts: iptables-dev
 Standards-Version: 3.9.5
 Homepage: http://www.xorp.org
diff -u xorp-1.8.5/debian/patches/series xorp-1.8.5/debian/patches/series
--- xorp-1.8.5/debian/patches/series
+++ xorp-1.8.5/debian/patches/series
@@ -13,0 +14,2 @@
+default_log_output.patch
+sd_notify_rtrmgr.patch
diff -u xorp-1.8.5/debian/rules xorp-1.8.5/debian/rules
--- xorp-1.8.5/debian/rules
+++ xorp-1.8.5/debian/rules
@@ -22,11 +22,11 @@
 DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
 DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
 
-# Personall Variables
+# Personal Variables
 PACKNAME=$(shell dh_listpackages)
 PACKAGE=$(shell dh_listpackages)
 
-# Variabels used by the Debian Maintainer exclusively for package
+# Variables used by the Debian Maintainer exclusively for package
 # development.
 SOURCENAME=$(shell dpkg-parsechangelog | grep "Source:" | cut -d ' ' -f 2)
 DEBVER=$(shell dpkg-parsechangelog | grep "Version:" | cut -d ' ' -f 2)
@@ -57,6 +57,7 @@
 		sysconfdir=/etc \
 		with-olsr=true \
 		disable_fw=true \
+		enable_systemd=true \
 		CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS='-Wl,-z,defs'
 
 #SCONSFLAGS += CC=gcc-4.6 CXX=g++-4.6
@@ -165,7 +166,9 @@
 	dh_installdocs
 	dh_installexamples -pxorp rtrmgr/config/*.boot debian/config.boot.mcast  rtrmgr/config/README
 	dh_installlogrotate
+	dh_systemd_enable
 	dh_installinit
+	dh_systemd_start
 	dh_installman 
 	dh_link
 	dh_strip
diff -u xorp-1.8.5/debian/xorp.postinst xorp-1.8.5/debian/xorp.postinst
--- xorp-1.8.5/debian/xorp.postinst
+++ xorp-1.8.5/debian/xorp.postinst
@@ -41,6 +41,7 @@
 	        --system \
 		--ingroup $XORPGROUP \
 		--no-create-home \
+		--home $LOGDIR \
 		--disabled-password \
 		$XORPUSER 2>/dev/null || true
 	fi
only in patch2:
unchanged:
--- xorp-1.8.5.orig/debian/patches/default_log_output.patch
+++ xorp-1.8.5/debian/patches/default_log_output.patch
@@ -0,0 +1,34 @@
+Description: Simplify and fix default log output setup.
+Author: Dhionel Díaz <[email protected]>
+Last-Update: 2015-09-09
+
+---
+--- a/libxorp/xlog.c
++++ b/libxorp/xlog.c
+@@ -798,24 +798,8 @@
+ 	return (xlog_add_output(fp));
+ 
+ #else /* !HOST_OS_WINDOWS */
+-
+-    const char* defaults[] = {	/* The default outputs (in preference order) */
+-	"/dev/stderr",		/* XXX: temporary this is the default */
+-	"/dev/console",
+-	"/dev/stdout"
+-    };
+-    size_t ndefaults = sizeof(defaults) / sizeof(defaults[0]);
+-    size_t i;
+-
+-    /*
+-     * Attempt to open default output stream, console first in case
+-     * we are root, then stderr.
+-     */
+-    for (i = 0; fp_default == NULL && i < ndefaults; i++) {
+-	if ((fp_default = fopen(defaults[i], "w")) != NULL) {
+-	    return (xlog_add_output(fp_default));
+-	}
+-    }
++    if((fp_default = fdopen(dup(STDERR_FILENO), "w")) != NULL)
++	return (xlog_add_output(fp_default));
+ #endif /* HOST_OS_WINDOWS */
+ 
+     return -1;
only in patch2:
unchanged:
--- xorp-1.8.5.orig/debian/patches/sd_notify_rtrmgr.patch
+++ xorp-1.8.5/debian/patches/sd_notify_rtrmgr.patch
@@ -0,0 +1,104 @@
+Description: Add support to systemd integration via status notifications
+Author: Dhionel Díaz <[email protected]>
+Last-Update: 2015-09-10
+
+---
+--- a/rtrmgr/main_rtrmgr.cc
++++ b/rtrmgr/main_rtrmgr.cc
+@@ -65,6 +65,9 @@
+ #include <getopt.h>
+ #endif
+ 
++#ifdef XORP_USE_SYSTEMD
++#include <systemd/sd-daemon.h>
++#endif
+ 
+ //
+ // Default values
+@@ -358,6 +361,11 @@
+ 	}
+ 
+ 	_ready = true;
++#ifdef XORP_USE_SYSTEMD
++	// Notify systemd that service startup has been successfully completed
++	sd_notify(0, "READY=1\n"
++		"STATUS=Startup successfully completed.");
++#endif
+ 	//
+ 	// Loop while handling configuration events and signals
+ 	//
+@@ -369,6 +377,11 @@
+ 	}
+ 	fflush(stdout);
+ 	_ready = false;
++#ifdef XORP_USE_SYSTEMD
++	// Notify systemd that the service is beginning its shutdown
++	sd_notify(0, "STOPPING=1\n"
++		"STATUS=Shutdown process started.");
++#endif
+ 
+ 	//
+ 	// Shutdown everything
+@@ -782,5 +795,9 @@
+     xlog_stop();
+     xlog_exit();
+ 
++#ifdef XORP_USE_SYSTEMD
++	// Send final status message to systemd
++	sd_notify(0, "STATUS=Exiting.");
++#endif
+     exit(errcode);
+ }
+--- a/SConstruct
++++ b/SConstruct
+@@ -83,6 +83,7 @@
+     BoolVariable('disable_profile',  'Disable Xorp Profiler feature', False),
+     BoolVariable('enable_boost',  'Use BOOST', False),
+     BoolVariable('enable_ustl',  'Use uSTL', False),
++    BoolVariable('enable_systemd',  'Use systemd', False),
+     BoolVariable('enable_bgp',  'Build BGP', True),
+     BoolVariable('enable_buildinfo',  'Build Info, see libxorp/create_buildinfo.sh', True),
+     BoolVariable('enable_olsr',  'Build OLSR', True),
+@@ -274,6 +275,7 @@
+ print 'Enable BuildInfo: ', env['enable_buildinfo']
+ print 'Try Enable BOOST: ', env['enable_boost']
+ print 'Try Enable uSTL : ', env['enable_ustl']
++print 'Try Enable systemd: ', env['enable_systemd']
+ print 'Disable IPv6:     ', env['disable_ipv6']
+ print 'Disable libtecla: ', env['disable_libtecla']
+ print 'Disable Firewall: ', env['disable_fw']
+@@ -396,6 +398,12 @@
+ else:
+     env['enable_ustl'] = False
+ 
++tst = ARGUMENTS.get('enable_systemd', False)
++if tst and not (tst == "no"):
++    env['enable_systemd'] = True
++else:
++    env['enable_systemd'] = False
++
+ tst = ARGUMENTS.get('enable_tests', False)
+ if tst and not (tst == "no"):
+     env['enable_tests'] = True
+@@ -654,6 +662,9 @@
+         #  so just over-ride it here and assume it exists.
+         conf.Define('HAS_BOOST_NONCOPYABLE_INC')
+ 
++    if env['enable_systemd']:
++        conf.Define('XORP_USE_SYSTEMD')
++
+     # Big ball of mud.
+     from config.allconfig import DoAllConfig
+     DoAllConfig(env, conf, host_os)
+--- a/rtrmgr/SConscript
++++ b/rtrmgr/SConscript
+@@ -175,6 +175,9 @@
+ 
+     rtrmgr_env.Append(LIBS = ['xorp_core', 'crypto'])
+ 
++if rtrmgr_env['enable_systemd']:
++    rtrmgr_env.ParseConfig("pkg-config --cflags --libs libsystemd")
++
+ 
+ rtrmgr_srcs = [
+ 	'main_rtrmgr.cc',
only in patch2:
unchanged:
--- xorp-1.8.5.orig/debian/xorp.service
+++ xorp-1.8.5/debian/xorp.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=eXtensible Open Router Platform
+After=network.target
+
+[Service]
+Type=notify
+EnvironmentFile=-/etc/default/xorp
+ExecStart=/usr/sbin/xorp_rtrmgr $DAEMON_OPTS
+TimeoutStopSec=233
+Restart=always
+
+[Install]
+WantedBy=multi-user.target


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to