Skip to content
Snippets Groups Projects
Commit a7811e2a authored by Jan David Mol's avatar Jan David Mol
Browse files

SW-610: Fix getting pid in swlevel, by using a dedicated function. Works on ccu and lcu now.

parent ded9ddfb
No related branches found
No related tags found
No related merge requests found
...@@ -42,10 +42,16 @@ ETCDIR=$LOFARROOT/etc ...@@ -42,10 +42,16 @@ ETCDIR=$LOFARROOT/etc
OPERBINDIR=/opt/operations/bin OPERBINDIR=/opt/operations/bin
LEVELTABLE=${ETCDIR}/swlevel.conf LEVELTABLE=${ETCDIR}/swlevel.conf
# pidof is in /usr/sbin, usually; this is not added to PATH for non-interactive logins
# (in /etc/profile) so explicitly find location of executable pidof now. # Return the PID of a process or script
PIDOF=`whereis -b pidof | awk '{print $2}'` function getpid {
PGREP=pgrep PROGRAM="$1"
# use "pgrep -f" to get the PID of scripts.
# only use this as a fall-back when "pgrep" itself returns nothing,
# since "pgrep -f" returns false positives for non-scripts.
pgrep $PROGRAM || pgrep -f $PROGRAM
}
# Counter to indicate if 48V reset has been attempted # Counter to indicate if 48V reset has been attempted
has_been_reset=0 has_been_reset=0
...@@ -282,7 +288,7 @@ start_prog() ...@@ -282,7 +288,7 @@ start_prog()
fi fi
# Check if program is already running # Check if program is already running
$PGREP -f ${prog} 1>/dev/null 2>&1 getpid ${prog} 1>/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
curdate=`date +%Y%m%dT%H%M%S` curdate=`date +%Y%m%dT%H%M%S`
# WinCC needs special treatment # WinCC needs special treatment
...@@ -349,7 +355,7 @@ stop_prog() ...@@ -349,7 +355,7 @@ stop_prog()
fi fi
# get processlist # get processlist
$PGREP -f ${prog} 1>/dev/null 2>&1 getpid ${prog} 1>/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
return return
fi fi
...@@ -370,7 +376,7 @@ stop_prog() ...@@ -370,7 +376,7 @@ stop_prog()
fi fi
# first try normal kill # first try normal kill
for pid in `$PGREP -f ${prog}` for pid in `getpid ${prog}`
do do
echo "Softly killing ${prog}(${pid})" echo "Softly killing ${prog}(${pid})"
$asroot kill $pid 1>/dev/null 2>&1 $asroot kill $pid 1>/dev/null 2>&1
...@@ -378,7 +384,7 @@ stop_prog() ...@@ -378,7 +384,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
for pid in `$PGREP -f ${prog}` for pid in `getpid ${prog}`
do do
echo "Hard killing ${prog}(${pid})" echo "Hard killing ${prog}(${pid})"
$asroot kill -9 $pid 1>/dev/null 2>&1 $asroot kill -9 $pid 1>/dev/null 2>&1
...@@ -386,7 +392,7 @@ stop_prog() ...@@ -386,7 +392,7 @@ stop_prog()
done done
# if user0 or lofarsys, try normal kill as root # if user0 or lofarsys, try normal kill as root
for pid in `$PGREP -f ${prog}` for pid in `getpid ${prog}`
do do
if [ "$user" == "user0" -o "$user" == "lofarsys" ]; then if [ "$user" == "user0" -o "$user" == "lofarsys" ]; then
sudo kill $pid 1>/dev/null 2>&1 sudo kill $pid 1>/dev/null 2>&1
...@@ -395,7 +401,7 @@ stop_prog() ...@@ -395,7 +401,7 @@ stop_prog()
done done
# if user0 or lofarsys, try hard kill as root # if user0 or lofarsys, try hard kill as root
for pid in `$PGREP -f ${prog}` for pid in `getpid ${prog}`
do do
if [ "$user" == "user0" -o "$user" == "lofarsys" ]; then if [ "$user" == "user0" -o "$user" == "lofarsys" ]; then
sudo kill -9 $pid 1>/dev/null 2>&1 sudo kill -9 $pid 1>/dev/null 2>&1
...@@ -404,7 +410,7 @@ stop_prog() ...@@ -404,7 +410,7 @@ stop_prog()
done done
# if still alive, write a message # if still alive, write a message
for pid in `$PGREP -f ${prog}` for pid in `getpid ${prog}`
do do
echo -n "Could not kill ${prog}(${pid}); " echo -n "Could not kill ${prog}(${pid}); "
if [ "$user" == "user0" -o "$user" == "lofarsys" ]; then if [ "$user" == "user0" -o "$user" == "lofarsys" ]; then
...@@ -464,9 +470,9 @@ status_prog() ...@@ -464,9 +470,9 @@ status_prog()
# find out the processID of the possibly (running) process # find out the processID of the possibly (running) process
obsid=() obsid=()
pid_user=() pid_user=()
$PGREP -f ${prog} 1>/dev/null 2>&1 getpid ${prog} 1>/dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
pid=( `$PGREP -f ${prog}` ) pid=( `getpid ${prog}` )
i=0 i=0
for apid in ${pid[@]} for apid in ${pid[@]}
do do
......
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