From c1ca842e3e1c8cacb95a414066a969578bf263a3 Mon Sep 17 00:00:00 2001
From: slerena <slerena@gmail.com>
Date: Tue, 11 Aug 2009 16:26:09 +0000
Subject: [PATCH] 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
---
 pandora_server/ChangeLog                      |  22 +-
 pandora_server/Makefile.PL                    |  11 +-
 pandora_server/bin/pandora_server             |  18 +-
 pandora_server/lib/PandoraFMS/Config.pm       |   2 +-
 .../lib/PandoraFMS/NetworkServer.pm           |   1 -
 pandora_server/pandora_server                 |  91 ++++---
 pandora_server/pandora_server_installer       | 256 ++++++++++++------
 pandora_server/util/tentacle_serverd          |  30 +-
 8 files changed, 280 insertions(+), 151 deletions(-)

diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog
index fcad410138..2dcc61f5a6 100644
--- a/pandora_server/ChangeLog
+++ b/pandora_server/ChangeLog
@@ -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.
 
diff --git a/pandora_server/Makefile.PL b/pandora_server/Makefile.PL
index b9cc906c9b..61c14e02f2 100644
--- a/pandora_server/Makefile.PL
+++ b/pandora_server/Makefile.PL
@@ -4,17 +4,16 @@ use ExtUtils::MakeMaker;
 WriteMakefile(
 	NAME            => 'PandoraFMS',
 	VERSION_FROM    => 'lib/PandoraFMS/Config.pm',
-	AUTHOR 		=> 'Sancho Lerena <slerena@artica.es>',
+	AUTHOR 		=> 'Artica ST <info@artica.es>',
 	PREREQ_PM 	=> {
 		NetAddr::IP => 0,
 		DBI => 0,
-                threads::shared => 0,
-                IO::Socket => 0,
+		threads::shared => 0,
+		IO::Socket => 0,
 		Time::Format => 0,
-                Time::Local => 0,
-                Date::Manip => 0,
+		Time::Local => 0,
+		Date::Manip => 0,
 		XML::Simple => 0,
-		Net::Ping => 0,
 		Time::HiRes => 0,
 		IO::Socket => 0,
 		Mail::Sendmail => 0,
diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server
index cccfc19ad0..93523aec56 100755
--- a/pandora_server/bin/pandora_server
+++ b/pandora_server/bin/pandora_server
@@ -42,7 +42,7 @@ my @Servers;
 my $DBH;
 
 ########################################################################################
-# Server shutdown
+# Server shutdown.  Handler to do a controlled shutdown.
 ########################################################################################
 sub pandora_shutdown () {
 	logger (\%Config, 'Pandora FMS Server \'' . $Config{'servername'} . '\' Shutdown by signal ', 0);
@@ -57,8 +57,24 @@ sub pandora_shutdown () {
 	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{'INT'} = 'pandora_shutdown';
+$SIG{__DIE__} = 'pandora_crash';
 
 # Prevent alarm from bombing the main thread when called within a thread
 $SIG{'ALRM'} = 'IGNORE';
diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm
index fde4e1cb11..65bf696dc3 100644
--- a/pandora_server/lib/PandoraFMS/Config.pm
+++ b/pandora_server/lib/PandoraFMS/Config.pm
@@ -37,7 +37,7 @@ our @EXPORT = qw(
 
 # version: Defines actual version of Pandora Server for this module only
 my $pandora_version = "3.0-dev";
-my $pandora_build = "PS090310";
+my $pandora_build = "PS090810";
 our $VERSION = $pandora_version." ".$pandora_build;
 
 # Setup hash
diff --git a/pandora_server/lib/PandoraFMS/NetworkServer.pm b/pandora_server/lib/PandoraFMS/NetworkServer.pm
index ce2f50eb89..b562ddbc98 100644
--- a/pandora_server/lib/PandoraFMS/NetworkServer.pm
+++ b/pandora_server/lib/PandoraFMS/NetworkServer.pm
@@ -25,7 +25,6 @@ use threads::shared;
 use Thread::Semaphore;
 
 use IO::Socket::INET;
-use Net::Ping;
 use POSIX qw(strftime);
 
 use PandoraFMS::Tools;
diff --git a/pandora_server/pandora_server b/pandora_server/pandora_server
index 38d96d1305..87c6b826bf 100755
--- a/pandora_server/pandora_server
+++ b/pandora_server/pandora_server
@@ -1,19 +1,29 @@
 #!/bin/bash
 
 # Pandora FMS Server, startup script
-# Copyright (c) 2006-2008 Sancho Lerena, <slerena@gmail.com>
-# Linux Version (generic)
-# v2.1 Build 081030
+# Copyright (c) 2006-2009 Sancho Lerena, <sancho.lerena@artica.es>
+# Linux Version (generic), for SuSe and Debian/Ubuntu.
+# other Linux distros could not work properly without modifications
+# v3.0 Build 090810
 # http://www.pandorafms.com
 # chkconfig: 23 99 99
 # description: Manages starting/stopping of server
 
 # Configurable path and filenames
+
 PANDORA_HOME="/etc/pandora/pandora_server.conf"
 PANDORA_PID_PATH="/var/run"
 PANDORA_PID=$PANDORA_PID_PATH/pandora_server.pid
 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
 
 if [ ! -d "$PANDORA_PID_PATH" ]
@@ -29,48 +39,55 @@ then
 fi
 
 case "$1" in
-  start)
-	OLD_PATH="`pwd`"
-	PANDORA_PID=$(pidof -x $PANDORA_DAEMON)
-	if [ ! -z $PANDORA_PID ]
-	then
-		echo "Pandora FMS Server is currently running on this machine with PID ($PANDORA_PID). Aborting now..."
-		exit 1	
-	else
-	rm -f $PANDORA_PID
-	fi
+	start)
+		PANDORA_PID=`pidof_pandora`
+		if [ ! -z "$PANDORA_PID" ]
+		then
+			echo "Pandora FMS Server is currently running on this machine with PID ($PANDORA_PID). Aborting now..."
+			exit 1
+		fi
 	
-	$PANDORA_DAEMON $PANDORA_HOME -D
-	sleep 1
+		$PANDORA_DAEMON $PANDORA_HOME -D
+		sleep 2
 
-	PANDORA_PID=$(pidof -x $PANDORA_DAEMON)
-	if [ ! -z "$PANDORA_PID" ]
-	then
-		echo "Pandora Server is now running with PID $PANDORA_PID"
-	else
-		echo "Cannot start Pandora FMS Server. Aborted."
-	fi
-	cd "$OLD_PATH"
-		;;
-  stop)
-	PANDORA_PID=$(pidof -x $PANDORA_DAEMON)
-	if [ -z $PANDORA_PID ]
-	then
-		echo "Pandora FMS Server is not running, cannot stop it."
-		exit 1
-	else
-		echo "Stopping Pandora FMS Server"
+		PANDORA_PID=`pidof_pandora`
+		if [ ! -z "$PANDORA_PID" ]
+		then
+			echo "Pandora Server is now running with PID $PANDORA_PID"
+		else
+			echo "Cannot start Pandora FMS Server. Aborted."
+			echo "Check Pandora FMS log files at '/var/log/pandora/pandora_server.log'"
+		fi
+	;;
+		
+	stop)
+		PANDORA_PID=`pidof_pandora`
+		if [ -z "$PANDORA_PID" ]
+		then
+			echo "Pandora FMS Server is not running, cannot stop it."
+			exit 1
+		else
+			echo "Stopping Pandora FMS Server"
 			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)
 		$0 stop
-		sleep 2
+		sleep 3
 		$0 start
 		;;
   *)
-		echo "Usage: pandora_server {start|stop|restart}"
+		echo "Usage: pandora_server { start | stop | restart | status }"
 		exit 1
 esac
 
diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer
index 9bf565b3b8..919729b389 100755
--- a/pandora_server/pandora_server_installer
+++ b/pandora_server/pandora_server_installer
@@ -1,103 +1,181 @@
-# 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
+# v3.0 Build 090810
 # This code is licensed under GPL 2.0 license.
 # **********************************************************************
 
-#!/bin/bash
-
 MODE=$1
 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 () {
 
-perl Makefile.PL > output 2>&1  #&& sleep 2 &&  cat output | grep "found" | wc -l 
-
-DEPENDENCIAS=`cat output | grep "found" | wc -l`
-
-if [ $DEPENDENCIAS -gt 0 ]
-then
-
-	echo "You are missing the following dependencies"
-	echo " "
-	cat output | awk -F ": prerequisite" '{print $2}' | awk -F " " '{print $1}'
-	echo "The complete installation guide is at: "http://www.openideas.info/wiki/index.php?title=Pandora_2.0:Documentation_en:Install_Server#Pandora_FMS_Server_installation" "
-	echo " "
-	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 " "
-	echo "RedHat-based distribution do"
-	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 " "
-	echo "To get it from source through CPAN do"
-	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 " "
-	rm output
-else
-	make
-	make install
-	mkdir /var/spool/pandora
-	mkdir /var/spool/pandora/data_in
-	id pandora
-	if [ $? -eq 0 ]; then
+	perl Makefile.PL > output 2>&1  #&& sleep 2 &&  cat output | grep "found" | wc -l 
+	DEPENDENCIAS=`cat output | grep "found" | wc -l`
+	if [ $DEPENDENCIAS -gt 0 ]
+	then
+		echo "You are missing the following dependencies"
 		echo " "
-		echo "User pandora does exist, make sure the SSH directories are correct"
+		cat output | awk -F ": prerequisite" '{print $2}' | awk -F " " '{print $1}'
+		echo "The complete installation guide is at: "http://www.openideas.info/wiki/index.php?title=Pandora_2.0:Documentation_en:Install_Server#Pandora_FMS_Server_installation" "
+		echo " "
+		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 " "
+		echo "RPM distribution do"
+		echo " "
+		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 "To get it from source through CPAN do"
+		echo " "
+		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 " "
+		rm output
 	else
-		useradd pandora
-		mkdir /home/pandora
-		mkdir /home/pandora/.ssh
-		chown -R pandora /home/pandora
-	fi
-	mkdir /var/log/pandora
-	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
-	mkdir /etc/pandora
-	if [ -e /etc/pandora/pandora_server.conf ]; then
-		echo "Old installation detected, backing up pandora_server.conf"
-		mv /etc/pandora/pandora_server.conf /etc/pandora/pandora_server.conf.bak
-	fi
-	cp conf/pandora_server.conf /etc/pandora/
-	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 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/
-		ln -s /etc/init.d/pandora_server /etc/rc2.d/S90pandora_server
-	fi
+	
+		DISTRO=`get_distro`
+		
+		if [ "$DISTRO" == "UBUNTU" ]
+		then
+			echo "UBUNTU distribution detected"
+		fi
 
-	if [ -e /usr/local/bin/pandora_server ]
-	then
-		ln -s /usr/local/bin/pandora_server /usr/bin/pandora_server
-		ln -s /usr/bin/pandora_server /usr/local/bin/pandora_server
-	fi
+		if [ "$DISTRO" == "SUSE" ]
+		then
+			echo "SUSE distribution detected"
+		fi
+		
+		echo "Installing binaries and libraries"
+		make
+		make install
+		
+		echo "Creating common Pandora FMS directories"
+		mkdir /var/spool/pandora 2> /dev/null
+		mkdir /var/spool/pandora/data_in 2> /dev/null
+		id pandora
+		if [ $? -eq 0 ]; then
+			echo " "
+			echo "User pandora does exist, make sure the SSH directories are correct"
+		else
+			echo "Creating 'pandora' user"
+			useradd pandora 
+			mkdir /home/pandora 2> /dev/null
+			mkdir /home/pandora/.ssh 2> /dev/null
+			chown -R pandora /home/pandora 
+		fi
+		mkdir /var/log/pandora 2> /dev/null
+		
+		echo "Giving proper permission to /var/spool/pandora"
+		if [ "$DISTRO" == "UBUNTU" ]
+		then
+			chown -R pandora:www-data /var/spool/pandora/ 
+		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
+		cp conf/pandora_server.conf /etc/pandora/
+		chmod 770 /etc/pandora/pandora_server.conf
+		
+		echo "Copying the daemon script into /etc/init.d/pandora_server"
+		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
+		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
 
+		echo "Creating links for /usr/local/bin/pandora_server"
+		if [ -e /usr/local/bin/pandora_server ]
+		then
+			ln -s /usr/local/bin/pandora_server /usr/bin/pandora_server 2> /dev/null
+		else
+			ln -s /usr/bin/pandora_server /usr/local/bin/pandora_server 2> /dev/null
+		fi
 
-	if [ "$SECOPT" != "--no-tentacle" ]
-	then
-		# Tentacle server install
-		echo "Installing tentacle server in /etc/rc2.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/rc2.d/S80tentacle_serverd
-	fi
+		if [ "$SECOPT" != "--no-tentacle" ]
+		then
+			if [ "$DISTRO" == "UBUNTU" ]
+			then
+				# Tentacle server install (Ubuntu)
+				echo "Installing tentacle server in /etc/rc2.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/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
 
-	mkdir /usr/share/pandora
-	cp -R util /usr/share/pandora
-	if [ -d /etc/cron.daily ]
-	then
-		echo "#!/bin/bash" > /etc/cron.daily/pandora_purge_db	
-		echo "perl /usr/share/pandora/util/pandora_db.pl /etc/pandora/pandora_server.conf" >> /etc/cron.daily/pandora_purge_db	
-		chmod +x /etc/cron.daily/pandora_purge_db
-	else
-		echo "You're probably not using cron for automatic scheduling. You should schedule the following command to run frequently (daily) on your master server:"
-		echo "   perl /usr/share/pandora/util/pandora_db.pl /etc/pandora/pandora_server.conf"
+		echo "Creating Pandora FMS distribution directory in /usr/share/pandora"
+		mkdir /usr/share/pandora 2> /dev/null
+		cp -R util /usr/share/pandora
+		if [ -d /etc/cron.daily ]
+		then
+			echo "#!/bin/bash" > /etc/cron.daily/pandora_purge_db	
+			echo "perl /usr/share/pandora/util/pandora_db.pl /etc/pandora/pandora_server.conf" >> /etc/cron.daily/pandora_purge_db	
+			chmod +x /etc/cron.daily/pandora_purge_db
+		else
+			echo "You're probably not using cron for automatic scheduling. You should schedule the following command to run frequently (daily) on your master server:"
+			echo "   perl /usr/share/pandora/util/pandora_db.pl /etc/pandora/pandora_server.conf"
+		fi
+		rm output
 	fi
-	rm output
-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 "   userdel 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
 
 	rm -Rf /var/log/pandora/  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/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/bin/pandora_server 2> /dev/null
-
 	rm -Rf /usr/share/pandora
 	rm -Rf /etc/cron.daily/pandora_purge_db
-
 	echo "Done"
 }
 
diff --git a/pandora_server/util/tentacle_serverd b/pandora_server/util/tentacle_serverd
index 6a87a09a94..567592811c 100755
--- a/pandora_server/util/tentacle_serverd
+++ b/pandora_server/util/tentacle_serverd
@@ -23,8 +23,10 @@ TENTACLE_EXT_OPTS=""
 
 # 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.
+
 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
@@ -40,13 +42,13 @@ case "$TENTACLE_PATH" in
 esac
 
 if [ ! -f "${TENTACLE_PATH}$TENTACLE_DAEMON" ]; then
-        echo "Tentacle server not found in ${TENTACLE_PATH}$TENTACLE_DAEMON."
-        exit 1
+	echo "Tentacle server not found in ${TENTACLE_PATH}$TENTACLE_DAEMON."
+	exit 1
 fi
 
 case "$1" in
-  	start)
-		get_pid
+	start)
+		TENTACLE_PID=`get_pid`
 		if [ ! -z "$TENTACLE_PID" ]; then
 			echo "Tentacle server is already running with PID $TENTACLE_PID."
 			exit 1
@@ -55,7 +57,7 @@ case "$1" in
 		sudo -u $TENTACLE_USER ${TENTACLE_PATH}$TENTACLE_DAEMON $TENTACLE_OPTS
 		sleep 1
 
-		get_pid
+		TENTACLE_PID=`get_pid`
 		if [ ! -z "$TENTACLE_PID" ]; then
 			echo "Tentacle server is now running with PID $TENTACLE_PID."
 		else
@@ -64,10 +66,10 @@ case "$1" in
 		fi
 
 		exit 0
-        ;;
+	;;
 	
 	stop)
-		get_pid
+		TENTACLE_PID=`get_pid`
 		if [ -z "$TENTACLE_PID" ]; then
 			echo "Tentacle server does not seem to be running."
 			exit 1;
@@ -88,12 +90,12 @@ case "$1" in
 	;;
 
 	force-reload|restart)
-        	$0 stop
-	        $0 start
-        ;;
+		$0 stop
+		$0 start
+	;;
 
 	status)
-		get_pid
+		TENTACLE_PID=`get_pid`
 		if [ -z "$TENTACLE_PID" ]; then
 			echo "Tentacle server is not running."
 		else
@@ -101,10 +103,10 @@ case "$1" in
 		fi
 		
 		exit 0
-        ;;
+	;;
 
 	*)
- 		echo "Usage: $0 {start|stop|restart|status}"
+		echo "Usage: $0  {start | stop | restart | status}"
 		exit 1
 	;;
 esac