Added improvements regarding multi-user environments as reported by cinly.ooi

This commit is contained in:
Louwrentius 2009-08-09 15:49:58 +00:00
parent 64486cb710
commit 04847e14db

46
ppss.sh
View File

@ -38,7 +38,7 @@ trap 'kill_process; ' INT
# Setting some vars. Do not change. # Setting some vars. Do not change.
SCRIPT_NAME="Distributed Parallel Processing Shell Script" SCRIPT_NAME="Distributed Parallel Processing Shell Script"
SCRIPT_VERSION="2.19" SCRIPT_VERSION="2.20"
# The first argument to this script is always the 'mode'. # The first argument to this script is always the 'mode'.
MODE="$1" MODE="$1"
@ -126,7 +126,7 @@ showusage () {
echo -e "--sourcefile | -f Each single line of the supplied file will be fed as an item to the" echo -e "--sourcefile | -f Each single line of the supplied file will be fed as an item to the"
echo -e " command that has been specified with -c." echo -e " command that has been specified with -c."
echo echo
echo -e "--config | -c If the mode is config, a config file with the specified name will be" echo -e "--config | -C If the mode is config, a config file with the specified name will be"
echo -e " generated based on all the options specified. In the other modes". echo -e " generated based on all the options specified. In the other modes".
echo -e " this option will result in PPSS reading the config file and start" echo -e " this option will result in PPSS reading the config file and start"
echo -e " processing items based on the settings of this file." echo -e " processing items based on the settings of this file."
@ -190,10 +190,10 @@ kill_process () {
kill $LISTENER_PID >> /dev/null 2>&1 kill $LISTENER_PID >> /dev/null 2>&1
while true while true
do do
JOBS=`ps ax | grep -v grep | grep -v -i screen | grep ppss.sh | grep -i bash | wc -l` JOBS=`ps aux | grep $USER | grep -v grep | grep -v -i screen | grep ppss.sh | grep -i bash | wc -l`
if [ "$JOBS" -gt "2" ] if [ "$JOBS" -gt "2" ]
then then
for x in `ps ax | grep -v grep | grep -v -i screen | grep ppss.sh | grep -i bash | awk '{ print $1 }'` for x in `ps aux | grep $USER | grep -v grep | grep -v -i screen | grep ppss.sh | grep -i bash | awk '{ print $1 }'`
do do
if [ ! "$x" == "$PID" ] && [ ! "$x" == "$$" ] if [ ! "$x" == "$PID" ] && [ ! "$x" == "$$" ]
then then
@ -483,6 +483,40 @@ do
esac esac
done done
check_for_running_instances () {
#Checking that this is the only instance of PPSS for this user
JOBS=`ps axu | grep -v grep | grep ${USER} | grep -v -i screen | grep ppss.sh | wc -l`
#echo "$(date) : ${JOBS}"
MIN_JOBS=2
if [ "$ARCH" == "Darwin" ]
then
MIN_JOBS=2
elif [ "$ARCH" == "Linux" ]
then
MIN_JOBS=2
fi
if [ "$JOBS" -gt "$MIN_JOBS" ]
then
log ERROR "Cannot run PPSS because there is another running instances of PPSS detected. See log for more details."
if [ "$ARCH" == "Darwin" ]
then
TMP=`ps aux -j | grep -v grep | grep ${USER} | grep -v -i screen | grep ppss.sh`
log DEBUG "$TMP"
elif [ "$ARCH" == "Linux" ]
then
TMP=`ps aux -f | grep -v grep | grep ${USER} | grep -v -i screen | grep ppss.sh`
log DEBUG "$TMP"
fi
cleanup
exit 2
fi
}
display_header () { display_header () {
log INFO "=========================================================" log INFO "========================================================="
@ -1431,7 +1465,7 @@ show_status () {
main () { main () {
is_running is_running
check_for_running_instances
case $MODE in case $MODE in
node|standalone ) node|standalone )
@ -1542,7 +1576,7 @@ main
while true while true
do do
sleep 5 sleep 5
JOBS=`ps ax | grep -v grep | grep -v -i screen | grep ppss.sh | wc -l` JOBS=`ps aux | grep $USER | grep -v grep | grep -v -i screen | grep ppss.sh | wc -l`
log DEBUG "There are $JOBS running processes. " log DEBUG "There are $JOBS running processes. "
MIN_JOBS=3 MIN_JOBS=3