add epel6 conditionals

This commit is contained in:
James Hogarth 2017-04-05 23:07:58 +01:00
parent 7fc6e678ea
commit a026e25dbb
2 changed files with 178 additions and 11 deletions

121
lldpd-el6.init Normal file
View File

@ -0,0 +1,121 @@
#!/bin/bash
# lldpd init file
#
# chkconfig: 2345 60 20
# description: 802.1ab (LLDP) daemon
#
# processname: lldpd
# pidfile: /var/run/lldpd.pid
### BEGIN INIT INFO
# Provides: lldpd
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $syslog $network $net-snmp
# Should-Stop: $syslog $network $net-snmp
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Short-Description: LLDP daemon
# Description: 802.1ab (LLDP) daemon
### END INIT INFO
# source function library
. /etc/rc.d/init.d/functions
LLDPD_OPTIONS=""
[ -e /etc/sysconfig/lldpd ] && . /etc/sysconfig/lldpd
RETVAL=0
prog="lldpd"
binary=/usr/sbin/lldpd
pidfile=/var/run/lldpd.pid
lockfile=/var/lock/subsys/$prog
# Determine if we can use the -p option to daemon, killproc, and status.
# RHEL < 5 can't.
if status | grep -q -- '-p' 2>/dev/null; then
daemonopts="--pidfile $pidfile"
pidopts="-p $pidfile"
fi
start() {
[ -x $binary ] || exit 5
echo -n $"Starting $prog: "
if [ $UID -ne 0 ]; then
RETVAL=1
failure
else
daemon $daemonopts $binary $LLDPD_OPTIONS
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $lockfile
fi;
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
if [ $UID -ne 0 ]; then
RETVAL=1
failure
else
killproc $pidopts $binary
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $lockfile
fi;
echo
return $RETVAL
}
restart(){
stop
start
}
condrestart(){
[ -e $lockfile ] && restart
return 0
}
rh_status_q(){
status $pidopts $prog >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
start
RETVAL=$?
;;
stop)
rh_status_q || exit 0
stop
RETVAL=$?
;;
restart)
restart
RETVAL=$?
;;
reload)
rh_status_q || exit 7
exit 3
;;
force-reload)
restart
RETVAL=$?
;;
condrestart|try-restart)
rh_status_q || exit 0
condrestart
RETVAL=$?
;;
status)
status $pidopts $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|force-reload}"
RETVAL=2
esac
exit $RETVAL

View File

@ -1,7 +1,10 @@
# there are tests but they don't run in mock
# as they require the ability to create and act
# inside a network namespace
%bcond_with tests
%if 0%{?el6}
%bcond_with systemd
%global rundir /var/run/
%else
%bcond_without systemd
%global rundir /run/
%endif
%global gh_owner vincentbernat
@ -16,16 +19,29 @@ Source0: https://media.luffy.cx/files/lldpd/lldpd-%{version}.tar.gz
Source1: %{name}-fedora.service
Source2: %{name}-tmpfiles
Source3: %{name}-fedora.sysconfig
Source4: %{name}-el6.init
BuildRequires: libevent-devel
BuildRequires: readline-devel
BuildRequires: check-devel
BuildRequires: net-snmp-devel
BuildRequires: libxml2-devel
# EL6 needs libevent2 as the package
%if 0%{?el6}
BuildRequires: libevent2-devel
%else
BuildRequires: libevent-devel
%endif
%if 0%{?with_systemd}
# For systemd stuff
BuildRequires: systemd
%{?systemd_requires}
%else
Requires(post): chkconfig
Requires(preun): chkconfig
# This is for /sbin/service
Requires(preun): initscripts
%endif
Requires(pre): shadow-utils
@ -48,10 +64,12 @@ Summary: %{summary}
%build
%configure --disable-static --with-snmp --disable-silent-rules \
--with-systemdsystemunitdir=%{_unitdir} --with-sysusersdir=no \
--with-privsep-user=%{name} --with-privsep-group=%{name} \
--with-privsep-chroot=/run/%{name}/chroot \
--with-lldpd-ctl-socket=/run/%{name}/%{name}.socket
--with-privsep-chroot=%{rundir}%{name}/chroot \
--with-lldpd-ctl-socket=%{rundir}%{name}/%{name}.socket \
%if 0%{?with_systemd}
--with-systemdsystemunitdir=%{_unitdir} --with-sysusersdir=no
%endif
make %{?_smp_mflags}
@ -59,10 +77,15 @@ make %{?_smp_mflags}
%install
%make_install
%if 0%{?with_systemd}
install -p -D -m644 %{SOURCE1} %{buildroot}%{_unitdir}/%{name}.service
install -p -D -m644 %{SOURCE2} %{buildroot}%{_tmpfilesdir}/%{name}.conf
%else
install -p -D -m755 %{SOURCE4} %{buildroot}%{_initddir}/%{name}
%endif
install -p -D -m644 %{SOURCE3} %{buildroot}/etc/sysconfig/%{name}
install -d -D -m 0755 %{buildroot}/run/%{name}/chroot
install -d -D -m 0755 %{buildroot}%{rundir}%{name}/chroot
install -d -m 0755 %{buildroot}%{_sharedstatedir}/%{name}
# remove the docs from buildroot
rm -rf %{buildroot}/usr/share/doc/%{name}
@ -84,14 +107,32 @@ exit 0
%post
/sbin/ldconfig
%if 0%{?with_systemd}
%systemd_post %{name}.service
%else
# This adds the proper /etc/rc*.d links for the script
/sbin/chkconfig --add %{name}
%endif
%preun
%if 0%{?with_systemd}
%systemd_preun %{name}.service
%else
if [ $1 -eq 0 ] ; then
/sbin/service %{name} stop >/dev/null 2>&1
/sbin/chkconfig --del %{name}
fi
%endif
%postun
/sbin/ldconfig
%if 0%{?with_systemd}
%systemd_postun_with_restart %{name}.service
%else
if [ "$1" -ge "1" ] ; then
/sbin/service %{name} condrestart >/dev/null 2>&1 || :
fi
%endif
%files
%doc NEWS README.md
@ -106,10 +147,14 @@ exit 0
%{_mandir}/man8/%{name}.8*
%{_libdir}/liblldpctl.so.4
%{_libdir}/liblldpctl.so.4.8.0
%dir /run/%{name}
%dir /run/%{name}/chroot
%dir %{rundir}%{name}
%dir %{rundir}%{name}/chroot
%if 0%{?with_systemd}
%{_unitdir}/%{name}.service
%{_tmpfilesdir}/%{name}.conf
%else
%{_initddir}/%{name}
%endif
%dir %attr(-,lldpd,lldpd) %{_sharedstatedir}/%{name}
%files devel
@ -122,6 +167,7 @@ exit 0
%changelog
* Wed Apr 05 2017 James Hogarth <james.hogarth@gmail.com> - 0.9.7-3
- Use the official release tarball rather than the github snapshot
- Add EPEL6 conditionals
* Wed Apr 05 2017 James Hogarth <james.hogarth@gmail.com> - 0.9.7-2
- Tweaks to spec requested in review