Welcome to Pandora FMS Community › Forums › Community support › 2 instances of the server are launched when starting service
-
2 instances of the server are launched when starting service
Posted by daggett on November 29, 2006 at 12:48Hi all,
first, I have replaced this in pandora_server.pl running on a Linux Mandriva2007:
use threads;
use threads::shared;by this:
use forks;
use forks::shared;Each time I’m starting the pandora server ($ pandora_server start) it starts two instances of the server… is it ok?
If it is, then the agent collecting information about pandora_server must be modified, because the ps aux | grep pandora_server.pl returns 2 lines, and then is returning wrong data.If I stop the server (pandora_server stop), the second instance of the server is marked as
and the first intance is still active (it is still processing data).
So the stop parameter is uneffective, it just creates a zombie and is not stopping the other instance.
An other try of the pandora_server stop tells me:
Pandora Data Server is not running, cannot stop it.
But, there are 2 processes running… (zombie + active server).how can I fix it?
I will try to do it myself, but if anyone can help me.
thanks,
byedaggett replied 18 years, 2 months ago 1 Member · 3 Replies -
3 Replies
-
::
some more informations:
ps -A|grep pandora_server
nothing returns: pandora server is not running, OK.
pandora_server start
Pandora Server 1.2 Beta 3 Build PS060929 Copyright (c) 2004-2006 ArticaST
This program is Free Software, licensed under the terms of GPL License v2 or later.
You can download latest versions and documentation at http://pandora.sourceforge.net.[W] It is not a good idea running Pandora Server as root user, please DON’T DO IT!
- Server basepath is /opt/pandora/pandora_server
- Server logfile at /opt/pandora/pandora_server/log/pandora_server.log
- Server errorlogfile at /opt/pandora/pandora_server/log/pandora_server.error
- Server incoming directory at /opt/pandora/pandora_server/data_in
- Server keepalive 60
- Server threshold 10
- You are running Pandora Data Server.
- This server is running in MASTER mode.
Pandora Data Server is now running with PID 15637
I run it as root, because it’s conveniant for me at that time.
then:
ps -A|grep pandora_server
15636 ? 00:00:00 pandora_server.
15637 ? 00:00:00 pandora_server.cat var/pandora_server.pid
15637/opt/pandora/pandora_server/pandora_server stop
Stopping Pandora Data Serverps -A|grep pandora_server
15636 ? 00:00:00 pandora_server.
15637 ? 00:00:00 pandora_server.and I must kill the FIRST instance (15636) to make it stop running.
So, my fix will be:
in the start/stop sh script (pandora_server), line 30 replace tail -1 by head -1.
So now the first process ID is in the .pid file, and the stop parameter kills the right process and the server is then stopped.But may be useful to check something else than the .pid file to ensure that the server is running or not, for that reason:
with the original start/stop script, when I’m starting the server it creates 2 processes, memorises the PID of the second in the .pid file. good.
when I try to stop the server with the original script, it checks the .pid file, and try to kill the process whiwh PID was in the .pid file. then it doesn’t check if it is still running or not, and issues a message indicating that server is stopped, and deletes the .pid file…
And then if I start the server again with the original script, the .pid file doesn’t exist, so it launches the server, creating 2 more instances… and never verifies how many processes are running or zombie, etc…So, I will try to fix this
bye for now -
::
Well, all is fixed:
I modified the pandora_server sh script, I can’t attach files to this post, so I simply post it there:
[code:1]#!/bin/sh
# Pandora Data Server startup script
# Sancho Lerena,
# Linux Version (generic)
# v1.2 (Ene/2006)# Configurable path and filenames
PANDORA_HOME=”/opt/pandora/pandora_server”
PANDORA_SERVER_PID=”$PANDORA_HOME/var/pandora_server.pid”# Main script
if [ ! -f $PANDORA_HOME/bin/pandora_server.pl ]
then
echo “Pandora Data Server not found, please check setup and read manual”
exit
ficase “$1″ in
start)
OLD_PATH=”`pwd`”
if [ -f $PANDORA_SERVER_PID ]
then
echo “Pandora Data Server is currently running on this machine. Aborting now…”
exit
fi
# we change to the pandora server bin directory
cd $PANDORA_HOME/bin
./pandora_server.pl $PANDORA_HOME -D
# the server may take some time to start, so we need to pause before collecting PIDs
sleep 2
# collecting first line (first PID with head -1) then the second (tail -1). It doesn’t matter if MYPID==MYPID2
MYPID=`ps aux | grep ‘pandora_server.pl’ | grep -v grep | head -1 | awk ‘{print $2}’`
MYPID2=`ps aux | grep ‘pandora_server.pl’ | grep -v grep | tail -1 | awk ‘{print $2}’`
if [ ! -z “$MYPID” ]
then
# there is at least one PID, so server is running, so put PID in the .pid file and create this file
echo $MYPID > $PANDORA_SERVER_PID
echo $MYPID2 >> $PANDORA_SERVER_PID
echo “Pandora Data Server is now running with PID $MYPID and $MYPID2”
else
# no PID collected, the server is not running
echo “Cannot start Pandora Data Server. Aborted”
fi
cd “$OLD_PATH”
;;
stop)
if [ -f $PANDORA_SERVER_PID ]
then
echo “Stopping Pandora Data Server”
# fetching PID from the .pid file it doesn’t matter if PID_1==PID_2
PID_1=`cat $PANDORA_SERVER_PID | head -1`
PID_2=`cat $PANDORA_SERVER_PID | tail -1`
# we check if PID_1 and PID_2 are still existing, if yes then we kill them
PIDS=`ps -F -p $PID_1 $PID_2 | grep -v grep | grep ‘pandora_server.pl’| awk ‘{print $2}’`
if [ ! -z “$PIDS” ]
then
kill $PIDS 2> /dev/null > /dev/null
fi
echo “Stopping PID: ” $PIDS
# we check if our PIDs were killed or not, we grep pandora_server. because of zombies loosing their “pl”
PIDS=`ps -F -p $PID_1 $PID_2 | grep -v grep | grep ‘pandora_server.’| awk ‘{print $2}’`
if [ ! -z “$PIDS”]
then
echo “Following PID didn’t stop, sending signal 9 to ” $PIDS
kill -9 $PIDS 2> /dev/null > /dev/null
fi
rm -f $PANDORA_SERVER_PID
echo Server Stopped
else
echo “Pandora Data Server is not running, cannot stop it.”
fi
;;
force-reload|restart)
$0 stop
$0 start
;;
*)
echo “Usage: pandora_network {start|stop|restart}”
exit 1
esacLet me know what you think of it, I added some comments in it to make it easier to comprehend for everyone.
thanks,
bye -
::
Hi,
I did get some problems when agressively testing it (ie killing one process then removing .pid file then tsarting it again then stopping… etc)
this script is only a start/stop script, so it makes some verifications but I decided that it would only issue warnings and comments if something tricky happends.Let me know your comments and feel free to give your advice/remarks/anything…
[code:1]#!/bin/sh
# Pandora Data Server startup script
# Sancho Lerena,
# Linux Version (generic)
# v1.2 (Ene/2006)# Configurable path and filenames
PANDORA_HOME=”/opt/pandora/pandora_server”
PANDORA_SERVER_PID=”$PANDORA_HOME/var/pandora_server.pid”# Main script
if [ ! -f $PANDORA_HOME/bin/pandora_server.pl ]
then
echo “Pandora Data Server not found, please check setup and read manual”
exit
ficase “$1″ in
start)
OLD_PATH=”`pwd`”
if [ -f $PANDORA_SERVER_PID ]
then
echo “Pandora Data Server is currently running on this machine. Aborting now…”
exit
fi
# we check if we have pinstances of the server already running
NUMPID=`ps aux | grep ‘pandora_server.pl’ | grep -v grep | wc -l`
if [ $NUMPID -gt 0 ]
then
echo Warning! It seems that there are some instances of pandora server already running
echo Starting anyway… but you may have some problems.
fi
# we change to the pandora server bin directory
cd $PANDORA_HOME/bin
./pandora_server.pl $PANDORA_HOME -D
# the server may take some time to start, so we need to pause before collecting PIDs
sleep 2
# collecting first line (first PID with head -1) then the second (tail -1). It doesn’t matter if MYPID==MYPID2
MYPID=`ps aux | grep ‘pandora_server.pl’ | grep -v grep | tail -2 | head -1 | awk ‘{print $2}’`
MYPID2=`ps aux | grep ‘pandora_server.pl’ | grep -v grep | tail -1 | awk ‘{print $2}’`
if [ ! -z “$MYPID” ]
then
# there is at least one PID, so server is running, so put PID in the .pid file and create this file
echo $MYPID > $PANDORA_SERVER_PID
echo $MYPID2 >> $PANDORA_SERVER_PID
echo “Pandora Data Server is now running with PID $MYPID and $MYPID2”
else
# no PID collected, the server is not running
echo “Cannot start Pandora Data Server. Aborted”
fi
cd “$OLD_PATH”
;;
stop)
if [ -f $PANDORA_SERVER_PID ]
then
echo “Stopping Pandora Data Server”
# fetching PID from the .pid file it doesn’t matter if PID_1==PID_2
PID_1=`cat $PANDORA_SERVER_PID | head -1`
PID_2=`cat $PANDORA_SERVER_PID | tail -1`
# we check if PID_1 and PID_2 are still existing, if yes then we kill them
PIDS=`ps -F -p $PID_1 $PID_2 | grep -v grep | grep ‘pandora_server.pl’| awk ‘{print $2}’`
if [ ! -z “$PIDS” ]
then
kill $PIDS 2> /dev/null > /dev/null
fi
echo “Stopping PID: ” $PIDS
# we check if our PIDs were killed or not, we grep pandora_server. because of zombies loosing their “pl”
PIDS=`ps -F -p $PID_1 $PID_2 | grep -v grep | grep ‘pandora_server.’| awk ‘{print $2}’`
if [ ! -z “$PIDS”]
then
echo “Following PID didn’t stop, sending signal 9 to ” $PIDS
kill -9 $PIDS 2> /dev/null > /dev/null
fi
rm -f $PANDORA_SERVER_PID
echo Server Stopped
else
echo “Pandora Data Server is not running, cannot stop it.”
fi
;;
force-reload|restart)
$0 stop
$0 start
;;
*)
echo “Usage: pandora_network {start|stop|restart}”
exit 1
esac
this is for me the final version, even if it issues an sh error when trying to stop the server from this section
if [ ! -z “$PIDS”]
then
echo “Following PID didn’t stop, sending signal 9 to ” $PIDS
kill -9 $PIDS 2> /dev/null > /dev/null
fi
it says /opt/pandora/pandora_server/pandora_server: line 91: [: missing `]’
This happends when there are multiple instances of the pandora server plus some zombies of pandora server.well, it’s not happening if all is done properly (starting/stopping with the script).
bye