spec files broken: core, plugins and nrpe incompat packages
Posted: Wed Oct 23, 2013 3:00 pm
I'm preparing for the upgrade to Nagios v4 on a Red Hat 5 compatible server. I am building RPM packages out of the tarballs for nagios-core, nagios-plugins, and nrpe. It's pretty messy. Out the box, the packages are incompatible with each other. For most, the build process exits with errors. Nagios Core has 644 permissions on the plugins directory. The list goes on and on. One or two problems are specific to RH5, but many would affect most if not all 64 bit distros, some errors allow build to happen, but the packages won't work once installed - anywhere.
I think the spec files have fallen into neglect, and some kind of spring cleaning is necessary. I am not the one to do it, I don't have enough time. I've merely fixed the specs while keeping them close to the original version, which is probably not ideal. The spec files should be overhauled closer to the RPM guidelines.
First off, take a look at the attached files. These are the fixed specs. Just remove the .txt extension, put the tarball in the SOURCES directory in your RPM build area, and do a "rpmbuild -ba specfilename.spec" and it will build the packages for you.
Now let's discuss each spec file. I'll do a diff -u on each spec file and discuss the output.
Nagios Core 4.0.0
Firstly, compilation during the package build fails outright on RH5 with the default gcc-4.1.2 compiler. You need to install the gcc44 package (yum install gcc44), then do "export CC=gcc44", then try again "rpmbuild -ba nagios.spec". I've chosen to use gcc44 for all Nagios-related packages, not only for Core, just to keep things consistent, even though the other packages may build without it.
The issue has been filed here:
http://tracker.nagios.org/view.php?id=488
Let's discuss the diff:
When unpacking most tarballs, the content will end up in a directory named %{name}-%{version}. The Nagios tarball unpacks into just %{name}. You have to explicitly indicate that, otherwise it will fail. This spec could never have worked with the original tarball. It was probably not tested before release.
Bug report filed here:
http://tracker.nagios.org/view.php?id=487
The spec file inconsistently uses either find, or the hardcoded path /bin/find. The problem is, there is no /bin/find on RH5. This would never work. Since plain find is used somewhere else in the spec, I've removed all the hardcoded paths.
Bug report filed here:
http://tracker.nagios.org/view.php?id=489
644 permissions on the plugins directory. This has caused me a lot of grief, since the error is subtle and hard to troubleshoot. Basically, no plugin works unless you're root. This would never work in real life, when Nagios is run as a non-root user.
Nagios Plugins 1.5
You need to build this package as root, even though this is contrary to standard practice, otherwise some plugins would not install correctly.
Here's the diff:
%{_libexecdir} and %{_sysconfdir} are RPM macros. Never over-write them! There's no reason to do that. You could simply pick a different name for whatever macro you want to use. If you overwrite the default macros, the side-effects could be hard to predict. I've renamed these to the custom macros %{_libexecnagios} and %{_sysconfnagios} and you'll see them renamed again many times below.
Also, while the Core package correctly uses the %{_libdir} macro to choose the location for the plugins directory, which ends up in /usr/lib64/nagios/plugins on a 64 bit system (and /usr/lib/nagios/plugins on a 32 bit system), the Plugins spec hardcodes that path to */lib/nagios/plugins no matter what. Nothing will work if you build the Core and the Plugins packages from tarballs on 64 bit Linux, because the plugin locations will be different. The packages will be incompatible.
I've changed the definition of the plugins directory to match the Core tarball, and be consistent with the architecture of the OS where you're building it.
Again, an RPM default macro is being over-written. Don't do that.
This is just a continuation of removing the over-write of the default macros.
A typo. I don't think the RPM would even build with this error. That macro must be unknown. Has this never been tested?
Again, restoring the default macros and using the alternative macro names. These are pretty big changes, I am not 100% sure these are correct, as I'm not very familiar with the software, but the package works well for me.
I think command.cfg was not even built, IIRC.
check_ldaps is installed, but it's not taken into the RPM for some reason, and the final stage of package building breaks. I don't have time to investigate why. Just add it here and it works. This is not a clean fix, sorry.
NRPE 2.15
This one also has to be built as root, otherwise changing the ownership on check_nrpe fails.
Here's the diff:
Lots and lots of over-riding default macros, hardcoding paths, etc. I'm not even sure I've fixed everything.
And again, the same issue with the compatibility with Core w.r.t. the location of the plugins directory. This package, again, was incorrectly hardcoding it to */lib/nagios/plugins, unlike Core. Fixed that to make these packages play nicely together.
Continuing down the path of reverting default macro over-rides.
And again.
And again.
Not sure why the init script was not being copied to /etc/init.d. It's needed there for the NRPE service. I've enabled the copy. Same for the .cfg file.
And again.
I think the spec files have fallen into neglect, and some kind of spring cleaning is necessary. I am not the one to do it, I don't have enough time. I've merely fixed the specs while keeping them close to the original version, which is probably not ideal. The spec files should be overhauled closer to the RPM guidelines.
First off, take a look at the attached files. These are the fixed specs. Just remove the .txt extension, put the tarball in the SOURCES directory in your RPM build area, and do a "rpmbuild -ba specfilename.spec" and it will build the packages for you.
Now let's discuss each spec file. I'll do a diff -u on each spec file and discuss the output.
Nagios Core 4.0.0
Firstly, compilation during the package build fails outright on RH5 with the default gcc-4.1.2 compiler. You need to install the gcc44 package (yum install gcc44), then do "export CC=gcc44", then try again "rpmbuild -ba nagios.spec". I've chosen to use gcc44 for all Nagios-related packages, not only for Core, just to keep things consistent, even though the other packages may build without it.
The issue has been filed here:
http://tracker.nagios.org/view.php?id=488
Let's discuss the diff:
Code: Select all
[root@oracle5 specs]# diff -u orig/nagios.spec fixed/nagios.spec
--- orig/nagios.spec 2013-09-20 12:01:20.000000000 -0700
+++ fixed/nagios.spec 2013-10-23 11:37:20.000000000 -0700
@@ -65,7 +65,7 @@
This package contains all the files from the contrib directory
%prep
-%setup
+%setup -n %{name}
# /usr/local/nagios is hardcoded in many places
%{__perl} -pi.orig -e 's|/usr/local/nagios/var/rw|%{_localstatedir}/nagios/rw|g;' contrib/eventhandlers/submit_check_resultBug report filed here:
http://tracker.nagios.org/view.php?id=487
Code: Select all
@@ -153,10 +153,10 @@
%{__cp} -afpv contrib/eventhandlers/* %{buildroot}%{_libdir}/nagios/plugins/eventhandlers/
%{__mv} contrib/README contrib/README.contrib
-CGI=`/bin/find contrib/ -name '*.cgi' -type f |sed s/'contrib\/'//g`
+CGI=`find contrib/ -name '*.cgi' -type f |sed s/'contrib\/'//g`
CGI=`for i in $CGI; do echo -n "$i|"; done |sed s/\|$//`
-/bin/find %{buildroot}/%{_libdir}/nagios/cgi -type f -print | sed s!'%{buildroot}'!!g | egrep -ve "($CGI)" > cgi.files
-/bin/find %{buildroot}/%{_libdir}/nagios/cgi -type f -print | sed s!'%{buildroot}'!!g | egrep "($CGI)" > contrib.files
+find %{buildroot}/%{_libdir}/nagios/cgi -type f -print | sed s!'%{buildroot}'!!g | egrep -ve "($CGI)" > cgi.files
+find %{buildroot}/%{_libdir}/nagios/cgi -type f -print | sed s!'%{buildroot}'!!g | egrep "($CGI)" > contrib.filesBug report filed here:
http://tracker.nagios.org/view.php?id=489
Code: Select all
@@ -206,7 +206,7 @@
%attr(0755,root,root) %config %{_initrddir}/nagios
%attr(0755,root,root) %{_bindir}/nagios
%attr(0755,root,root) %{_bindir}/nagiostats
-%attr(0644,root,root) %{_libdir}/nagios/plugins/
+%attr(0755,root,root) %{_libdir}/nagios/plugins/
%attr(0755,root,root) %{_datadir}/nagios/
%attr(0755,nagios,nagios) %dir %{_sysconfdir}/nagios/
%attr(0644,nagios,nagios) %config(noreplace) %{_sysconfdir}/nagios/*.cfgNagios Plugins 1.5
You need to build this package as root, even though this is contrary to standard practice, otherwise some plugins would not install correctly.
Here's the diff:
Code: Select all
[root@oracle5 specs]# diff -u orig/nagios-plugins.spec fixed/nagios-plugins.spec
--- orig/nagios-plugins.spec 2013-10-02 08:26:48.000000000 -0700
+++ fixed/nagios-plugins.spec 2013-10-23 11:37:27.000000000 -0700
@@ -7,12 +7,12 @@
%define _prefix /opt/nagios
# %define _defaultdocdir %{_datadir}/doc
%else
- %define _libexecdir %{_exec_prefix}/lib/nagios/plugins
+ %define _libexecnagios "%{_libdir}/nagios/plugins"
%endif
-%define _sysconfdir /etc/nagios
+%define _sysconfnagios "%{_sysconfdir}/nagios"
%define npusr nagios
-%define nphome /opt/nagios
+%define nphome %{_localstatedir}/log/nagios
%define npgrp nagios
Name: nagios-pluginsAlso, while the Core package correctly uses the %{_libdir} macro to choose the location for the plugins directory, which ends up in /usr/lib64/nagios/plugins on a 64 bit system (and /usr/lib/nagios/plugins on a 32 bit system), the Plugins spec hardcodes that path to */lib/nagios/plugins no matter what. Nothing will work if you build the Core and the Plugins packages from tarballs on 64 bit Linux, because the plugin locations will be different. The packages will be incompatible.
I've changed the definition of the plugins directory to match the Core tarball, and be consistent with the architecture of the OS where you're building it.
Code: Select all
@@ -30,8 +30,8 @@
%if %{isaix}
Prefix: %{_prefix}
-%else
-Prefix: %{_prefix}/lib/nagios/plugins
+#%else
+#Prefix: %{_prefix}/lib/nagios/plugins
%endif
Packager: Karl DeBisschop <[email protected]>
Vendor: Nagios Plugin Development GroupCode: Select all
@@ -117,8 +117,8 @@
%{?isaix: MAKE=gmake} ./configure \
--prefix=%{_prefix} \
--exec-prefix=%{_exec_prefix} \
---libexecdir=%{_libexecdir} \
---sysconfdir=%{_sysconfdir} \
+--libexecdir="%{_libdir}/nagios/plugins" \
+--sysconfdir=%{_sysconfnagios} \
--datadir=%{_datadir} \
--with-cgiurl=/nagios/cgi-bin
ls -1 %{npdir}/plugins > %{npdir}/ls-plugins-beforeCode: Select all
@@ -155,7 +155,7 @@
%if %{islinux}
getent passwd %{npusr} > /dev/null 2> /dev/null
if [ $? -ne 0 ] ; then
- useradd -r -d %{nshome} -c "%{npusr}" -g %{npgrp} %{npusr} || \
+ useradd -r -d %{nphome} -c "%{npusr}" -g %{npgrp} %{npusr} || \
%nnmmsg Unexpected error adding user "%{npusr}". Aborting install process.
fi
%endifCode: Select all
@@ -163,30 +163,32 @@
%install
rm -rf $RPM_BUILD_ROOT
make AM_INSTALL_PROGRAM_FLAGS="" DESTDIR=${RPM_BUILD_ROOT} install
-build-aux/install-sh -c -d ${RPM_BUILD_ROOT}%{_sysconfdir}
-build-aux/install-sh -c -m 664 command.cfg ${RPM_BUILD_ROOT}%{_sysconfdir}
+build-aux/install-sh -c -d ${RPM_BUILD_ROOT}%{_sysconfnagios}
+#build-aux/install-sh -c -m 664 command.cfg ${RPM_BUILD_ROOT}%{_sysconfnagios}
+build-aux/install-sh -c -m 664 plugins/libnpcommon.a ${RPM_BUILD_ROOT}%{_libexecnagios}
%find_lang %{name}
echo "%defattr(755,%{npusr},%{npgrp})" >> %{name}.lang
-comm -13 %{npdir}/ls-plugins-before %{npdir}/ls-plugins-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecdir} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
+comm -13 %{npdir}/ls-plugins-before %{npdir}/ls-plugins-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecnagios} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
echo "%defattr(755,root,root)" >> %{name}.lang
-comm -13 %{npdir}/ls-plugins-root-before %{npdir}/ls-plugins-root-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecdir} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
+comm -13 %{npdir}/ls-plugins-root-before %{npdir}/ls-plugins-root-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecnagios} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
echo "%defattr(755,%{npusr},%{npgrp})" >> %{name}.lang
-comm -13 %{npdir}/ls-plugins-scripts-before %{npdir}/ls-plugins-scripts-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecdir} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
-echo "%{_libexecdir}/utils.pm" >> %{name}.lang
-echo "%{_libexecdir}/utils.sh" >> %{name}.lang
+comm -13 %{npdir}/ls-plugins-scripts-before %{npdir}/ls-plugins-scripts-after | egrep -v "\.o$|^\." | gawk -v libexecdir=%{_libexecnagios} '{printf( "%s/%s\n", libexecdir, $0);}' >> %{name}.lang
+echo "%{_libexecnagios}/utils.pm" >> %{name}.lang
+echo "%{_libexecnagios}/utils.sh" >> %{name}.lang
%clean
rm -rf $RPM_BUILD_ROOT
%files -f %{name}.lang
-%config(missingok,noreplace) %{_sysconfdir}/command.cfg
+#%config(missingok,noreplace) %{_sysconfnagios}/command.cfg
%doc CODING COPYING FAQ INSTALL LEGAL README REQUIREMENTS SUPPORT THANKS
-%doc ChangeLog command.cfg
+%doc ChangeLog
%if ! %{isaix}
%{_datadir}/locale/de/LC_MESSAGES/nagios-plugins.mo
%{_datadir}/locale/fr/LC_MESSAGES/nagios-plugins.mo
%endif
+%{_libdir}/nagios/plugins/check_ldaps
%changelog
* Mon May 23 2005 Sean Finney <[email protected]> - cvs headI think command.cfg was not even built, IIRC.
check_ldaps is installed, but it's not taken into the RPM for some reason, and the final stage of package building breaks. I don't have time to investigate why. Just add it here and it works. This is not a clean fix, sorry.
NRPE 2.15
This one also has to be built as root, otherwise changing the ownership on check_nrpe fails.
Here's the diff:
Code: Select all
[root@oracle5 specs]# diff -u orig/nrpe.spec fixed/nrpe.spec
--- orig/nrpe.spec 2013-09-06 08:27:13.000000000 -0700
+++ fixed/nrpe.spec 2013-10-23 11:37:33.000000000 -0700
@@ -9,16 +9,14 @@
%endif
%if %{islinux}
%define _init_dir /etc/init.d
- %define _exec_prefix %{_prefix}/sbin
- %define _bindir %{_prefix}/sbin
- %define _sbindir %{_prefix}/lib/nagios/cgi
- %define _libexecdir %{_prefix}/lib/nagios/plugins
- %define _datadir %{_prefix}/share/nagios
- %define _localstatedir /var/log/nagios
- %define nshome /var/log/nagios
+ %define _bindir_nrpe %{_prefix}/sbin
+ %define _sbindir_nrpe %{_libdir}/nagios/cgi
+ %define _libexecdir_nrpe %{_libdir}/nagios/plugins
+ %define _datadir_nrpe %{_datadir}/nagios
+ %define nshome %{_localstatedir}/log/nagios
%define _make make
%endif
-%define _sysconfdir /etc/nagios
+%define _sysconfdir_nrpe %{_sysconfdir}/nagios
%define name nrpe
%define version 2.15And again, the same issue with the compatibility with Core w.r.t. the location of the plugins directory. This package, again, was incorrectly hardcoding it to */lib/nagios/plugins, unlike Core. Fixed that to make these packages play nicely together.
Code: Select all
@@ -141,7 +139,7 @@
%post
/usr/bin/lssrc -s nrpe > /dev/null 2> /dev/null
if [ $? -eq 1 ] ; then
- /usr/bin/mkssys -p %{_bindir}/nrpe -s nrpe -u 0 -a "-c %{_sysconfdir}/nrpe.cfg -d -s" -Q -R -S -n 15 -f 9
+ /usr/bin/mkssys -p %{_bindir_nrpe}/nrpe -s nrpe -u 0 -a "-c %{_sysconfdir_nrpe}/nrpe.cfg -d -s" -Q -R -S -n 15 -f 9
fi
/usr/bin/startsrc -s nrpe
%endifCode: Select all
@@ -177,13 +175,11 @@
--with-nrpe-user=%{nsusr} \
--with-nrpe-group=%{nsgrp} \
--prefix=%{_prefix} \
- --exec-prefix=%{_exec_prefix} \
- --bindir=%{_bindir} \
- --sbindir=%{_sbindir} \
- --libexecdir=%{_libexecdir} \
- --datadir=%{_datadir} \
- --sysconfdir=%{_sysconfdir} \
- --localstatedir=%{_localstatedir} \
+ --bindir=%{_bindir_nrpe} \
+ --sbindir=%{_sbindir_nrpe} \
+ --libexecdir=%{_libexecdir_nrpe} \
+ --datadir=%{_datadir_nrpe} \
+ --sysconfdir=%{_sysconfdir_nrpe} \
--enable-command-args
%{_make} allCode: Select all
@@ -193,17 +189,17 @@
install -d -m 0755 ${RPM_BUILD_ROOT}%{_init_dir}
%endif
DESTDIR=${RPM_BUILD_ROOT} %{_make} install install-daemon-config
-#install -d -m 0755 ${RPM_BUILD_ROOT}%{_sysconfdir}
-#install -d -m 0755 ${RPM_BUILD_ROOT}%{_bindir}
-#install -d -m 0755 ${RPM_BUILD_ROOT}%{_libexecdir}
+#install -d -m 0755 ${RPM_BUILD_ROOT}%{_sysconfdir_nrpe}
+#install -d -m 0755 ${RPM_BUILD_ROOT}%{_bindir_nrpe}
+#install -d -m 0755 ${RPM_BUILD_ROOT}%{_libexecdir_nrpe}
# install templated configuration files
-#cp sample-config/nrpe.cfg ${RPM_BUILD_ROOT}%{_sysconfdir}/nrpe.cfg
+cp sample-config/nrpe.cfg ${RPM_BUILD_ROOT}%{_sysconfdir_nrpe}/nrpe.cfg
#%if %{isaix}
-#cp init-script ${RPM_BUILD_ROOT}%{_init_dir}/nrpe
+cp init-script ${RPM_BUILD_ROOT}%{_init_dir}/nrpe
#%endif
-#cp src/nrpe ${RPM_BUILD_ROOT}%{_bindir}
-#cp src/check_nrpe ${RPM_BUILD_ROOT}%{_libexecdir}
+#cp src/nrpe ${RPM_BUILD_ROOT}%{_bindir_nrpe}
+#cp src/check_nrpe ${RPM_BUILD_ROOT}%{_libexecdir_nrpe}
%clean
rm -rf $RPM_BUILD_ROOTNot sure why the init script was not being copied to /etc/init.d. It's needed there for the NRPE service. I've enabled the copy. Same for the .cfg file.
Code: Select all
@@ -214,16 +210,16 @@
%defattr(755,root,root)
/etc/init.d/nrpe
%endif
-%{_bindir}/nrpe
-%dir %{_sysconfdir}
+%{_bindir_nrpe}/nrpe
+%dir %{_sysconfdir_nrpe}
%defattr(600,%{nsusr},%{nsgrp})
-%config(noreplace) %{_sysconfdir}/*.cfg
+%config(noreplace) %{_sysconfdir_nrpe}/*.cfg
%defattr(755,%{nsusr},%{nsgrp})
%doc Changelog LEGAL README
%files plugin
%defattr(755,%{nsusr},%{nsgrp})
-%{_libexecdir}
+%{_libexecdir_nrpe}
%defattr(644,%{nsusr},%{nsgrp})
%doc Changelog LEGAL README