Changes of Revision 7
[-] | Added | nagios.spec |
x 1
2 +%define name nagios 3 +%define version 2.10 4 +%define release 1 5 +%define nsusr nagios 6 +%define nsgrp nagios 7 +%define cmdgrp nagiocmd 8 +%define wwwusr wwwrun 9 +%define wwwgrp www 10 + 11 +# Performance data handling method to use. By default we will use 12 +# the file-based one (as existed in NetSaint). 13 +# You can select the external command based method (the defaut for 14 +# Nagios) by specifying 15 +# --define 'PERF_EXTERNAL 1' 16 +# in the rpm command-line 17 +%{!?PERF_EXTERNAL: %define PERF_EXTERNAL 0} 18 + 19 +# Embedded Perl stuff, specify 20 +# --define 'EMBPERL 1' 21 +# in the rpm command-line to enable it 22 +%{!?EMBPERL: %define EMBPERL 0} 23 + 24 +# Macro that print mesages to syslog at package (un)install time 25 +%define nnmmsg logger -t %{name}/rpm 26 + 27 +Summary: Host/service/network monitoring program 28 +Name: %{name} 29 +Version: %{version} 30 +Release: %{release} 31 +License: GPL 32 +Group: Application/System 33 +Source0: %{name}-%{version}.tar.gz 34 +BuildRoot: %{_tmppath}/%{name}-buildroot 35 +Prefix: %{_prefix} 36 +Prefix: /etc/init.d 37 +Prefix: /etc/nagios 38 +Prefix: /var/log/nagios 39 +Prefix: /var/spool/nagios 40 +Requires: gd > 1.8 zlib libpng libjpeg bash grep 41 +PreReq: /bin/logger, sed, mktemp 42 +BuildRequires: gd-devel > 1.8 zlib-devel libpng-devel libjpeg-devel glibc-devel libgcc gcc gcc-c++ perl 43 +%if 0%{?fedora_version} == 7 44 +BuildRequires: perl-ExtUtils-MakeMaker 45 +%endif 46 + 47 +%description 48 +Nagios is a program that will monitor hosts and services on your 49 +network. It has the ability to email or page you when a problem arises 50 +and when a problem is resolved. Nagios is written in C and is 51 +designed to run under Linux (and some other *NIX variants) as a 52 +background process, intermittently running checks on various services 53 +that you specify. 54 + 55 +The actual service checks are performed by separate "plugin" programs 56 +which return the status of the checks to Nagios. The plugins are 57 +available at http://sourceforge.net/projects/nagiosplug 58 + 59 +This package provide core programs for nagios. The web interface, 60 +documentation, and development files are built as separate packages 61 + 62 + 63 +%package www 64 +Group: Application/System 65 +Summary: Provides the HTML and CGI files for the Nagios web interface. 66 +Requires: %{name} = %{version} 67 +Requires: http_daemon 68 + 69 + 70 +%description www 71 +Nagios is a program that will monitor hosts and services on your 72 +network. It has the ability to email or page you when a problem arises 73 +and when a problem is resolved. Nagios is written in C and is 74 +designed to run under Linux (and some other *NIX variants) as a 75 +background process, intermittently running checks on various services 76 +that you specify. 77 + 78 +Several CGI programs are included with Nagios in order to allow you 79 +to view the current service status, problem history, notification 80 +history, and log file via the web. This package provides the HTML and 81 +CGI files for the Nagios web interface. In addition, HTML 82 +documentation is included in this package 83 + 84 + 85 +%package devel 86 +Group: Application/System 87 +Summary: Provides include files that Nagios-related applications may compile against. 88 +Requires: %{name} = %{version} 89 + 90 +%description devel 91 +Nagios is a program that will monitor hosts and services on your 92 +network. It has the ability to email or page you when a problem arises 93 +and when a problem is resolved. Nagios is written in C and is 94 +designed to run under Linux (and some other *NIX variants) as a 95 +background process, intermittently running checks on various services 96 +that you specify. 97 + 98 +This package provides include files that Nagios-related applications 99 +may compile against. 100 + 101 + 102 +%prep 103 +%setup -q 104 + 105 + 106 +%pre 107 +# Create `nagios' user on the system if necessary 108 +if /usr/bin/id %{nsusr} > /dev/null 2>&1 ; then 109 + : # user already exists 110 +else 111 + /usr/sbin/useradd -r -d /var/log/nagios -s /bin/sh -c "%{nsusr}" %{nsusr} || \ 112 + %nnmmsg Unexpected error adding user "%{nsusr}". Aborting install process. 113 +fi 114 + 115 +# id cannot tell us if the group already exists 116 +# so just try to create it and assume it works 117 +/usr/sbin/groupadd %{nsgrp} > /dev/null 2>&1 118 +/usr/sbin/groupadd %{cmdgrp} > /dev/null 2>&1 119 + 120 +# if LSB standard /etc/init.d does not exist, 121 +# create it as a symlink to the first match we find 122 +if [ -d /etc/init.d -o -L /etc/init.d ]; then 123 + : # we're done 124 +elif [ -d /etc/rc.d/init.d ]; then 125 + ln -s /etc/rc.d/init.d /etc/init.d 126 +elif [ -d /usr/local/etc/rc.d ]; then 127 + ln -s /usr/local/etc/rc.d /etc/init.d 128 +elif [ -d /sbin/init.d ]; then 129 + ln -s /sbin/init.d /etc/init.d 130 +fi 131 + 132 + 133 +%preun 134 +if [ "$1" = 0 ]; then 135 + /sbin/service nagios stop > /dev/null 2>&1 136 + /sbin/chkconfig --del nagios 137 +fi 138 + 139 +%postun 140 +if [ "$1" -ge "1" ]; then 141 + /sbin/service nagios condrestart >/dev/null 2>&1 || : 142 +fi 143 +# Delete nagios user and group 144 +# (if grep doesn't find a match, then it is NIS or LDAP served and cannot be deleted) 145 +if [ $1 = 0 ]; then 146 + /bin/grep '^%{nsusr}:' /etc/passwd > /dev/null 2>&1 && /usr/sbin/userdel %{nsusr} || %nnmmsg "User %{nsusr} could not be deleted." 147 + /bin/grep '^%{nsgrp}:' /etc/group > /dev/null 2>&1 && /usr/sbin/groupdel %{nsgrp} || %nnmmsg "Group %{nsgrp} could not be deleted." 148 + /bin/grep '^%{cmdgrp}:' /etc/group > /dev/null 2>&1 && /usr/sbin/groupdel %{cmdgrp} || %nnmmsg "Group %{cmdgrp} could not be deleted." 149 +fi 150 + 151 + 152 +%post www 153 +# If apache is installed, and we can find the apache user, set a shell var 154 +wwwusr=`awk '/^[ \t]*User[ \t]+[a-zA-Z0-9]+/ {print $2}' /etc/apache2/*.conf` 155 +if [ "z" == "z$wwwusr" ]; then # otherwise, use the default 156 + wwwusr=%{wwwusr} 157 +fi 158 +# if apache user is not in cmdgrp, add it 159 +if /usr/bin/id -Gn $wwwusr 2>/dev/null | /bin/grep -q %{cmdgrp} > /dev/null 2>&1 ; then 160 + : # $wwwusr (default: apache) is already in nagiocmd group 161 +else 162 + # first find apache primary group 163 + pgrp=`/usr/bin/id -gn $wwwusr 2>/dev/null` 164 + # filter apache primary group from secondary groups 165 + sgrps=`/usr/bin/id -Gn $wwwusr 2>/dev/null | /bin/sed "s/^$pgrp //;s/ $pgrp //;s/^$pgrp$//;s/ /,/g;"` 166 + if [ "z" == "z$sgrps" ] ; then 167 + sgrps=%{nsgrp} 168 + else 169 + sgrps=$sgrps,%{cmdgrp} 170 + fi 171 + # modify apache user, adding it to cmdgrp 172 + /usr/sbin/usermod -G $sgrps $wwwusr >/dev/null 2>&1 173 + %nnmmsg "User $wwwusr added to group %{cmdgrp} so sending commands to Nagios from the command CGI is possible." 174 +fi 175 + 176 + 177 +%preun www 178 +if [ $1 = 0 ]; then 179 +if test -f /etc/apache2/httpd.conf; then 180 + TEMPFILE=`mktemp /etc/apache2/httpd.conf.tmp.XXXXXX` 181 + if grep "^ *Include /etc/apache2/conf.d/nagios.conf" /etc/apache2/httpd.conf > /dev/null; then 182 + grep -v "^ *Include /etc/apache2/conf.d/nagios.conf" /etc/apache2/httpd.conf > $TEMPFILE 183 + mv $TEMPFILE /etc/apache2/httpd.conf 184 + chmod 644 /etc/apache2/httpd.conf 185 + /etc/init.d/apache2 restart 186 + fi 187 +fi 188 +fi 189 + 190 + 191 +%build 192 +export PATH=$PATH:/usr/sbin 193 +CFLAGS="$RPM_OPT_FLAGS" CXXFLAGS="$RPM_OPT_FLAGS" \ 194 +./configure \ 195 + --with-init-dir=/etc/init.d \ 196 + --with-cgiurl=/nagios/cgi-bin \ 197 + --with-htmurl=/nagios \ 198 + --with-lockfile=/var/run/nagios.pid \ 199 + --with-nagios-user=%{nsusr} \ 200 + --with-nagios-group=%{nsgrp} \ 201 |