[arch-commits] Commit in dnsmasq/trunk (5 files)
Dave Reisner
dreisner at archlinux.org
Sun Sep 11 16:01:13 UTC 2011
Date: Sunday, September 11, 2011 @ 12:01:12
Author: dreisner
Revision: 137812
numerous improvements to startup behavior
- create and run as dnsmasq user, as per upstream recommendation
- add checkconfig option to /etc/rc.d script
- add /etc/conf.d file, for adding arbitrary options
- use our own systemd service file, which mirrors the above behavior
- use dnsmasq's own pidfile, rather than managing the pid ourselves
Added:
dnsmasq/trunk/dnsmasq.confd
dnsmasq/trunk/dnsmasq.install
dnsmasq/trunk/dnsmasq.service
Modified:
dnsmasq/trunk/PKGBUILD
dnsmasq/trunk/rc.dnsmasq
-----------------+
PKGBUILD | 20 +++++++++++++-------
dnsmasq.confd | 9 +++++++++
dnsmasq.install | 21 +++++++++++++++++++++
dnsmasq.service | 13 +++++++++++++
rc.dnsmasq | 47 ++++++++++++++++++++++++++++++++---------------
5 files changed, 88 insertions(+), 22 deletions(-)
Modified: PKGBUILD
===================================================================
--- PKGBUILD 2011-09-11 15:35:27 UTC (rev 137811)
+++ PKGBUILD 2011-09-11 16:01:12 UTC (rev 137812)
@@ -5,19 +5,23 @@
pkgname=dnsmasq
pkgver=2.58
-pkgrel=1
+pkgrel=2
pkgdesc="Lightweight, easy to configure DNS forwarder and DHCP server"
url="http://www.thekelleys.org.uk/dnsmasq/doc.html"
arch=('i686' 'x86_64')
license=('GPL')
depends=('glibc' 'bash' 'dbus-core')
makedepends=('libcap>=2.16')
-backup=('etc/dnsmasq.conf')
-install=
-source=("http://www.thekelleys.org.uk/$pkgname/$pkgname-$pkgver.tar.gz"
- 'rc.dnsmasq')
+install=$pkgname.install
+backup=('etc/dnsmasq.conf'
+ 'etc/conf.d/dnsmasq')
+source=("http://www.thekelleys.org.uk/$pkgname/$pkgname-$pkgver.tar.gz"
+ 'dnsmasq.confd'
+ 'rc.dnsmasq'
+ 'dnsmasq.service')
md5sums=('14c5c81debb324adc261db971730f4c6'
- 'e956eee1ec24212a3254d2b168187495')
+ '66479e99123faeab83ebaed709ef95b5'
+ '5d1abd670b3ef093b90a28d3b9ba802e')
build() {
cd "$srcdir/$pkgname-$pkgver"
@@ -35,9 +39,11 @@
install -dm755 "$pkgdir"/var/{db,lib/misc}
install -Dm755 "$srcdir"/rc.dnsmasq "$pkgdir"/etc/rc.d/dnsmasq
+ install -Dm644 "$srcdir"/dnsmasq.confd "$pkgdir/etc/conf.d/dnsmasq"
+
install -Dm644 "dbus/dnsmasq.conf" "$pkgdir"/etc/dbus-1/system.d/dnsmasq.conf
install -Dm644 "dnsmasq.conf.example" "$pkgdir"/etc/dnsmasq.conf
- install -Dm644 "contrib/systemd/dnsmasq.service" "$pkgdir"/lib/systemd/system/dnsmasq.service
+ install -Dm644 "$srcdir/dnsmasq.service" "$pkgdir"/lib/systemd/system/dnsmasq.service
}
# vim: ts=2 sw=2 et ft=sh
Added: dnsmasq.confd
===================================================================
--- dnsmasq.confd (rev 0)
+++ dnsmasq.confd 2011-09-11 16:01:12 UTC (rev 137812)
@@ -0,0 +1,9 @@
+#
+# runtime config for dnsmasq
+#
+
+# if unset, dnsmasq will run as nobody.
+DNSMASQ_USER=dnsmasq
+
+# other runtime options. treated as an array.
+DNSMASQ_OPTS=()
Added: dnsmasq.install
===================================================================
--- dnsmasq.install (rev 0)
+++ dnsmasq.install 2011-09-11 16:01:12 UTC (rev 137812)
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+add_dnsmasq_user() {
+ if ! getent passwd dnsmasq >/dev/null; then
+ useradd -r -d / -c 'dnsmasq daemon' -s /sbin/nologin dnsmasq
+ fi
+}
+
+post_install() {
+ add_dnsmasq_user
+}
+
+post_upgrade() {
+ add_dnsmasq_user
+}
+
+post_remove() {
+ if getent passwd dnsmasq >/dev/null; then
+ userdel dnsmasq
+ fi
+}
Added: dnsmasq.service
===================================================================
--- dnsmasq.service (rev 0)
+++ dnsmasq.service 2011-09-11 16:01:12 UTC (rev 137812)
@@ -0,0 +1,13 @@
+[Unit]
+Description=A lightweight DHCP and caching DNS server
+
+[Service]
+Type=dbus
+BusName=uk.org.thekelleys.dnsmasq
+ExecStartPre=/usr/sbin/dnsmasq --test
+ExecStart=/usr/sbin/dnsmasq -k --enable-dbus --user=dnsmasq --pid-file
+ExecReload=/bin/kill -HUP $MAINPID
+
+[Install]
+WantedBy=multi-user.target
+Alias=dbus-uk.org.thekelleys.dnsmasq
Modified: rc.dnsmasq
===================================================================
--- rc.dnsmasq 2011-09-11 15:35:27 UTC (rev 137811)
+++ rc.dnsmasq 2011-09-11 16:01:12 UTC (rev 137812)
@@ -2,35 +2,52 @@
. /etc/rc.conf
. /etc/rc.d/functions
+. /etc/conf.d/dnsmasq
-PID=`pidof -o %PPID /usr/sbin/dnsmasq`
-case "$1" in
+pidfile=/run/dnsmasq.pid
+if [[ -r $pidfile ]]; then
+ read -r PID < "$pidfile"
+ if [[ ! -d /proc/$PID ]]; then
+ # stale pidfile
+ unset PID
+ rm -f "$pidfile"
+ fi
+fi
+
+case $1 in
start)
stat_busy "Starting DNS/DHCP daemon"
- [ -z "$PID" ] && /usr/sbin/dnsmasq
- if [ $? -gt 0 ] ; then
+ if [[ -z $PID ]] && /usr/sbin/dnsmasq --test &&
+ /usr/sbin/dnsmasq "--user=${DNSMASQ_USER:-nobody}" \
+ "--pid-file=$pidfile" \
+ "${DNSMASQ_OPTS[@]}"; then
+ add_daemon dnsmasq
+ stat_done
+ else
stat_fail
- else
- add_daemon dnsmasq # create the 'state' dir
- stat_done
fi
;;
stop)
stat_busy "Stopping DNS/DHCP daemon"
- [ "$PID" ] && kill $PID &> /dev/null
- if [ $? -gt 0 ]; then
+ if [[ $PID ]] && kill "$PID" &> /dev/null; then
+ # dnsmasq doesn't clean up after itself
+ rm -f "$pidfile"
+ rm_daemon dnsmasq
+ stat_done
+ else
stat_fail
- else
- rm_daemon dnsmasq # remove the 'state' dir
- stat_done
fi
;;
restart)
$0 stop
- sleep 5
+ sleep 1
$0 start
;;
+ checkconfig)
+ # diagnostics will be printed, with zero/non-zero exit
+ /usr/sbin/dnsmasq --test
+ ;;
*)
- echo "usage: $0 {start|stop|restart}"
+ echo "usage: $0 <start|stop|restart|checkconfig>"
esac
-exit 0
+
More information about the arch-commits
mailing list