autofs-5.0.5 - add systemd unit support From: Ian Kent Add a systemd unit file and attempt to integrating it into our install. --- CHANGELOG | 1 + Makefile.conf.in | 2 ++ aclocal.m4 | 28 ++++++++++++++++++++++ autofs.spec | 58 ++++++++++++++++++++++++++++++++++++++++----- configure | 47 ++++++++++++++++++++++++++++++++++++ configure.in | 9 +++++++ redhat/Makefile | 10 ++++++-- samples/Makefile | 23 +++++++++++++----- samples/autofs.service.in | 12 +++++++++ 9 files changed, 176 insertions(+), 14 deletions(-) create mode 100644 samples/autofs.service.in diff --git a/CHANGELOG b/CHANGELOG index c2a7b1f..d951b5a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -18,6 +18,7 @@ - fix ipv6 rpc calls. - fix ipv6 configure check. - add piddir to configure. +- add systemd unit support. 28/06/2011 autofs-5.0.6 ----------------------- diff --git a/Makefile.conf.in b/Makefile.conf.in index f49dbd0..fa4936d 100644 --- a/Makefile.conf.in +++ b/Makefile.conf.in @@ -98,3 +98,5 @@ mandir = @mandir@ # Location for init.d files initdir = @initdir@ +# Location of systemd unit files +systemddir = @systemddir@ diff --git a/aclocal.m4 b/aclocal.m4 index 461801d..7cfc7ef 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -199,6 +199,34 @@ fi], [AC_MSG_RESULT(no)]) ]) dnl -------------------------------------------------------------------------- +dnl AF_WITH_SYSTEMD +dnl +dnl Check the location of the systemd unit files directory +dnl -------------------------------------------------------------------------- +AC_DEFUN([AF_WITH_SYSTEMD], +[AC_ARG_WITH(systemd, +[ --with-systemd install systemd unit file if systemd unit directory + is found on system], +[if test "$withval" = yes; then + if test -z "$systemddir"; then + AC_MSG_CHECKING([location of the systemd unit files directory]) + for systemd_d in /lib/systemd/system; do + if test -z "$systemddir"; then + if test -d "$systemd_d"; then + systemddir="$systemd_d" + fi + fi + done + fi + if test -n "$systemddir"; then + AC_MSG_RESULT($systemddir) + else + AC_MSG_RESULT(not found) + fi +fi]) +]) + +dnl -------------------------------------------------------------------------- dnl AF_CHECK_LIBXML dnl dnl Check for lib xml diff --git a/autofs.spec b/autofs.spec index 510ef76..d854b1f 100644 --- a/autofs.spec +++ b/autofs.spec @@ -8,6 +8,10 @@ %define _lib lib64 %endif +# Use --without systemd in your rpmbuild command or force values to 0 to +# disable them. +%define with_systemd %{?_without_systemd: 0} %{?!_without_systemd: 1} + Summary: A tool from automatically mounting and umounting filesystems. Name: autofs %define version 5.0.6 @@ -18,9 +22,18 @@ License: GPL Group: System Environment/Daemons Source: ftp://ftp.kernel.org/pub/linux/daemons/autofs/v4/autofs-%{version}.tar.gz Buildroot: %{_tmppath}/%{name}-tmp +%if %{with_systemd} +BuildRequires: systemd-units +%endif BuildPrereq: autoconf, hesiod-devel, openldap-devel, bison, flex, cyrus-sasl-devel Prereq: chkconfig Requires: /bin/bash mktemp sed textutils sh-utils grep /bin/ps +%if %{with_systemd} +Requires(post): systemd-sysv +Requires(post): systemd-units +Requires(preun): systemd-units +Requires(postun): systemd-units +%endif Obsoletes: autofs-ldap Summary(de): autofs daemon Summary(fr): démon autofs @@ -55,14 +68,22 @@ inkludera n %prep %setup -q echo %{version}-%{release} > .version +%if %{with_systemd} + %define _unitdir %{?_unitdir:/lib/systemd/system} + %define systemd_configure_arg --with-systemd +%endif %build -CFLAGS="$RPM_OPT_FLAGS -Wall" ./configure --libdir=%{_libdir} --disable-mount-locking --enable-ignore-busy --with-libtirpc --disable-mount-move +CFLAGS="$RPM_OPT_FLAGS -Wall" ./configure --libdir=%{_libdir} --disable-mount-locking --enable-ignore-busy --with-libtirpc --disable-mount-move %{?systemd_configure_arg:} CFLAGS="$RPM_OPT_FLAGS -Wall" make initdir=/etc/rc.d/init.d DONTSTRIP=1 %install rm -rf $RPM_BUILD_ROOT +%if %{with_systemd} +install -d -m 755 $RPM_BUILD_ROOT%{_unitdir} +%else mkdir -p -m755 $RPM_BUILD_ROOT/etc/rc.d/init.d +%endif mkdir -p -m755 $RPM_BUILD_ROOT%{_sbindir} mkdir -p -m755 $RPM_BUILD_ROOT%{_libdir}/autofs mkdir -p -m755 $RPM_BUILD_ROOT%{_mandir}/{man5,man8} @@ -70,31 +91,56 @@ mkdir -p -m755 $RPM_BUILD_ROOT/etc/sysconfig mkdir -p -m755 $RPM_BUILD_ROOT/etc/auto.master.d make install mandir=%{_mandir} initdir=/etc/rc.d/init.d INSTALLROOT=$RPM_BUILD_ROOT +echo make -C redhat make -C redhat +%if %{with_systemd} +install -m 644 redhat/autofs.service $RPM_BUILD_ROOT%{_unitdir}/autofs.service +%else install -m 755 redhat/autofs.init $RPM_BUILD_ROOT/etc/rc.d/init.d/autofs +%endif install -m 644 redhat/autofs.sysconfig $RPM_BUILD_ROOT/etc/sysconfig/autofs %clean [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT %post +%if %{with_systemd} +/bin/systemctl daemon-reload >/dev/null 2>&1 || : +%else chkconfig --add autofs - -%postun -if [ $1 -ge 1 ] ; then - /sbin/service autofs condrestart > /dev/null 2>&1 || : -fi +%endif %preun if [ "$1" = 0 ] ; then +%if %{with_systemd} + /bin/systemctl --no-reload disable autofs.service > /dev/null 2>&1 || : + /bin/systemctl stop autofs.service > /dev/null 2>&1 || : +%else /sbin/service autofs stop > /dev/null 2>&1 || : /sbin/chkconfig --del autofs +%endif fi +%postun +%if %{with_systemd} +/bin/systemctl daemon-reload >/dev/null 2>&1 || : +if [ $1 -ge 1 ] ; then + /bin/systemctl try-restart autofs.service >/dev/null 2>&1 || : +fi +%else +if [ $1 -ge 1 ] ; then + /sbin/service autofs condrestart > /dev/null 2>&1 || : +fi +%endif + %files %defattr(-,root,root) %doc CREDITS CHANGELOG INSTALL COPY* README* samples/ldap* samples/autofs.schema samples/autofs_ldap_auth.conf +%if %{with_systemd} +%{_unitdir}/autofs.service +%else %config /etc/rc.d/init.d/autofs +%endif %config(noreplace) /etc/auto.master %config(noreplace,missingok) /etc/auto.misc %config(noreplace,missingok) /etc/auto.net diff --git a/configure b/configure index 0d014c1..86a0d74 100755 --- a/configure +++ b/configure @@ -650,6 +650,8 @@ flagdir fifodir mapdir confdir +systemddir +piddir initdir target_alias host_alias @@ -693,6 +695,7 @@ ac_subst_files='' ac_user_opts=' enable_option_checking with_path +with_systemd with_confdir with_mapdir with_fifodir @@ -1337,6 +1340,8 @@ Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-path=PATH look in PATH for binaries needed by the automounter + --with-systemd install systemd unit file if systemd unit directory + is found on system --with-confdir=DIR use DIR for autofs configuration files --with-mapdir=PATH look in PATH for mount maps used by the automounter --with-fifodir=PATH use PATH as the directory for fifos used by the automounter @@ -2119,6 +2124,48 @@ $as_echo "$initdir" >&6; } done fi +if test -z "$piddir"; then + for pid_d in /run /var/run /tmp; do + if test -z "$piddir"; then + if test -d "$pid_d"; then + piddir="$pid_d" + fi + fi + done +fi + + +# +# Check for systemd unit files direectory exists if unit file installation +# is requested +# + +# Check whether --with-systemd was given. +if test "${with_systemd+set}" = set; then : + withval=$with_systemd; if test "$withval" = yes; then + if test -z "$systemddir"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking location of the systemd unit files directory" >&5 +$as_echo_n "checking location of the systemd unit files directory... " >&6; } + for systemd_d in /lib/systemd/system; do + if test -z "$systemddir"; then + if test -d "$systemd_d"; then + systemddir="$systemd_d" + fi + fi + done + fi + if test -n "$systemddir"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $systemddir" >&5 +$as_echo "$systemddir" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 +$as_echo "not found" >&6; } + fi +fi +fi + + + # # Location of system config script directory? diff --git a/configure.in b/configure.in index d3e4e54..05ee67f 100644 --- a/configure.in +++ b/configure.in @@ -43,6 +43,15 @@ AF_LINUX_PROCFS() # AF_INIT_D() AC_SUBST(initdir) +AF_PID_D() +AC_SUBST(piddir) + +# +# Check for systemd unit files direectory exists if unit file installation +# is requested +# +AF_WITH_SYSTEMD() +AC_SUBST(systemddir) # # Location of system config script directory? diff --git a/redhat/Makefile b/redhat/Makefile index b9ad209..d9b9101 100644 --- a/redhat/Makefile +++ b/redhat/Makefile @@ -2,7 +2,7 @@ -include ../Makefile.conf include ../Makefile.rules -all: autofs.init autofs.sysconfig +all: autofs.init autofs.sysconfig autofs.service autofs.init: autofs.init.in sed -e "s|@@sbindir@@|$(sbindir)|g" \ @@ -15,6 +15,12 @@ autofs.sysconfig: autofs.sysconfig.in sed -e "s|@@autofsmapdir@@|$(autofsmapdir)|g" \ < autofs.sysconfig.in > autofs.sysconfig +autofs.service: ../samples/autofs.service.in + sed -e "s|@@sbindir@@|$(sbindir)|g" \ + -e "s|@@autofsconfdir@@|$(autofsconfdir)|g" \ + -e "s|@@autofspiddir@@|$(autofspiddir)|g" \ + < ../samples/autofs.service.in > autofs.service + clean: - rm -f autofs.init autofs.sysconfig + rm -f autofs.init autofs.sysconfig autofs.service diff --git a/samples/Makefile b/samples/Makefile index 2a6e898..91c1d6b 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -4,7 +4,7 @@ include ../Makefile.rules SAMPLES = auto.master auto.misc auto.net auto.smb -all: rc.autofs autofs.conf.default +all: rc.autofs autofs.conf.default autofs.service rc.autofs: rc.autofs.in sed -e "s|@@sbindir@@|$(sbindir)|g" \ @@ -16,6 +16,12 @@ autofs.conf.default: autofs.conf.default.in sed -e "s|@@autofsmapdir@@|$(autofsmapdir)|g" \ < autofs.conf.default.in > autofs.conf.default +autofs.service: autofs.service.in + sed -e "s|@@sbindir@@|$(sbindir)|g" \ + -e "s|@@autofsconfdir@@|$(autofsconfdir)|g" \ + -e "s|@@autofspiddir@@|$(autofspiddir)|g" \ + < autofs.service.in > autofs.service + .PHONY: dirs dirs: install -d -m 755 $(INSTALLROOT)$(autofsmapdir) @@ -26,13 +32,18 @@ dirs: .PHONY: autofs.init autofs.init: @echo -ifneq ($(initdir),) +ifneq ($(systemddir),) + install -d -m 755 $(INSTALLROOT)$(systemddir) + install autofs.service -m 644 $(INSTALLROOT)$(systemddir)/autofs.service +else + ifneq ($(initdir),) install -d -m 755 $(INSTALLROOT)$(initdir) install rc.autofs -m 755 $(INSTALLROOT)$(initdir)/autofs -else + else if test -d $(INSTALLROOT)/etc/rc.d ; then \ install -c rc.autofs -m 755 $(INSTALLROOT)/etc/rc.d ; \ fi + endif endif CONFIG = $(shell test -e $(INSTALLROOT)$(autofsconfdir)/autofs.orig || echo "-b --suffix=.orig") @@ -173,10 +184,10 @@ auto.smb: fi ; \ fi -install: rc.autofs autofs.conf.default dirs autofs.init autofs.conf \ - autofs_ldap_auth.conf $(SAMPLES) +install: rc.autofs autofs.conf.default dirs autofs.init autofs.service \ + autofs.conf autofs_ldap_auth.conf $(SAMPLES) @echo clean: - rm -f *.o *.s rc.autofs autofs.conf.default + rm -f *.o *.s rc.autofs autofs.conf.default autofs.service diff --git a/samples/autofs.service.in b/samples/autofs.service.in new file mode 100644 index 0000000..3756078 --- /dev/null +++ b/samples/autofs.service.in @@ -0,0 +1,12 @@ +[Unit] +Description=Automounts filesystems on demand +After=network.target ypbind.service + +[Service] +Type=forking +PIDFile=@@autofspiddir@@/autofs.pid +EnvironmentFile=-@@autofsconfdir@@/autofs +ExecStart=@@sbindir@@/automount ${OPTIONS} --pid-file @@autofspiddir@@/autofs.pid + +[Install] +WantedBy=multi-user.target