]> granicus.if.org Git - pdns/commitdiff
Add dnsdist user when installing RPMs
authorPieter Lexis <pieter.lexis@powerdns.com>
Wed, 13 Apr 2016 08:04:01 +0000 (10:04 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Mon, 18 Apr 2016 08:00:59 +0000 (10:00 +0200)
build-scripts/build-dnsdist-rpm
pdns/dnsdistdist/contrib/dnsdist.init.centos6

index c50fc8220f696fdbf9ffdb328c4ffd62453792db..71b87577bcb6de233e12fd73ffd1890ab85c23f4 100755 (executable)
@@ -40,8 +40,7 @@ SODIUM_CONFIGURE=''
 
 # Some RPM platforms use systemd, others sysv, we default to systemd here
 INIT_BUILDREQUIRES='BuildRequires: systemd-devel'
-#INIT_INSTALL='install -d -m 755 %{buildroot}/lib/systemd/system/ && install -m 664 dnsdist.service %{buildroot}/lib/systemd/system/dnsdist.service'
-INIT_INSTALL=''
+INIT_INSTALL='sed -i "s!/dnsdist!/dnsdist -u dnsdist -g dnsdist!" %{buildroot}/lib/systemd/system/dnsdist.service'
 INIT_FILES='/lib/systemd/system/dnsdist.service'
 INIT_CONFIGURE='--enable-systemd --with-systemd=/lib/systemd/system \'
 
@@ -89,6 +88,7 @@ License: GPLv2
 Vendor: PowerDNS.COM BV
 Group: System/DNS
 Source: dnsdist-${TARBALLVERSION}.tar.bz2
+Requires(pre): shadow-utils
 BuildRequires: readline-devel
 BuildRequires: boost-devel
 BuildRequires: lua-devel
@@ -115,6 +115,41 @@ install -d %{buildroot}/%{_sysconfdir}/dnsdist
 ${INIT_INSTALL}
 ${DEFAULTS_INSTALL}
 
+%pre
+getent group dnsdist >/dev/null || groupadd -r dnsdist
+getent passwd dnsdist >/dev/null || \
+       useradd -r -g dnsdist -d / -s /sbin/nologin \
+       -c "dnsdist user" dnsdist
+exit 0
+
+
+%post
+%if 0%{?el6}
+/sbin/chkconfig --add %{name}
+%else
+%systemd_post %{name}.service
+%endif
+
+%preun
+%if 0%{?el6}
+if [ "\$1" -eq "0" ]; then
+  # Package removal, not upgrade
+  /sbin/service %{name} stop > /dev/null 2>&1 || :
+  /sbin/chkconfig --del %{name}
+fi
+%else
+%systemd_preun %{name}.service
+%endif
+
+%postun
+%if 0%{?el6}
+if [ "\$1" -ge "1" ] ; then
+  /sbin/service %{name} condrestart >/dev/null 2>&1 || :
+fi
+%else
+%systemd_postun_with_restart %{name}.service
+%endif
+
 %files
 %{!?_licensedir:%global license %%doc}
 %license COPYING
index 071fa0b35aadc0d6550bd3232fd1fa923b46b670..ebd8ce0218ee91b2c97b23221e253f97ee88e206 100644 (file)
@@ -17,6 +17,8 @@
 PROG=dnsdist
 DNSDIST=/usr/bin/${PROG}
 PIDFILE=/var/run/${PROG}.pid
+DNSDIST_USER='dnsdist'
+DNSDIST_GROUP='dnsdist'
 DNSDIST_OPTIONS=""
 
 if [ -f /etc/default/${PROG} ]; then
@@ -31,7 +33,7 @@ RETVAL=0
 
 do_start() {
   echo -n "Starting ${PROG}..."
-  daemon --pidfile=${PIDFILE} $DNSDIST -d -p ${PIDFILE} ${DNSDIST_OPTIONS}
+  daemon --pidfile=${PIDFILE} $DNSDIST -u ${DNSDIST_USER} -g ${DNSDIST_GROUP} -d -p ${PIDFILE} ${DNSDIST_OPTIONS}
   ret=$?
   echo
   return $ret