dijous, 2 d’abril de 2015

Xymon Client 4.3.19 for RHEL 7 RPM Creation

Introducció:

L'objectiu d'aquest document es entendre com funciona la generació d'RPMs i generar un rpm a mida per a la instal·lació del client de xymon 4.3.19 per a RHEL 7.

Creació d'un RPM

Per a generar paquets RPM hem d'instal·lar el següents paquets:
yum install rpm-build rpmdevtools
Creem un usuari no privilegiat per a realitzar la compil·lació.
useradd developer
passwd developer
su developer
A continuació creem l'estructura per a la genaració del RPM, aquesta comanda generarà un directori amb el nom rpmbuild d'on penjaran tots els directoris i fitxers necessaris per a la seua generació.
cd ~/
rpmdev-setuptree
Per a la generació del RPM copiem en el directori /home/developer/rpmbuild/SOURCES/ els següents fitxers:
  • xymon-4.3.19.tar.gz
  • client-ext/
  • 98-xymonlaunch.present
  • xymon-client.default
  • xymon-client.service
  • xymon-init.d
  • xymonlaunch
  • xymonlaunch.service
  • xymon.logrotate
També creem un fitxer xymon.spec en /home/developer/rpmbuild/SPECS/
La configuració dels següents fitxers s'ha realitzar utilitzant com a base els fitxers de rpm proporcionats dins de la configuració del tar.gz de xymon i els rpms de terrabithia (veure enllaços del final).

El contingut del fitxer xymon.spec es el següent:
Name: xymon
Version: 4.3.19
Release: 1
Group: Networking/Daemons
URL: http://xymon.sourceforge.net/
License: GPL
Source: xymon-4.3.19.tar.gz
Source1: xymon.logrotate
Source2: xymonlaunch
Source3: xymon-client.default
Source4: client-ext
Source5: xymonlaunch.service
Source6: 98-xymonlaunch.preset
Source7: xymon-client.service
Summary: Xymon network monitor
BuildRoot: /tmp/xymon-root
#BuildRequires: openssl-devel
#BuildRequires: pcre-devel
#BuildRequires: rrdtool-devel
#BuildRequires: openldap-devel
Conflicts: xymon-client

%description
Xymon (previously known as Hobbit) is a system for monitoring 
your network servers and applications. This package contains 
the server side of the Xymon package.

%package client
Summary: Xymon client reporting data to the Xymon server
Group: Applications/System
Conflicts: xymon

%description client
This package contains a client for the Xymon (previously known
as Hobbit) monitor. Clients report data about the local system to 
the monitor, allowing it to check on the status of the system 
load, filesystem utilisation, processes that must be running etc.

%prep
rm -rf $RPM_BUILD_ROOT

%setup
        USEXYMONPING=y \
        ENABLESSL=y \
        ENABLELDAP=y \
        ENABLELDAPSSL=y \
        XYMONUSER=xymon \
        XYMONTOPDIR=/usr/lib/xymon \
        XYMONVAR=/var/lib/xymon \
        XYMONHOSTURL=/xymon \
        CGIDIR=/usr/lib/xymon/cgi-bin \
        XYMONCGIURL=/xymon-cgi \
        SECURECGIDIR=/usr/lib/xymon/cgi-secure \
        SECUREXYMONCGIURL=/xymon-seccgi \
        HTTPDGID=apache \
        XYMONLOGDIR=/var/log/xymon \
        XYMONHOSTNAME=localhost \
        XYMONHOSTIP=127.0.0.1 \
        MANROOT=/usr/share/man \
        INSTALLBINDIR=/usr/lib/xymon/server/bin \
        INSTALLETCDIR=/etc/xymon \
        INSTALLWEBDIR=/etc/xymon/web \
        INSTALLEXTDIR=/usr/lib/xymon/server/ext \
        INSTALLTMPDIR=/var/lib/xymon/tmp \
        INSTALLWWWDIR=/var/lib/xymon/www \
        ./configure

%build
        PKGBUILD=1 make

%install
        INSTALLROOT=$RPM_BUILD_ROOT PKGBUILD=1 make install
        mkdir -p $RPM_BUILD_ROOT/etc/logrotate.d
        cp %{SOURCE1} $RPM_BUILD_ROOT/etc/logrotate.d/xymon
        mkdir -p $RPM_BUILD_ROOT/etc/sysconfig
        cp %{SOURCE3} $RPM_BUILD_ROOT/etc/sysconfig/xymon-client
        cp %{SOURCE2} $RPM_BUILD_ROOT/etc/sysconfig/xymonlaunch
        mkdir -p $RPM_BUILD_ROOT/usr/bin
        cd $RPM_BUILD_ROOT/usr/bin && ln -sf ../lib/xymon/server/bin/{xymon,xymoncmd} .
        mkdir -p $RPM_BUILD_ROOT/etc/httpd/conf.d
        mv $RPM_BUILD_ROOT/etc/xymon/xymon-apache.conf $RPM_BUILD_ROOT/etc/httpd/conf.d/
        rmdir $RPM_BUILD_ROOT/usr/lib/xymon/client/tmp
        cd $RPM_BUILD_ROOT/usr/lib/xymon/client && ln -sf /tmp tmp
        rmdir $RPM_BUILD_ROOT/usr/lib/xymon/client/logs
        cd $RPM_BUILD_ROOT/usr/lib/xymon/client && ln -sf ../../../../var/log/xymon logs
        mv $RPM_BUILD_ROOT/usr/lib/xymon/client/etc/xymonclient.cfg /tmp/xymonclient.cfg.$$
        cat /tmp/xymonclient.cfg.$$ | sed -e \
        's!^XYMSRV=.*!include /etc/sysconfig/xymon-client!' | grep -v \
        "^XYMSERVERS=" >$RPM_BUILD_ROOT/usr/lib/xymon/client/etc/xymonclient.cfg
        rm /tmp/xymonclient.cfg.$$
        cp -r %{SOURCE4} $RPM_BUILD_ROOT/usr/lib/xymon/client/ext/
        mv $RPM_BUILD_ROOT/usr/lib/xymon/client/ext/client-ext/*   \ 
        $RPM_BUILD_ROOT/usr/lib/xymon/client/ext/
        rmdir $RPM_BUILD_ROOT/usr/lib/xymon/client/ext/client-ext
        mkdir -p $RPM_BUILD_ROOT/run/xymon
        mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/
        mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/system
        mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/system-present
        cp %{SOURCE5} $RPM_BUILD_ROOT/usr/lib/systemd/system/
        cp %{SOURCE7} $RPM_BUILD_ROOT/usr/lib/systemd/system/
        cp %{SOURCE6} $RPM_BUILD_ROOT/usr/lib/systemd/system-present/

%clean
rm -rf $RPM_BUILD_ROOT


%pre
id xymon 1>/dev/null 2>&1
if [ $? -ne 0 ]
then
   groupadd xymon || true
   useradd -g xymon -c "Xymon user" -d /usr/lib/xymon xymon
fi

%pre client
id xymon 1>/dev/null 2>&1
if [ $? -ne 0 ]
then
   groupadd xymon || true
   useradd -g xymon -c "Xymon user" -d /usr/lib/xymon xymon
fi

%post client
systemctl enable xymon-client.service

%preun client
systemctl stop xymon-client
systemctl disable xymon-client

%files
%attr(-, root, root) %doc README README.CLIENT Changes* COPYING CREDITS RELEASENOTES
%attr(644, root, root) %doc /usr/share/man/man*/*
%attr(644, root, root) %config /etc/xymon/*
%attr(644, root, root) %config /etc/httpd/conf.d/xymon-apache.conf
%attr(755, root, root) %dir /etc/xymon 
%attr(755, root, root) %dir /etc/xymon/tasks.d
%attr(755, root, root) %dir /usr/lib/xymon/server/download
%attr(755, root, root) %dir /etc/xymon/web
%attr(755, xymon, xymon) %dir /var/log/xymon
%attr(644, root, root) /etc/logrotate.d/xymon
%attr(-, root, root) /usr/lib/xymon
%attr(-, root, root) /usr/bin/*
%attr(-, xymon, xymon) /var/lib/xymon
%attr(775, xymon, apache) %dir /var/lib/xymon/www/rep
%attr(775, xymon, apache) %dir /var/lib/xymon/www/snap
%attr(644, root, root) %config /var/lib/xymon/www/menu/xymonmenu-grey.css
%attr(644, root, root) %config /var/lib/xymon/www/menu/xymonmenu-blue.css
%attr(755, xymon, xymon) %dir /usr/lib/xymon/client/ext
%attr(664, xymon, apache) %config /etc/xymon/critical.cfg
%attr(664, xymon, apache) %config /etc/xymon/critical.cfg.bak
%attr(4750, root, xymon) /usr/lib/xymon/server/bin/xymonping
%attr(750, root, xymon) /usr/lib/xymon/client/bin/logfetch
%attr(750, root, xymon) /usr/lib/xymon/client/bin/clientupdate

%files client
%attr(-, root, root) %doc README README.CLIENT Changes* COPYING CREDITS RELEASENOTES
%attr(-, root, root) /usr/lib/xymon/client
%attr(644, root, root) %config /etc/sysconfig/xymon-client
%attr(644, root, root) %config /etc/sysconfig/xymonlaunch
%attr(644, root, root) %config /usr/lib/systemd/system/xymonlaunch.service
%attr(644, root, root) %config /usr/lib/systemd/system/xymon-client.service
%attr(644, root, root) %config /usr/lib/systemd/system-present/98-xymonlaunch.preset
%attr(755, xymon, xymon) %dir /var/log/xymon
%attr(755, xymon, xymon) %dir /usr/lib/xymon/client/ext
%attr(755, xymon, xymon) %config /usr/lib/xymon/client/ext/*
%attr(750, root, xymon) /usr/lib/xymon/client/bin/logfetch
%attr(750, root, xymon) /usr/lib/xymon/client/bin/clientupdate
%attr(644, root, root) /run/xymon/
En client_ext tenim els scripts a mida que comproben determinats monitors. A continuació el contingut dels següents fitxer importants, en xymon-client.default tenim el següent:
XYMSRV="0.0.0.0"
XYMSERVERS="192.168.1.2 192.168.1.3"
En xymon-client.service tenim el init script de xymon per a Redhat 7
# systemd file for Fedora 18 and up, or RHEL 7 and up

[Unit]
Description=Xymon systems and network monitor
Documentation=man:xymon(7) man:xymonlaunch(8) man:xymon(1)
After=network.target

[Install]
# Compatibility with "xymon" and "xymon-client"
Alias=xymon.service
Alias=xymon-client.service
WantedBy=multi-user.target


[Service]
EnvironmentFile=/etc/sysconfig/xymonlaunch
User=xymon
# We wrap in xymoncmd to eliminate the need for the bulk of the old init script
ExecStart=/usr/lib/xymon/client/bin/xymoncmd /usr/lib/xymon/client/bin/xymonlaunch \
  --config=/usr/lib/xymon/client/etc/clientlaunch.cfg --no-daemon $XYMONLAUNCHOPTS
Type=simple

# Kill xymonlaunch, but don't send kills to the underlying procs, since they
# might be doing important things (like writing checkpoints and flushing caches)
KillMode=process
# SendSIGHUP=yes
SendSIGKILL=no
Una volta tenim ja tot al seu lloc generem el rpm amb:
rpmbuild -ba SPECS/xymon.spec
I finalment ja podem instal·lar el paquet en RHEL 7 amb:
rpm -ivh xymon-client-4.3.19-1.x86_64.rpm --nodeps

Comandes utils per a la creació de RPM

Si volem veure el contingut de un rpm sense instal·lar-lo ho podem fer amb la següent ordre:
 rpm2cpio xymon-client-4.3.19-1-x86_64.rpm | cpio -idmv
Llavors ens el desempaqueta en el mateix directory on hem executat la comanda i ja podem accedir seguint la seua estructura de directories. Una altra comanda interessant per interactuar amb rpms es
rpm -qp xymon-client-4.3.19-1.x86_64.rpm --requires
Amb aquesta comanda veiem les dependencies del paquet. Amb l'opció --provides podem veure el que ens aporta el paquet.
rpm -qp xymon-client-4.3.19-1.x86_64.rpm --provides

ENLLAÇOS

http://www.cyberciti.biz/tips/how-to-extract-an-rpm-package-without-installing-it.html
http://mylinuxlife.com/building-rpms-in-rhel-6/
https://fedoraproject.org/wiki/How_to_create_an_RPM_package/es
http://lists.xymon.com/archive/2011-March/031039.html
http://terabithia.org/rpms/xymon/

Cap comentari:

Publica un comentari a l'entrada