2009-08-11 Sancho Lerena <slerena@artica.es>

* pandora_server: Using new method to get PID of process, compatible with
	any distro (SUSE problems reported). Removed old stuff and updated headers.
	
	* pandora_server_installer: A lot of improvementes and added separated code
	for Ubuntu/Debian and SUSE targets. Fixed some minor bugs reported.
	
	* bin/pandora_server: Added a new die handled for manage crashes and report
	more information into logs and console on startup. This helps to determine
	some common problems.
	
	* Config.pm: Updated version number.
	
	* util/tentacle_serverd: Fixed startup script to work also in SUSE. New
	code for getpid compatible with all distros.

	* Makefile.PL,  NetworkServer.pm: Removed Net::Ping dependency, 
	not used anymore. Pending to remove Date::Manip from pandora_db script.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1840 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2009-08-11 16:26:09 +00:00
parent f8c9288521
commit 732c2ac20e
8 changed files with 280 additions and 151 deletions

View File

@ -1,4 +1,24 @@
2009-08-10 Sancho Lerena <slerena@artica.es> 2009-08-11 Sancho Lerena <slerena@artica.es>
* pandora_server: Using new method to get PID of process, compatible with
any distro (SUSE problems reported). Removed old stuff and updated headers.
* pandora_server_installer: A lot of improvementes and added separated code
for Ubuntu/Debian and SUSE targets. Fixed some minor bugs reported.
* bin/pandora_server: Added a new die handled for manage crashes and report
more information into logs and console on startup. This helps to determine
some common problems.
* Config.pm: Updated version number.
* util/tentacle_serverd: Fixed startup script to work also in SUSE. New
code for getpid compatible with all distros.
* Makefile.PL, NetworkServer.pm: Removed Net::Ping dependency,
not used anymore. Pending to remove Date::Manip from pandora_db script.
2009-08-09 Sancho Lerena <slerena@artica.es>
* pandora_server.conf: Removed deprecated parameter: Alert_threshold. * pandora_server.conf: Removed deprecated parameter: Alert_threshold.

View File

@ -4,7 +4,7 @@ use ExtUtils::MakeMaker;
WriteMakefile( WriteMakefile(
NAME => 'PandoraFMS', NAME => 'PandoraFMS',
VERSION_FROM => 'lib/PandoraFMS/Config.pm', VERSION_FROM => 'lib/PandoraFMS/Config.pm',
AUTHOR => 'Sancho Lerena <slerena@artica.es>', AUTHOR => 'Artica ST <info@artica.es>',
PREREQ_PM => { PREREQ_PM => {
NetAddr::IP => 0, NetAddr::IP => 0,
DBI => 0, DBI => 0,
@ -14,7 +14,6 @@ WriteMakefile(
Time::Local => 0, Time::Local => 0,
Date::Manip => 0, Date::Manip => 0,
XML::Simple => 0, XML::Simple => 0,
Net::Ping => 0,
Time::HiRes => 0, Time::HiRes => 0,
IO::Socket => 0, IO::Socket => 0,
Mail::Sendmail => 0, Mail::Sendmail => 0,

View File

@ -42,7 +42,7 @@ my @Servers;
my $DBH; my $DBH;
######################################################################################## ########################################################################################
# Server shutdown # Server shutdown. Handler to do a controlled shutdown.
######################################################################################## ########################################################################################
sub pandora_shutdown () { sub pandora_shutdown () {
logger (\%Config, 'Pandora FMS Server \'' . $Config{'servername'} . '\' Shutdown by signal ', 0); logger (\%Config, 'Pandora FMS Server \'' . $Config{'servername'} . '\' Shutdown by signal ', 0);
@ -57,8 +57,24 @@ sub pandora_shutdown () {
exit (0); exit (0);
} }
########################################################################################
# Server crash. Handler to write in the log unhandled errors and write it to console
########################################################################################
sub pandora_crash () {
logger (\%Config, 'Pandora FMS Server \'' . $Config{'servername'} . '\' unhandled error', 0);
print_message (\%Config, '[E] Unhandled error in "' . $Config{'servername'} . "\". See more information in logfiles at '/var/log/pandora' \n", 0);
my(@array) = @_;
foreach my $error_line (@array) {
logger (\%Config, '[E] \'' . $Config{'servername'} . "': $error_line", 0);
print_message (\%Config, "[E] $error_line \n", 0);
}
}
$SIG{'TERM'} = 'pandora_shutdown'; $SIG{'TERM'} = 'pandora_shutdown';
$SIG{'INT'} = 'pandora_shutdown'; $SIG{'INT'} = 'pandora_shutdown';
$SIG{__DIE__} = 'pandora_crash';
# Prevent alarm from bombing the main thread when called within a thread # Prevent alarm from bombing the main thread when called within a thread
$SIG{'ALRM'} = 'IGNORE'; $SIG{'ALRM'} = 'IGNORE';

View File

@ -37,7 +37,7 @@ our @EXPORT = qw(
# version: Defines actual version of Pandora Server for this module only # version: Defines actual version of Pandora Server for this module only
my $pandora_version = "3.0-dev"; my $pandora_version = "3.0-dev";
my $pandora_build = "PS090310"; my $pandora_build = "PS090810";
our $VERSION = $pandora_version." ".$pandora_build; our $VERSION = $pandora_version." ".$pandora_build;
# Setup hash # Setup hash

View File

@ -25,7 +25,6 @@ use threads::shared;
use Thread::Semaphore; use Thread::Semaphore;
use IO::Socket::INET; use IO::Socket::INET;
use Net::Ping;
use POSIX qw(strftime); use POSIX qw(strftime);
use PandoraFMS::Tools; use PandoraFMS::Tools;

View File

@ -1,19 +1,29 @@
#!/bin/bash #!/bin/bash
# Pandora FMS Server, startup script # Pandora FMS Server, startup script
# Copyright (c) 2006-2008 Sancho Lerena, <slerena@gmail.com> # Copyright (c) 2006-2009 Sancho Lerena, <sancho.lerena@artica.es>
# Linux Version (generic) # Linux Version (generic), for SuSe and Debian/Ubuntu.
# v2.1 Build 081030 # other Linux distros could not work properly without modifications
# v3.0 Build 090810
# http://www.pandorafms.com # http://www.pandorafms.com
# chkconfig: 23 99 99 # chkconfig: 23 99 99
# description: Manages starting/stopping of server # description: Manages starting/stopping of server
# Configurable path and filenames # Configurable path and filenames
PANDORA_HOME="/etc/pandora/pandora_server.conf" PANDORA_HOME="/etc/pandora/pandora_server.conf"
PANDORA_PID_PATH="/var/run" PANDORA_PID_PATH="/var/run"
PANDORA_PID=$PANDORA_PID_PATH/pandora_server.pid PANDORA_PID=$PANDORA_PID_PATH/pandora_server.pid
PANDORA_DAEMON=/usr/local/bin/pandora_server PANDORA_DAEMON=/usr/local/bin/pandora_server
# This function replace pidof, not working in the same way in different linux distros
function pidof_pandora () (
PANDORA_PID=`ps aux | grep $PANDORA_DAEMON | grep -v grep | tail -1 | awk '{ print $2 }'`
echo $PANDORA_PID
)
# Main script # Main script
if [ ! -d "$PANDORA_PID_PATH" ] if [ ! -d "$PANDORA_PID_PATH" ]
@ -30,47 +40,54 @@ fi
case "$1" in case "$1" in
start) start)
OLD_PATH="`pwd`" PANDORA_PID=`pidof_pandora`
PANDORA_PID=$(pidof -x $PANDORA_DAEMON) if [ ! -z "$PANDORA_PID" ]
if [ ! -z $PANDORA_PID ]
then then
echo "Pandora FMS Server is currently running on this machine with PID ($PANDORA_PID). Aborting now..." echo "Pandora FMS Server is currently running on this machine with PID ($PANDORA_PID). Aborting now..."
exit 1 exit 1
else
rm -f $PANDORA_PID
fi fi
$PANDORA_DAEMON $PANDORA_HOME -D $PANDORA_DAEMON $PANDORA_HOME -D
sleep 1 sleep 2
PANDORA_PID=$(pidof -x $PANDORA_DAEMON) PANDORA_PID=`pidof_pandora`
if [ ! -z "$PANDORA_PID" ] if [ ! -z "$PANDORA_PID" ]
then then
echo "Pandora Server is now running with PID $PANDORA_PID" echo "Pandora Server is now running with PID $PANDORA_PID"
else else
echo "Cannot start Pandora FMS Server. Aborted." echo "Cannot start Pandora FMS Server. Aborted."
echo "Check Pandora FMS log files at '/var/log/pandora/pandora_server.log'"
fi fi
cd "$OLD_PATH"
;; ;;
stop) stop)
PANDORA_PID=$(pidof -x $PANDORA_DAEMON) PANDORA_PID=`pidof_pandora`
if [ -z $PANDORA_PID ] if [ -z "$PANDORA_PID" ]
then then
echo "Pandora FMS Server is not running, cannot stop it." echo "Pandora FMS Server is not running, cannot stop it."
exit 1 exit 1
else else
echo "Stopping Pandora FMS Server" echo "Stopping Pandora FMS Server"
kill $PANDORA_PID > /dev/null 2>&1 kill $PANDORA_PID > /dev/null 2>&1
rm -f $PANDORA_PID
fi fi
;; ;;
status)
PANDORA_PID=`pidof_pandora`
if [ -z "$PANDORA_PID" ]
then
echo "Pandora FMS Server is not running."
else
echo "Pandora FMS Server is running with PID $PANDORA_PID."
fi
exit 0
;;
force-reload|restart) force-reload|restart)
$0 stop $0 stop
sleep 2 sleep 3
$0 start $0 start
;; ;;
*) *)
echo "Usage: pandora_server {start|stop|restart}" echo "Usage: pandora_server { start | stop | restart | status }"
exit 1 exit 1
esac esac

View File

@ -1,22 +1,58 @@
# Pandora FMS 3.0 Server Installer (c) 2008-2009 Artica ST #!/bin/bash
# Pandora FMS Server Installer (c) 2008-2009 Artica ST
# Linux Version (generic), for SuSe and Debian/Ubuntu only
# other Linux distros could not work properly without modifications
# Please see http://www.pandorafms.org # Please see http://www.pandorafms.org
# v3.0 Build 090810
# This code is licensed under GPL 2.0 license. # This code is licensed under GPL 2.0 license.
# ********************************************************************** # **********************************************************************
#!/bin/bash
MODE=$1 MODE=$1
SECOPT=$2 SECOPT=$2
get_distro () {
# Get Linux Distro type and version
if [ -f "/etc/SuSE-release" ]
then
OS_VERSION=`cat /etc/SuSE-release | grep VERSION | cut -f 3 -d " "`
LINUX_DISTRO=SUSE
else
if [ -f "/etc/lsb-release" ]
then
OS_VERSION=`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -f 2 -d "="`
LINUX_DISTRO=UBUNTU
OS_VERSION="UBUNTU $OS_VERSION"
else
if [ -f "/etc/debian_version" ]
then
OS_VERSION=`cat /etc/debian_version`
OS_VERSION="DEBIAN $OS_VERSION"
LINUX_DISTRO=DEBIAN
else
if [ -f "/etc/fedora-release" ]
then
OS_VERSION=`cat /etc/fedora-release | cut -f 4 -d " "`
OS_VERSION="FEDORA $OS_VERSION"
LINUX_DISTRO=FEDORA
else
LINUX_DISTRO=GENERIC
OS_VERSION=`uname -r`
fi
fi
fi
fi
echo $LINUX_DISTRO
}
install () { install () {
perl Makefile.PL > output 2>&1 #&& sleep 2 && cat output | grep "found" | wc -l perl Makefile.PL > output 2>&1 #&& sleep 2 && cat output | grep "found" | wc -l
DEPENDENCIAS=`cat output | grep "found" | wc -l`
DEPENDENCIAS=`cat output | grep "found" | wc -l` if [ $DEPENDENCIAS -gt 0 ]
then
if [ $DEPENDENCIAS -gt 0 ]
then
echo "You are missing the following dependencies" echo "You are missing the following dependencies"
echo " " echo " "
cat output | awk -F ": prerequisite" '{print $2}' | awk -F " " '{print $1}' cat output | awk -F ": prerequisite" '{print $2}' | awk -F " " '{print $1}'
@ -25,67 +61,109 @@ then
echo "Debian-based distribution do:" echo "Debian-based distribution do:"
echo " $ apt-get install libdate-manip-perl snmp snmpd libsnmp-perl libtime-format-perl libxml-simple-perl libnetaddr-ip-perl libdbi-perl libxml-simple-perl libnetaddr-ip-perl libhtml-parser-perl wmi-client xprobe2 libmail-sendmail-perl" echo " $ apt-get install libdate-manip-perl snmp snmpd libsnmp-perl libtime-format-perl libxml-simple-perl libnetaddr-ip-perl libdbi-perl libxml-simple-perl libnetaddr-ip-perl libhtml-parser-perl wmi-client xprobe2 libmail-sendmail-perl"
echo " " echo " "
echo "RedHat-based distribution do" echo "RPM distribution do"
echo " " echo " "
echo " $ yum perl-XML-SAX* perl-Tie* perl-XML-Simple* perl-DateManip* perl-IO-Socket* perl-Time-modules* perl-NetAddr-IP* perl-GD* perl-DateTime* perl-ExtUtils" echo " $ yum perl-XML-SAX* perl-Tie* perl-XML-Simple* perl-IO-Socket* perl-Time-modules* perl-NetAddr-IP* perl-GD* perl-DateTime* perl-ExtUtils perl-DBI perl-Date-Manip perl-SNMP"
echo " " echo " "
echo "To get it from source through CPAN do" echo "To get it from source through CPAN do"
echo " " echo " "
echo " $ cpan Digest::MD5 Time::Local DBI threads threads::shared IO::Socket Time::HiRes Time::Format Net::Ping NetAddr::IP Mail::Sendmail Net::Traceroute::PurePerl HTML::Entities" echo " $ cpan Digest::MD5 Time::Local DBI threads threads::shared IO::Socket Time::HiRes Time::Format NetAddr::IP Mail::Sendmail Net::Traceroute::PurePerl HTML::Entities Date::Manip"
echo " " echo " "
rm output rm output
else else
DISTRO=`get_distro`
if [ "$DISTRO" == "UBUNTU" ]
then
echo "UBUNTU distribution detected"
fi
if [ "$DISTRO" == "SUSE" ]
then
echo "SUSE distribution detected"
fi
echo "Installing binaries and libraries"
make make
make install make install
mkdir /var/spool/pandora
mkdir /var/spool/pandora/data_in echo "Creating common Pandora FMS directories"
mkdir /var/spool/pandora 2> /dev/null
mkdir /var/spool/pandora/data_in 2> /dev/null
id pandora id pandora
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo " " echo " "
echo "User pandora does exist, make sure the SSH directories are correct" echo "User pandora does exist, make sure the SSH directories are correct"
else else
echo "Creating 'pandora' user"
useradd pandora useradd pandora
mkdir /home/pandora mkdir /home/pandora 2> /dev/null
mkdir /home/pandora/.ssh mkdir /home/pandora/.ssh 2> /dev/null
chown -R pandora /home/pandora chown -R pandora /home/pandora
fi fi
mkdir /var/log/pandora mkdir /var/log/pandora 2> /dev/null
chown pandora:wheel /var/spool/pandora/data_in > /dev/null 2>&1 || chown pandora:root /var/spool/pandora/data_in
chmod 770 /var/spool/pandora/data_in echo "Giving proper permission to /var/spool/pandora"
mkdir /etc/pandora if [ "$DISTRO" == "UBUNTU" ]
if [ -e /etc/pandora/pandora_server.conf ]; then then
echo "Old installation detected, backing up pandora_server.conf" chown -R pandora:www-data /var/spool/pandora/
mv /etc/pandora/pandora_server.conf /etc/pandora/pandora_server.conf.bak else
chown -R pandora:www /var/spool/pandora/
fi
echo "Creating setup directory in /etc/pandora"
mkdir /etc/pandora 2> /dev/null
if [ -e /etc/pandora/pandora_server.conf ]
then
OLDFILENAMETMP=`date +"%Y-%m-%d"`
echo "Old installation detected, backing up pandora_server.conf.$ODFILENAMETMP"
mv /etc/pandora/pandora_server.conf /etc/pandora/pandora_server.conf.$OLDFILENAMETMP
fi fi
cp conf/pandora_server.conf /etc/pandora/ cp conf/pandora_server.conf /etc/pandora/
chmod 770 /etc/pandora/pandora_server.conf chmod 770 /etc/pandora/pandora_server.conf
if [ "`uname -s`" != "Linux" ]; then
echo "This is not a Linux-based distro. The installer will not create files for automatic startup." echo "Copying the daemon script into /etc/init.d/pandora_server"
echo "Copying the binaries into /usr/local/bin"
cp pandora_server /usr/local/bin
else
echo "Copying the startup scripts into /etc/init.d and linking it to /etc/rc2.d"
cp pandora_server /etc/init.d/ cp pandora_server /etc/init.d/
if [ "$DISTRO" == "UBUNTU" ]
then
echo "Linking startup script to /etc/rc2.d"
ln -s /etc/init.d/pandora_server /etc/rc2.d/S90pandora_server ln -s /etc/init.d/pandora_server /etc/rc2.d/S90pandora_server
else
INITLV=`cat /etc/inittab | grep "[0-9]\:initdefault" | cut -f 2 -d ":"`
echo "Linking startup script to /etc/rc.d/rc$INITLV.d"
ln -s /etc/init.d/pandora_server /etc/rc.d/rc$INITLV.d/S90pandora_server
fi fi
echo "Creating links for /usr/local/bin/pandora_server"
if [ -e /usr/local/bin/pandora_server ] if [ -e /usr/local/bin/pandora_server ]
then then
ln -s /usr/local/bin/pandora_server /usr/bin/pandora_server ln -s /usr/local/bin/pandora_server /usr/bin/pandora_server 2> /dev/null
ln -s /usr/bin/pandora_server /usr/local/bin/pandora_server else
ln -s /usr/bin/pandora_server /usr/local/bin/pandora_server 2> /dev/null
fi fi
if [ "$SECOPT" != "--no-tentacle" ] if [ "$SECOPT" != "--no-tentacle" ]
then then
# Tentacle server install if [ "$DISTRO" == "UBUNTU" ]
then
# Tentacle server install (Ubuntu)
echo "Installing tentacle server in /etc/rc2.d/S80tentacle_serverd" echo "Installing tentacle server in /etc/rc2.d/S80tentacle_serverd"
cp bin/tentacle_server /usr/local/bin cp bin/tentacle_server /usr/local/bin
cp util/tentacle_serverd /etc/init.d/tentacle_serverd cp util/tentacle_serverd /etc/init.d/tentacle_serverd
ln -s /etc/init.d/tentacle_serverd /etc/rc2.d/S80tentacle_serverd ln -s /etc/init.d/tentacle_serverd /etc/rc2.d/S80tentacle_serverd
else
# Tentacle server install (SUSE)
echo "Installing tentacle server in /etc/rc.d/rc$INITLV.d/S80tentacle_serverd"
cp bin/tentacle_server /usr/local/bin
cp util/tentacle_serverd /etc/init.d/tentacle_serverd
ln -s /etc/init.d/tentacle_serverd /etc/rc.d/rc$INITLV.d/S80tentacle_serverd
fi
fi fi
mkdir /usr/share/pandora echo "Creating Pandora FMS distribution directory in /usr/share/pandora"
mkdir /usr/share/pandora 2> /dev/null
cp -R util /usr/share/pandora cp -R util /usr/share/pandora
if [ -d /etc/cron.daily ] if [ -d /etc/cron.daily ]
then then
@ -97,7 +175,7 @@ else
echo " perl /usr/share/pandora/util/pandora_db.pl /etc/pandora/pandora_server.conf" echo " perl /usr/share/pandora/util/pandora_db.pl /etc/pandora/pandora_server.conf"
fi fi
rm output rm output
fi fi
} }
@ -111,22 +189,20 @@ uninstall () {
echo "If the user Pandora is not being used for any other operations, please delete using the following commands:" echo "If the user Pandora is not being used for any other operations, please delete using the following commands:"
echo " userdel pandora" echo " userdel pandora"
echo " rm -Rf /home/pandora/" echo " rm -Rf /home/pandora/"
## Just to clarify here. Some people (like me) are using the pandora user for other purposes and/or using an LDAP-based user management
## Just to clarify here. Some people (like me) are using the pandora user
## for other purposes and/or using an LDAP-based user management
## I would hate to have a script clear out this users' information without any notification ## I would hate to have a script clear out this users' information without any notification
rm -Rf /var/log/pandora/ 2> /dev/null rm -Rf /var/log/pandora/ 2> /dev/null
rm -Rf /etc/pandora/pandora_server.conf 2> /dev/null rm -Rf /etc/pandora/pandora_server.conf 2> /dev/null
rm -Rf /etc/init.d/pandora_server 2> /dev/null rm -Rf /etc/init.d/pandora_server 2> /dev/null
rm -Rf /etc/rc2.d/S90pandora_server 2> /dev/null rm -Rf /etc/rc2.d/S90pandora_server 2> /dev/null
rm -Rf /etc/rc.d/rc3.d/S90pandora_server 2> /dev/null
rm -Rf /usr/local/bin/pandora_server 2> /dev/null rm -Rf /usr/local/bin/pandora_server 2> /dev/null
rm -Rf /usr/bin/pandora_server 2> /dev/null rm -Rf /usr/bin/pandora_server 2> /dev/null
rm -Rf /usr/share/pandora rm -Rf /usr/share/pandora
rm -Rf /etc/cron.daily/pandora_purge_db rm -Rf /etc/cron.daily/pandora_purge_db
echo "Done" echo "Done"
} }

View File

@ -23,8 +23,10 @@ TENTACLE_EXT_OPTS=""
# Sets the shell variable TENTACLE_PID to the PID of the Tentacle server (empty # Sets the shell variable TENTACLE_PID to the PID of the Tentacle server (empty
# if not running). Can be a list of PIDs if multiple instances are running. # if not running). Can be a list of PIDs if multiple instances are running.
function get_pid { function get_pid {
TENTACLE_PID=$(pidof -x $TENTACLE_DAEMON) TENTACLE_PID=`ps aux | grep $TENTACLE_PATH$TENTACLE_DAEMON | grep -v grep | tail -1 | awk '{ print $2 }'`
echo $TENTACLE_PID
} }
# Main script # Main script
@ -46,7 +48,7 @@ fi
case "$1" in case "$1" in
start) start)
get_pid TENTACLE_PID=`get_pid`
if [ ! -z "$TENTACLE_PID" ]; then if [ ! -z "$TENTACLE_PID" ]; then
echo "Tentacle server is already running with PID $TENTACLE_PID." echo "Tentacle server is already running with PID $TENTACLE_PID."
exit 1 exit 1
@ -55,7 +57,7 @@ case "$1" in
sudo -u $TENTACLE_USER ${TENTACLE_PATH}$TENTACLE_DAEMON $TENTACLE_OPTS sudo -u $TENTACLE_USER ${TENTACLE_PATH}$TENTACLE_DAEMON $TENTACLE_OPTS
sleep 1 sleep 1
get_pid TENTACLE_PID=`get_pid`
if [ ! -z "$TENTACLE_PID" ]; then if [ ! -z "$TENTACLE_PID" ]; then
echo "Tentacle server is now running with PID $TENTACLE_PID." echo "Tentacle server is now running with PID $TENTACLE_PID."
else else
@ -67,7 +69,7 @@ case "$1" in
;; ;;
stop) stop)
get_pid TENTACLE_PID=`get_pid`
if [ -z "$TENTACLE_PID" ]; then if [ -z "$TENTACLE_PID" ]; then
echo "Tentacle server does not seem to be running." echo "Tentacle server does not seem to be running."
exit 1; exit 1;
@ -93,7 +95,7 @@ case "$1" in
;; ;;
status) status)
get_pid TENTACLE_PID=`get_pid`
if [ -z "$TENTACLE_PID" ]; then if [ -z "$TENTACLE_PID" ]; then
echo "Tentacle server is not running." echo "Tentacle server is not running."
else else
@ -104,7 +106,7 @@ case "$1" in
;; ;;
*) *)
echo "Usage: $0 {start|stop|restart|status}" echo "Usage: $0 {start | stop | restart | status}"
exit 1 exit 1
;; ;;
esac esac