File icinga.spec of Package icinga

%define realname icinga2
%define srcext   tar.bz2

%define ICINGA_VAR   %{_localstatedir}/lib/icinga2

%define ICINGA_USER  icinga
%define ICINGA_GROUP icinga

# turn off the generation of debuginfo rpm  (RH9) ??
%global debug_package %{nil}

# Common info
Name:          %{realname}
Version:       2.0.0
Release:       wiz%{?extraver:0.}1
License:       GPL-2.0
Group:         System/Monitoring
URL:           http://www.icinga.org/
Summary:       Enterprise grade open source monitoring system

# Install-time parameters
Requires:      logrotate
Requires:      %{realname}-db
%if 0%{?suse_version}
Requires:      http_daemon
PreReq:        permissions
%else
Requires:      webserver
%endif

# Build-time parameters
BuildRequires: gcc-c++ bison flex cmake >= 2.6 pkgconfig
BuildRequires: python%{?suse_version:-base} python-setuptools
BuildRequires: boost-devel >= 1.41.0 openssl-devel
BuildRequires: mysql-devel postgresql-devel
BuildRoot:     %{_tmppath}/%{name}-root
Source:        %{realname}-%{version}%{?extraver}.%{srcext}
Source11:      icinga2.sysconfig

%description
Icinga is a fork of Nagios and is backward compatible. So, Nagios configurations,
plugins and addons can all be used with Icinga. Though Icinga retains all
the existing features of its predecessor, it builds on them to add many long
awaited patches and features requested by the user community.

Icinga is an enterprise grade open source monitoring system which keeps watch
over a network and any conceivable network resource, notifies the user of errors
and recoveries, and generates performance data for reporting. Scalable and
extensible, Icinga can monitor complex, large environments across dispersed
locations. Icinga is licensed under GPL V2 and is free to use,
distribute and modify.

%package mysql
Group:         System/Monitoring
Summary:       MySQL backend database support for %{realname}
Provides:      %{realname}-db

%description mysql
MySQL backend database support for %{realname}

%package postgresql
Group:         System/Monitoring
Summary:       PostgreSQL backend database support for %{realname}
Provides:      %{realname}-db

%description postgresql
PostgreSQL backend database support for %{realname}

%package python
Group:         Development/Languages/Python
Summary:       Python bindings for %{realname}
Requires:      python%{?suse_version:-base}

%description python
Python bindings for %{realname}

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{version}%{?extraver}

%build
cmake \
 -DCMAKE_INSTALL_PREFIX=%{_prefix} \
 -DCMAKE_INSTALL_SYSCONFDIR=%{_sysconfdir} \
 -DCMAKE_INSTALL_LOCALSTATEDIR=%{_localstatedir} \
 -DCMAKE_BUILD_TYPE=Release \
 -DCMAKE_C_FLAGS_RELEASE="%{optflags}" \
 -DCMAKE_CXX_FLAGS_RELEASE="%{optflags}" \
 -DCMAKE_EXE_LINKER_FLAGS_RELEASE="-Wl,--as-needed -Wl,--strip-all" \
 -DCMAKE_MODULE_LINKER_FLAGS_RELEASE="-Wl,--as-needed -Wl,--strip-all" \
 -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="-Wl,--as-needed -Wl,--strip-all" \
%if 0%{?_unitdir:1}
 -DUSE_SYSTEMD=ON \
 -DINSTALL_SYSTEMD_SERVICE_AND_INITSCRIPT=ON \
%endif
 -DICINGA2_USER=%{ICINGA_USER} \
 -DICINGA2_GROUP=%{ICINGA_GROUP} \
 -DICINGA2_COMMAND_USER=%{ICINGA_USER} \
 -DICINGA2_COMMAND_GROUP=%{ICINGA_GROUP}
%{__make} %{?_smp_mflags} all

%install
%{__make} DESTDIR=%{buildroot} \
 install \
 INSTALL_OPTS="" \
 INSTALL_OPTS_WEB="" \
 INIT_OPTS="" \
 COMMAND_OPTS=""
%if %{expand:%_vendor == "suse"}
[ -f %{buildroot}%{_sysconfdir}/init.d/icinga2 ] && %{__ln_s} %{_sysconfdir}/init.d/icinga2 %{buildroot}%{_sbindir}/rcicinga2
%{__rm} -f %{buildroot}%{_sysconfdir}/sysconfig/icinga2
%{__install} -d -m755 %{buildroot}/var/adm/fillup-templates
%{__sed} \
 -e 's|##sbindir##|%{_sbindir}|' \
 -e 's|##sysconfdir##|%{_sysconfdir}|' \
 -e 's|##icinga_user##|%{ICINGA_USER}|' \
 -e 's|##icinga_group##|%{ICINGA_GROUP}|' \
 -e 's|##localstatedir##|%{_localstatedir}|' \
 %{S:11} > %{buildroot}/var/adm/fillup-templates/sysconfig.icinga2

%endif
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}%{_datadir}/doc/icinga2

%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

%files
%defattr(-,root,root)
%doc AUTHORS COPYING COPYING.Exceptions ChangeLog LICENSE.txt README.md
%dir %{_sysconfdir}/icinga2/conf.d/hosts/localhost
%dir %{_sysconfdir}/icinga2/conf.d/hosts
%dir %{_sysconfdir}/icinga2/conf.d
%dir %{_sysconfdir}/icinga2/features-available
%dir %{_sysconfdir}/icinga2/features-enabled
%dir %{_sysconfdir}/icinga2/pki
%dir %{_sysconfdir}/icinga2/scripts
%dir %{_sysconfdir}/icinga2/zones.d
%dir %{_sysconfdir}/icinga2
%config(noreplace) %{_sysconfdir}/icinga2/conf.d/hosts/localhost/*.conf
%config(noreplace) %{_sysconfdir}/icinga2/conf.d/hosts/localhost.conf
%config(noreplace) %{_sysconfdir}/icinga2/conf.d/*.conf
%config(noreplace) %{_sysconfdir}/icinga2/features-available/*.conf
%config(noreplace) %{_sysconfdir}/icinga2/features-enabled/*.conf
%config(noreplace) %{_sysconfdir}/icinga2/scripts/*.sh
%config(noreplace) %{_sysconfdir}/icinga2/constants.conf
%config(noreplace) %{_sysconfdir}/icinga2/icinga2.conf
%config(noreplace) %{_sysconfdir}/icinga2/zones.conf
%{_sysconfdir}/icinga2/zones.d/README
%if %{expand:%_vendor == "suse"}
/var/adm/fillup-templates/sysconfig.icinga2
%else
%config(noreplace) %{_sysconfdir}/sysconfig/icinga2
%endif
%{_sysconfdir}/init.d/icinga2
%if 0%{?_unitdir:1}
%{_unitdir}/icinga2.service
%endif
%config(noreplace) %{_sysconfdir}/logrotate.d/icinga2
%{_bindir}/*
%{_sbindir}/*
%dir %{_libdir}/icinga2
%{_libdir}/icinga2/*.so
%dir %{_datadir}/icinga2/include
%dir %{_datadir}/icinga2/pki
%dir %{_datadir}/icinga2
%{_datadir}/icinga2/include/*
%{_datadir}/icinga2/pki/*
%doc %{_mandir}/man8/*
%dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/cache/icinga2
%dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/lib/icinga2/api/log
%dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/lib/icinga2/api/repository
%dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/lib/icinga2/api/zones
%dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/lib/icinga2/api
%dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/lib/icinga2
%dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/log/icinga2/compat/archives
%dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/log/icinga2/compat
%dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/log/icinga2
%dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/spool/icinga2/perfdata
%dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/spool/icinga2/tmp
%dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/spool/icinga2
%ghost %dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/run/icinga2/cmd
%ghost %dir %attr(0775,%{ICINGA_USER},%{ICINGA_GROUP}) %{_localstatedir}/run/icinga2
%exclude %{_libdir}/icinga2/libdb_ido_mysql.so
%exclude %{_libdir}/icinga2/libdb_ido_pgsql.so

%files mysql
%defattr(-,root,root)
%{_libdir}/icinga2/libdb_ido_mysql.so
%dir %{_datadir}/icinga2-ido-mysql/schema/upgrade
%dir %{_datadir}/icinga2-ido-mysql/schema
%dir %{_datadir}/icinga2-ido-mysql
%{_datadir}/icinga2-ido-mysql/schema/upgrade/*.sql
%{_datadir}/icinga2-ido-mysql/schema/mysql.sql

%files postgresql
%defattr(-,root,root)
%{_libdir}/icinga2/libdb_ido_pgsql.so
%dir %{_datadir}/icinga2-ido-pgsql/schema/upgrade
%dir %{_datadir}/icinga2-ido-pgsql/schema
%dir %{_datadir}/icinga2-ido-pgsql
%{_datadir}/icinga2-ido-pgsql/schema/upgrade/*.sql
%{_datadir}/icinga2-ido-pgsql/schema/pgsql.sql

%files python
%defattr(-,root,root)
%{python_sitelib}/icinga2
%exclude %{python_sitelib}/icinga2-%{version}-py%{python_version}.egg-info

%pre
/usr/sbin/groupadd -r %{ICINGA_GROUP} &>/dev/null ||:
/usr/sbin/useradd  -g %{ICINGA_GROUP} -s /bin/false -r -c "Icinga user" -d %{ICINGA_VAR} %{ICINGA_USER} &>/dev/null ||:

%if 0%{?suse_version}

%post
%if 0%{!?_unitdir:1}
%{fillup_and_insserv %{realname}}
%else
%{fillup_only %{realname}}
%endif

%if 0%{!?_unitdir:1}
%preun
%{stop_on_removal %{realname}}
%endif

%postun
%if 0%{!?_unitdir:1}
%{restart_on_update %{realname}}
%endif
%{insserv_cleanup}
[ -d %{_localstatedir}/run/icinga2 ] && %{__rm} -rf %{_localstatedir}/run/icinga2

%endif

%changelog