Skip to content

Commit

Permalink
Actuaizacion y posibilidad de pausar y continuar para el proceso current
Browse files Browse the repository at this point in the history
  • Loading branch information
nfaguirrec committed Mar 29, 2015
1 parent 4182b12 commit 231cce6
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 101 deletions.
165 changes: 115 additions & 50 deletions sjobq.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
############################################################################
# Copyright (C) 2010 by Nestor Aguirre #
# nfaguirrec@iff.csic.es #
# Copyright (C) 2010-2015 by Nestor Aguirre #
# nfaguirrec@gmail.com #
# #
# This program is free software; you can redistribute it and#or modify #
# it under the terms of the GNU General Public License as published by #
Expand All @@ -25,7 +25,10 @@ STOP_FILE="$DATA_DIR/stop"
REFRESH_INTERVAL="2"
CURRENT_JOB_HOME="$DATA_DIR/current"

update()
##
# @brief
##
function update()
{
local lastID="`cat $CURRENT_JOB_HOME/pid 2> /dev/null`"
local currentPID=""
Expand All @@ -45,7 +48,7 @@ update()

echo "command = `cat $CURRENT_JOB_HOME/com`" >> $DATA_DIR/history
echo "dir = `cat $CURRENT_JOB_HOME/pwd`" >> $DATA_DIR/history
echo "time spent = $((spentTime/3600))h $((spentTime/60))m $((spentTime%60))s" >> $DATA_DIR/history
echo "time spent = $((spentTime/3600))h $(((spentTime/60)%60))m $((spentTime%60))s" >> $DATA_DIR/history
echo "" >> $DATA_DIR/history
fi

Expand Down Expand Up @@ -100,7 +103,10 @@ update()
fi
}

start()
##
# @brief
##
function start()
{
while [ 1 ]
do
Expand All @@ -115,60 +121,119 @@ start()
done
}

stop()
##
# @brief
##
function stop()
{
echo "" > $STOP_FILE
sleep 3
rm -rf $DATA_DIR
}

case $1 in
start)
if [ ! -d "$DATA_DIR" ]
then
mkdir -p $DATA_DIR
fi
##
# @brief
##
function pause()
{
pushd . &> /dev/null
cd $DATA_DIR
ID_LIST=`ls *.bid 2> /dev/null | sed '{s/[.].*//g}'`
popd &> /dev/null

PID_LIST=`cat $CURRENT_JOB_HOME/pids`
PID_FIRST=`echo $PID_LIST | awk '{print $1}'`

if [ -n "`ps -A | awk '{print $1}' | grep "$PID_FIRST"`" ]
then
kill -STOP $PID_LIST
fi

nohup $0 __start > $DATA_DIR/log 2> $DATA_DIR/err &
echo "Job with id=current has been paused !!"
}

##
# @brief
##
function cont()
{
pushd . &> /dev/null
cd $DATA_DIR
ID_LIST=`ls *.bid 2> /dev/null | sed '{s/[.].*//g}'`
popd &> /dev/null

PID_LIST=`cat $CURRENT_JOB_HOME/pids`
PID_FIRST=`echo $PID_LIST | awk '{print $1}'`

if [ -n "`ps -A | awk '{print $1}' | grep "$PID_FIRST"`" ]
then
kill -CONT $PID_LIST
fi

echo "=============================="
echo " SJobQ daemon has been started"
echo "=============================="
;;
stop)
isRunning="`ps -u $USER | grep "sjobq.d$" | awk '{a[NR]=$1}END{ if(a[2]==(a[1]+1)) print 0; else print 1}'`"
if [ $isRunning -eq "0" ]
then
echo "### Error ### The daemon sjobq.d is not running"
echo " run it using \"sjobq.d start\""
exit 1
else
echo "Job with id=current has been continued !!"
}

##
# @brief
##
function main()
{
case $1 in
start)
if [ ! -d "$DATA_DIR" ]
then
mkdir -p $DATA_DIR
fi

nohup $0 __start > $DATA_DIR/log 2> $DATA_DIR/err &

echo "=============================="
echo " SJobQ daemon has been stopped"
echo " SJobQ daemon has been started"
echo "=============================="
;;
stop)
isRunning="`ps -u $USER | grep "sjobq.d$" | awk '{a[NR]=$1}END{ if(a[2]==(a[1]+1)) print 0; else print 1}'`"
if [ $isRunning -eq "0" ]
then
echo "### Error ### The daemon sjobq.d is not running"
echo " run it using \"sjobq.d start\""
exit 1
else
echo "=============================="
echo " SJobQ daemon has been stopped"
echo "=============================="
stop
fi

;;
pause)
pause
;;
cont)
cont
;;
restart)
stop
fi

;;
restart)
stop

if [ ! -d "$DATA_DIR" ]
then
mkdir -p $DATA_DIR
fi

nohup $0 __start > $DATA_DIR/log 2> $DATA_DIR/err &

echo "================================"
echo " SJobQ daemon has been restarted"
echo "================================"
;;
__start)
start
;;
*)
echo "Usage: sjobq.d {start|stop|restart}"
;;
esac

if [ ! -d "$DATA_DIR" ]
then
mkdir -p $DATA_DIR
fi

nohup $0 __start > $DATA_DIR/log 2> $DATA_DIR/err &

echo "================================"
echo " SJobQ daemon has been restarted"
echo "================================"
;;
__start)
start
;;
*)
echo "Usage: sjobq.d {start|stop|restart}"
;;
esac
}

main $*

55 changes: 35 additions & 20 deletions sjobq.del
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
############################################################################
# Copyright (C) 2010 by Nestor Aguirre #
# nfaguirrec@iff.csic.es #
# Copyright (C) 2010-2015 by Nestor Aguirre #
# nfaguirrec@gmail.com #
# #
# This program is free software; you can redistribute it and#or modify #
# it under the terms of the GNU General Public License as published by #
Expand All @@ -24,7 +24,10 @@ COUNTER_FILE="$DATA_DIR/counter"
CURRENT_JOB_HOME="$DATA_DIR/current"
MAX_HISTORY="10"

showJobs()
##
# @brief
##
function showJobs()
{
pushd . &> /dev/null
cd $DATA_DIR
Expand All @@ -45,7 +48,7 @@ showJobs()
echo "pid = `cat $CURRENT_JOB_HOME/pid`"
echo "command = `cat $CURRENT_JOB_HOME/com`"
echo "dir = `cat $CURRENT_JOB_HOME/pwd`"
echo "time spent = $((spentTime/3600))h $((spentTime/60))m $((spentTime%60))s"
echo "time spent = $((spentTime/3600))h $(((spentTime/60)%60))m $((spentTime%60))s"
echo "pids = `cat $CURRENT_JOB_HOME/pids`"
echo "tree ="
cat $CURRENT_JOB_HOME/tree | sed '{s/^/\t/g}'
Expand Down Expand Up @@ -78,7 +81,10 @@ showJobs()
fi
}

deleteJob()
##
# @brief
##
function deleteJob()
{
ID=$1

Expand All @@ -97,6 +103,7 @@ deleteJob()
kill -9 $PID_LIST
fi

echo "Job with id=current has been deleted !!"
return
fi

Expand All @@ -121,19 +128,27 @@ deleteJob()
fi
}

if [ -z "`ps -u $USER | grep "sjobq.d$"`" ]
then
echo "### Error ### The daemon sjobq.d is not running"
echo " run it using \"sjobq.d start\""
exit 1
fi
##
# @brief
##
function main()
{
if [ -z "`ps -u $USER | grep "sjobq.d$"`" ]
then
echo "### Error ### The daemon sjobq.d is not running"
echo " run it using \"sjobq.d start\""
exit 1
fi

if [ -n "$*" ]
then
for delId in $*
do
deleteJob $delId
done
else
showJobs
fi
if [ -n "$*" ]
then
for delId in $*
do
deleteJob $delId
done
else
showJobs
fi
}

main $*
65 changes: 36 additions & 29 deletions sjobq.push
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
############################################################################
# Copyright (C) 2010 by Nestor Aguirre #
# nfaguirrec@iff.csic.es #
# Copyright (C) 2010-2015 by Nestor Aguirre #
# nfaguirrec@gmail.com #
# #
# This program is free software; you can redistribute it and#or modify #
# it under the terms of the GNU General Public License as published by #
Expand All @@ -22,38 +22,45 @@
DATA_DIR="/var/tmp/$USER/sjobq.data"
COUNTER_FILE="$DATA_DIR/counter"

if [ -z "`ps -u $USER | grep "sjobq.d$"`" ]
then
echo "### Error ### The daemon sjobq.d is not running"
echo " run it using \"sjobq.d start\""
exit 1
fi
##
# @brief
##
function main()
{
if [ -z "`ps -u $USER | grep "sjobq.d$"`" ]
then
echo "### Error ### The daemon sjobq.d is not running"
echo " run it using \"sjobq.d start\""
exit 1
fi

BID="X"
if [ -f "$COUNTER_FILE" ]
then
previous=`cat $COUNTER_FILE`

if [ $previous -eq "32767" ]
BID="X"
if [ -f "$COUNTER_FILE" ]
then
BID="0"
previous=`cat $COUNTER_FILE`

if [ $previous -eq "32767" ]
then
BID="0"
else
BID=$(( $previous + 1 ))
fi

else
BID=$(( $previous + 1 ))
echo "0" > $COUNTER_FILE
BID=`cat $COUNTER_FILE`
fi

else
echo "0" > $COUNTER_FILE
BID=`cat $COUNTER_FILE`
fi
echo $BID > $COUNTER_FILE
echo $BID > $COUNTER_FILE

COMMAND=$*
COMMAND=$*

echo "id = $BID"
echo "command = $COMMAND"
echo "dir = $PWD"
echo "id = $BID"
echo "command = $COMMAND"
echo "dir = $PWD"

echo "$BID" > $DATA_DIR/$BID.bid
echo "$COMMAND" > $DATA_DIR/$BID.com
echo "$PWD" > $DATA_DIR/$BID.pwd
echo "$BID" > $DATA_DIR/$BID.bid
echo "$COMMAND" > $DATA_DIR/$BID.com
echo "$PWD" > $DATA_DIR/$BID.pwd
}

main $*
4 changes: 2 additions & 2 deletions sjobq.stat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
############################################################################
# Copyright (C) 2010 by Nestor Aguirre #
# nfaguirrec@iff.csic.es #
# Copyright (C) 2010-2015 by Nestor Aguirre #
# nfaguirrec@gmail.com #
# #
# This program is free software; you can redistribute it and#or modify #
# it under the terms of the GNU General Public License as published by #
Expand Down

0 comments on commit 231cce6

Please sign in to comment.