File monit.spec of Package monit

#
# spec file for package monit
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#               Pascal Bleser <pascal.bleser@opensuse.org>
#
# 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/
#


#Compat macro for new _fillupdir macro introduced in Nov 2017
%if ! %{defined _fillupdir}
  %define _fillupdir /var/adm/fillup-templates
%endif

Name:           monit
Version:        5.26.0
Release:        0
Summary:        Service Manager and Monitor System
License:        AGPL-3.0
Group:          System/Monitoring
Url:            https://m%{name}.com/%{name}/#download
Source0:        https://m%{name}.com/%{name}/dist/%{name}-%{version}.tar.gz
Source1:        https://m%{name}.com/%{name}/dist/%{name}-%{version}.tar.gz.sha256
Source2:        %{name}-rpmlintrc
Source3:        %{name}.service
Source100:      %{name}-vendor-files.tar.gz
Patch1:         %{name}-better_default_monitrc.patch
Patch2:         %{name}-rundir.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
#
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  bison
BuildRequires:  flex
BuildRequires:  gcc
BuildRequires:  glibc-devel
BuildRequires:  libtool
BuildRequires:  make
BuildRequires:  openssl-devel
BuildRequires:  pam-devel
BuildRequires:  zlib-devel

%if 0%{?suse_version} >= 1210
BuildRequires:  systemd
%{?systemd_requires}
%define has_systemd 1
%define _monit_run_dir  /run/%{name}
%else
Requires(pre):  %insserv_prereq
%define _monit_run_dir  %{_localstatedir}/run/%{name}
%endif

Obsoletes:      %{name}-beta < %{version}
Provides:       %{name}-beta = %{version}

%if "%{_vendor}" == "suse"
%define VENDOR SUSE
%else
%define VENDOR %_vendor
%endif


%description
Monit is a utility for managing and monitoring processes, files,
directories, and devices on a Unix system.  Monit conducts automatic
maintenance and repair and can execute meaningful causal actions in
error situations.  For example, monit can start a process if it does
not run, restart a process if it does not respond, and stop a process
if it uses too many resources.	You can use monit to monitor files,
directories, and devices for changes, such as time stamp changes,
checksum changes, or size changes. You can even use monit to monitor
remote hosts: monit can ping a remote host and check port connections.

%package doc
Summary:        Service Manager and Monitor System (Documentation and Examples)
Group:          System/Monitoring
%if 0%{?suse_version} > 1110
BuildArch:      noarch
%endif

%description doc
Monit is a utility for managing and monitoring processes, files,
directories, and devices on a Unix system.  Monit conducts automatic
maintenance and repair and can execute meaningful causal actions in
error situations.  For example, monit can start a process if it does
not run, restart a process if it does not respond, and stop a process
if it uses too many resources.	You can use monit to monitor files,
directories, and devices for changes, such as time stamp changes,
checksum changes, or size changes. You can even use monit to monitor
remote hosts: monit can ping a remote host and check port connections.

This package only contains the documentation and examples.
You must also install the package %{name} to actually use monit.

%package -n monit-bash-completion
Summary:        Bash completion for monit
License:        AGPL-3.0
Group:          System/Monitoring
BuildRequires:  bash-completion
Requires:       bash-completion
Requires:       monit
Supplements:    packageand(%{name}:bash-completion)

%description -n monit-bash-completion
This package contains the bash completion command for monit.


%prep
%setup -q -a100
%patch1
%patch2

find doc/ -type f -size 0 -exec %__rm {} \;

%build
export CFLAGS="%{optflags} -fno-strict-aliasing"
%configure \
	--with-ssl-lib-dir="%{_libdir}"

%__make %{?_smp_flags}

%install
%__make DESTDIR="%{buildroot}" install

%__install -d \
	"%{buildroot}/etc/init.d" \
	"%{buildroot}%{_sysconfdir}/%{name}.d" \
	"%{buildroot}%{_sbindir}" \
	"%{buildroot}%{_datadir}/%{name}" \
	"%{buildroot}%{_fillupdir}" \
	"%{buildroot}%{_monit_run_dir}" \
	"%{buildroot}%{_monit_run_dir}/events" \
	"%{buildroot}%{_localstatedir}/lib/%{name}"

. vendor-files/sysconfig/%{name}.tmpl
MONIT_BIN="%{_bindir}/%{name}"
MONIT_MODIFY_INITTAB="%{_datadir}/%{name}/%{name}-modifyinittab"
MONIT_PID_FILE="%{_monit_run_dir}/%{name}.pid"
MONIT_SYSCONFIG_FILE="/etc/sysconfig/%{name}"
MONIT_INITTAB_STATE_FILE="%{_localstatedir}/lib/%{name}/%{name}-inittab.state"
MONIT_ARGS="-p ${MONIT_PID_FILE} -s %{_monit_run_dir}/%{name}.state"
MONIT_EVENTQUE_DIR="%{_localstatedir}/lib/%{name}"
%__sed -e "s|%{_monit_run_dir}|${MONIT_EVENTQUE_DIR}|g" \
	< %{name}rc > "%{buildroot}%{_sysconfdir}/%{name}rc"

pushd vendor-files
for templatefile in docu/README tools/%{name}-modifyinittab init/%{name} sysconfig/%{name}; do
	%__sed \
		-e "s|__MONIT_RC_FILE__|${MONIT_RC_FILE}|g" \
		-e "s|__MONIT_INITTAB_BASE__|${MONIT_INITTAB_BASE}|g" \
		-e "s|__MONIT_INITTAB_COMMENT__|${MONIT_INITTAB_COMMENT}|g" \
		-e "s|__MONIT_INITTAB_STATE_FILE__|${MONIT_INITTAB_STATE_FILE}|g" \
		-e "s|__MONIT_ARGS__|${MONIT_ARGS}|g" \
		-e "s|__MONIT_BIN__|${MONIT_BIN}|g" \
		-e "s|__MONIT_MODIFY_INITTAB__|${MONIT_MODIFY_INITTAB}|g" \
		-e "s|__MONIT_PID_FILE__|${MONIT_PID_FILE}|g" \
		-e "s|__MONIT_SYSCONFIG_FILE__|${MONIT_SYSCONFIG_FILE}|g" \
		< "${templatefile}.tmpl" \
		> "${templatefile}"
done
popd # vendor-files

# systemd vs SysVinit
%if 0%{?has_systemd}
install -D -m 0644 %{S:3} %{buildroot}%{_unitdir}/%{name}.service
ln -sf %{_sbindir}/service %{buildroot}/%{_sbindir}/rc%{name}
%else #SysVinit
%__install -m0754 vendor-files/init/%{name} "%{buildroot}%{_sysconfdir}/init.d/%{name}"
%__ln_s %{_sysconfdir}/init.d/%{name} %{buildroot}%{_sbindir}/rc%{name}
%endif
%__install -m0644 vendor-files/sysconfig/%{name} "%{buildroot}%{_fillupdir}/sysconfig.%{name}"

%__install -m0754 vendor-files/tools/%{name}-modifyinittab "%{buildroot}%{_datadir}/%{name}"

touch "%{buildroot}%{_localstatedir}/lib/%{name}/%{name}-inittab.state"
%if 0%{?suse_version} == 0 || 0%{?suse_version} > 1110
touch "%{buildroot}%{_monit_run_dir}/.%{name}.id"
touch "%{buildroot}%{_monit_run_dir}"/%{name}.pid
touch "%{buildroot}%{_monit_run_dir}"/%{name}.state
%endif
%__install -m0644 vendor-files/docu/README README.SUSE

%__install -d "%{buildroot}%{_docdir}/%{name}"
>doc.main.lst
for f in COPYING; do
    %__install -m0644 "$f" "%{buildroot}%{_docdir}/%{name}/$f"
    echo "%doc %{_docdir}/%{name}/$f" >>doc.main.lst
done
>doc.doc.lst
for f in README* doc; do
    %__cp -a "$f" "%{buildroot}%{_docdir}/%{name}/"
    echo "%doc %{_docdir}/%{name}/$(basename $f)" >>doc.doc.lst
done

install -Dm 0644 system/bash/monit %{buildroot}%{_datadir}/bash-completion/completions/monit

%pre
%if 0%{?has_systemd}
%service_add_pre %{name}.service
%endif

%preun
%if 0%{?has_systemd}
%service_del_preun %{name}.service
%else
%stop_on_removal %{name}
%endif

%post
%if 0%{?has_systemd}
%service_add_post %{name}.service
%{fillup_and_insserv -i}
%else
%{fillup_and_insserv}
%__install -d -m0700 -o root -g root %{_localstatedir}/run/%{name}
%__install -d -m0700 -o root -g root %{_localstatedir}/run/%{name}/events
%endif

%postun
%if 0%{?has_systemd}
%service_del_postun %{name}.service
%else
%restart_on_update %{name}
%{insserv_cleanup}
%endif

%files -f doc.main.lst
%defattr(-,root,root)
%doc %{_mandir}/man1/%{name}.1%{ext_man}
%doc %dir %{_docdir}/%{name}
%attr(0600,root,root) %config(noreplace) %{_sysconfdir}/%{name}rc
%dir %{_sysconfdir}/%{name}.d
%if 0%{?has_systemd}
%{_unitdir}/%{name}.service
%else
%attr(0754,root,root) %config %{_sysconfdir}/init.d/%{name}
%endif
%{_sbindir}/rc%{name}
%{_bindir}/%{name}
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/%{name}-modifyinittab
%{_fillupdir}/sysconfig.%{name}
%dir %{_localstatedir}/lib/%{name}
%ghost %{_localstatedir}/lib/%{name}/%{name}-inittab.state
%if 0%{?suse_version} == 0 || 0%{?suse_version} > 1110
%ghost %dir %{_monit_run_dir}
%ghost %{_monit_run_dir}/%{name}.pid
%ghost %{_monit_run_dir}/%{name}.state
%ghost %{_monit_run_dir}/.%{name}.id
%ghost %dir %{_monit_run_dir}/events
%endif

%files doc -f doc.doc.lst
%defattr(-,root,root)
%doc %dir %{_docdir}/%{name}

%files -n monit-bash-completion
%{_datadir}/bash-completion/completions/monit

%changelog