File keepalived.spec of Package keepalived

#
# spec file for package keepalived
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%if 0%{?suse_version} > 1210
%bcond_without systemd
%else
%bcond_with    systemd
%endif
%bcond_with dbus

Name:           keepalived
Version:        1.3.3
Release:        0
Summary:        A strong & robust keepalive facility for linux
License:        GPL-2.0+
Group:          Productivity/Networking/Routing
Url:            http://www.keepalived.org/
# TODO: revert to old source line with 1.3.4 update
# Source:         http://www.keepalived.org/software/keepalived-%{version}.tar.gz
Source:         https://github.com/acassen/keepalived/files/779998/keepalived-1.3.3.tar.gz
Source1:        keepalived.service
Source2:        keepalive-rpmlintrc
Patch1:         keepalive-init.patch
BuildRequires:  libnfnetlink-devel
BuildRequires:  net-snmp-devel
BuildRequires:  openssl-devel
BuildRequires:  pkgconfig
BuildRequires:  snmp-mibs
%if 0%{?suse_version} > 1110
BuildRequires:  pkgconfig(dbus-1)
BuildRequires:  pkgconfig(gio-2.0)
BuildRequires:  pkgconfig(libipset)
BuildRequires:  pkgconfig(libiptc)
BuildRequires:  pkgconfig(libnl-3.0)
BuildRequires:  pkgconfig(xtables)
%else
BuildRequires:  dbus-1-devel
BuildRequires:  glib2-devel
BuildRequires:  ipset-devel
BuildRequires:  libiptc-devel
BuildRequires:  libnl-devel
BuildRequires:  libxtables-devel
%endif
BuildRequires:  libnfnetlink-devel
BuildRequires:  net-snmp-devel
BuildRequires:  popt-devel
%if 0%{?suse_version} && 0%{?suse_version} <= 1110
BuildRequires:  cyrus-sasl-devel
%endif
Requires(pre):  pwdutils
Requires(pre):  %insserv_prereq
Requires(pre):  %fillup_prereq
%if %{with systemd}
BuildRequires:  systemd
Requires:       systemd
%endif

BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
The main goal of this project is to provide simple and robust facilities for
loadbalancing and high-availability to Linux system and Linux based
infrastructures. Loadbalancing framework relies on well-known and widely used
Linux Virtual Server (IPVS) kernel module providing Layer4 loadbalancing.
Keepalived implements a set of checkers to dynamically and adaptively maintain
and manage loadbalanced server pool according their health. On the other hand
high-availability is achieved by VRRP protocol. VRRP is a fundamental brick for
router failover. In addition, Keepalived implements a set of hooks to the VRRP
finite state machine providing low-level and high-speed protocol interactions.
Keepalived frameworks can be used independently or all together to provide
resilient infrastructures.

%prep
%setup -q
%patch1 -p0

%build
export STRIP=true
export CPPFLAGS="$(pkg-config --cflags libnfnetlink libiptc libipset xtables)"
export CFLAGS="%optflags -DOPENSSL_NO_SSL_INTERN"
%configure \
  --disable-silent-rules \
  --enable-snmp \
  --enable-snmp-vrrp \
  %if %{with dbus}
  --enable-dbus \
  --enable-dbus-create-instance \
  %endif
  --enable-snmp-checker \
  --enable-snmp-rfc \
  --enable-snmp-rfcv2 \
  --enable-snmp-rfcv3 \
  --enable-sha1 \
  --enable-routes \
  --enable-libiptc \
  --enable-libipset
make %{?_smp_mflags}

%install
make install DESTDIR="%{buildroot}"
install -dD -m 0750 %{buildroot}%{_var}/lib/%{name}
install -D  -m 0644 %{buildroot}/etc/sysconfig/keepalived %{buildroot}/var/adm/fillup-templates/sysconfig.%{name}

%if %{with systemd}
install -D -m0644 %{SOURCE1} %{buildroot}%{_unitdir}/%{name}.service
ln -s /sbin/service %{buildroot}%{_sbindir}/rckeepalived
%else
install -D -m 0750 keepalived/etc/init.d/keepalived.suse.init %{buildroot}/etc/init.d/keepalived
ln -s /etc/init.d/keepalived %{buildroot}%{_sbindir}/rckeepalived
%endif

chmod -R o= %{buildroot}/etc/keepalived
rm -rv %{buildroot}/etc/keepalived/samples/ %{buildroot}/etc/sysconfig/keepalived

%pre
/usr/sbin/groupadd -r %{name} >/dev/null 2>&1 || :
/usr/sbin/useradd -g %{name} -s /bin/false -r -c "Keepalived" -d %{_var}/lib/%{name} %{name} >/dev/null 2>&1 || :
%if %{with systemd}
%service_add_pre %{name}.service %{name}.socket
%endif

%preun
%stop_on_removal %{name}
%if %{with systemd}
%service_del_preun %{name}.service %{name}.socket
%endif

%post
%fillup_only %{name}
%if %{with systemd}
%service_add_post %{name}.service %{name}.socket
%endif

%postun
%insserv_cleanup
%restart_on_update %{name}
%if %{with systemd}
%service_del_postun %{name}.service %{name}.socket
%endif

%files
%defattr(-,root,root)
%doc README COPYING ChangeLog
%config(noreplace) %attr(-,root,keepalived) /etc/keepalived/
%{_bindir}/genhash
%{_sbindir}/rckeepalived
%{_sbindir}/keepalived
%{_mandir}/man1/genhash.1.gz
%{_mandir}/man5/keepalived.conf.5.gz
%{_mandir}/man8/keepalived.8.gz
%{_datadir}/snmp/mibs/KEEPALIVED-MIB.txt
%{_datadir}/snmp/mibs/VRRP-MIB.txt
%{_datadir}/snmp/mibs/VRRPv3-MIB.txt
#
%if %{with dbus}
%config /etc/dbus-1/system.d/org.keepalived.Vrrp1.conf
%{_datadir}/dbus-1/interfaces/org.keepalived.Vrrp1.Instance.xml
%{_datadir}/dbus-1/interfaces/org.keepalived.Vrrp1.Vrrp.xml
%endif
#
%if %{with systemd}
%{_unitdir}/%name.service
%else
/etc/init.d/keepalived
%endif
%dir %attr(-,keepalived,keepalived) %{_var}/lib/%{name}
/var/adm/fillup-templates/sysconfig.%{name}
%doc AUTHOR ChangeLog CONTRIBUTORS COPYING README
%doc doc/samples/
%doc doc/keepalived.conf.SYNOPSIS doc/NOTE_vrrp_vmac.txt

%changelog