Skip to content
Snippets Groups Projects
Commit f953996e authored by Ruud Overeem's avatar Ruud Overeem
Browse files

Bug 1000: More secure matching

parent fd534aa7
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
# #
# $Id$ # $Id$
# #
VERSION="v1.0" VERSION="v1.4 20071017" # added possibility for custom scripts
BINDIR=/opt/lofar/bin BINDIR=/opt/lofar/bin
LOGDIR=/opt/lofar/log LOGDIR=/opt/lofar/log
LEVELTABLE=${BINDIR}/../etc/swlevel.conf LEVELTABLE=${BINDIR}/../etc/swlevel.conf
...@@ -57,15 +57,22 @@ start_prog() ...@@ -57,15 +57,22 @@ start_prog()
{ {
# make arguments readable # make arguments readable
prog=$1 prog=$1
asroot=$2 asroot=${2:1}
withmpi=${3:1}
# check existance # check existance
[ -x $BINDIR/$prog ] || return [ -x $BINDIR/$prog ] || [ -x $BINDIR/${prog}.sh ] || return
# if it is a shell script call the script
if [ -f $BINDIR/${prog}.sh ]; then
$BINDIR/${prog}.sh start
return
fi
ps -ef | grep -v grep | grep $prog 2>&1 >/dev/null ps -ef | grep -v grep | grep -v ${prog}[^\ ] | grep $prog 2>&1 >/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
# program is running, show it # program is running, show it
ps -ef | grep -v grep | grep $prog ps -ef | grep -v grep | grep -v ${prog}[^\ ] | grep $prog
else else
echo Starting $prog echo Starting $prog
# PVSS needs special treatment # PVSS needs special treatment
...@@ -87,7 +94,7 @@ start_prog() ...@@ -87,7 +94,7 @@ start_prog()
fi fi
sleep 1 sleep 1
fi fi
ps -ef | grep -v grep | grep $prog ps -ef | grep -v grep | grep -v ${prog}[^\ ] | grep $prog
fi fi
} }
...@@ -98,13 +105,21 @@ stop_prog() ...@@ -98,13 +105,21 @@ stop_prog()
{ {
# make arguments readable # make arguments readable
prog=$1 prog=$1
asroot=$2 asroot=${2:1}
withmpi=${3:1}
[ ! -z "$asroot" ] && asroot=sudo [ ! -z "$asroot" ] && asroot=sudo
# check existance # check existance
[ -x $BINDIR/$prog ] || return [ -x $BINDIR/$prog ] || [ -x $BINDIR/${prog}.sh ] || return
# if it is a shell script call the script
if [ -f $BINDIR/${prog}.sh ]; then
$BINDIR/${prog}.sh stop
return
fi
ps -ef | grep -v grep | grep $prog 2>&1 >/dev/null # get processlist
ps -ef | grep -v grep | grep -v ${prog}[^\ ] | grep $prog 2>&1 >/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
return return
fi fi
...@@ -116,8 +131,14 @@ stop_prog() ...@@ -116,8 +131,14 @@ stop_prog()
return return
fi fi
# first handle mpi programs
if [ ! -z "$withmpi" ]; then
$asroot cexec :0-11 killall -9 ${prog}
return
fi
# first try normal kill # first try normal kill
ps -ef | grep -v grep | grep $prog | awk '{ print $2 }' | while read pid ps -ef | grep -v grep | grep -v ${prog}[^\ ] | grep $prog | awk '{ print $2 }' | while read pid
do do
echo "Softly killing ${prog}(${pid})" echo "Softly killing ${prog}(${pid})"
$asroot kill $pid $asroot kill $pid
...@@ -125,7 +146,7 @@ stop_prog() ...@@ -125,7 +146,7 @@ stop_prog()
done done
# when normal kill did not work, kill is with -9 # when normal kill did not work, kill is with -9
ps -ef | grep -v grep | grep $prog | awk '{ print $2 }' | while read pid ps -ef | grep -v grep | grep -v ${prog}[^\ ] | grep $prog | awk '{ print $2 }' | while read pid
do do
sleep 2 sleep 2
echo "Hard killing ${prog}(${pid})" echo "Hard killing ${prog}(${pid})"
...@@ -145,19 +166,31 @@ status_prog() ...@@ -145,19 +166,31 @@ status_prog()
cat $LEVELTABLE | cut -d"#" -f1 | awk '{ if (NF>0) print $0 }' | while read line cat $LEVELTABLE | cut -d"#" -f1 | awk '{ if (NF>0) print $0 }' | while read line
do do
levelnr=`echo $line | cut -d":" -f1` levelnr=`echo $line | cut -d":" -f1`
prog=`echo $line | cut -d":" -f5` prog=`echo $line | cut -d":" -f6`
# check existance # check existance
[ -x $BINDIR/$prog ] || continue [ -x $BINDIR/$prog ] || [ -x $BINDIR/${prog}.sh ] || continue
if [ $prevlevel -ne $levelnr ]; then if [ $prevlevel -ne $levelnr ]; then
echo "---" echo "---"
prevlevel=$levelnr prevlevel=$levelnr
fi fi
ps -ef | grep -v grep | grep $prog 2>&1 >/dev/null
# if it is a shell script call the script
if [ -f $BINDIR/${prog}.sh ]; then
$BINDIR/${prog}.sh status $levelnr
continue
fi
ps -ef | grep -v grep | grep -v ${prog}[^\ ] | grep ${prog} 2>&1 >/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
# program is running, show it # program is running, show it
pid=`ps -ef | grep -v grep | grep $prog | awk '{ print $2 }'` # pid=""
# ps -ef | grep -v grep | grep -v ${prog}[^\ ] | grep ${prog} | awk '{ print $2 }' | while read somepid
# do
# pid=${pid}" "${somepid}
# done
pid=`ps -ef | grep -v grep | grep -v ${prog}[^\ ] | grep ${prog} | awk '{ print $2 }'`
else else
pid="DOWN" pid="DOWN"
fi fi
...@@ -178,8 +211,9 @@ goto_level() ...@@ -178,8 +211,9 @@ goto_level()
grep "^${l}:" | grep ":d:" | while read line grep "^${l}:" | grep ":d:" | while read line
do do
asroot=`echo $line | cut -d":" -f4` asroot=`echo $line | cut -d":" -f4`
program=`echo $line | cut -d":" -f5` withmpi=`echo $line | cut -d":" -f5`
stop_prog $program $asroot program=`echo $line | cut -d":" -f6`
stop_prog $program x$asroot x$withmpi
done done
done done
...@@ -190,8 +224,9 @@ goto_level() ...@@ -190,8 +224,9 @@ goto_level()
grep "^${l}:" | grep ":u:" | while read line grep "^${l}:" | grep ":u:" | while read line
do do
asroot=`echo $line | cut -d":" -f4` asroot=`echo $line | cut -d":" -f4`
program=`echo $line | cut -d":" -f5` withmpi=`echo $line | cut -d":" -f5`
start_prog $program $asroot program=`echo $line | cut -d":" -f6`
start_prog $program x$asroot x$withmpi
done done
done done
} }
......
...@@ -2,21 +2,23 @@ ...@@ -2,21 +2,23 @@
# swlevel.conf # swlevel.conf
# #
# Table to manage the progrma that should be started and stopped # Table to manage the progrma that should be started and stopped
# level : up : down : root : program # level : up : down : root : mpi : program
# #
1:u:d::ServiceBroker 1:u:d:::ServiceBroker
1:u:d::CTStartDaemon 1:u:d:::CTStartDaemon
2:u:d:r:EPAStub 2:u:d:r::EPAStub
2:u:d:r:RSPDriver 2:u:d:r::RSPDriver
3:u:d::PVSS00pmon 3:u:d:r::TBBDriver
3:u:d::CodeLoggingProcessor 4:u:d:::PVSS00pmon
4:u:d::HardwareMonitor 4:u:d:::LoggingProcessor
5:u:d::amcserver 4:u:d:::HardwareMonitor
5:u:d::CalServer 5:u:d:::amcserver
5:u:d::BeamServer 5:u:d:::CalServer
6:u:d::MACScheduler 5:u:d:::BeamServer
6::d::ObservationControl 5:u:d:::MACInformationServer
6::d::StationControl 6:u:d:::MACScheduler
6::d::DigitalBoardControl 6::d:::ObservationControl
6::d::CalibrationControl 6::d:::StationControl
6::d::BeamControl 6::d:::DigitalBoardControl
6::d:::CalibrationControl
6::d:::BeamControl
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment