aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2021-08-22 09:00:50 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2021-08-22 09:00:50 +0200
commit25e3092887264b8267f775fed053117445173992 (patch)
tree88c9ec88693eef0d539d7c0ad695b95ddba43810
parentbe4c8b2f375137976fb7016e60c038409c7f4349 (diff)
Debug
-rw-r--r--README.md2
-rwxr-xr-xpool.sh69
2 files changed, 57 insertions, 14 deletions
diff --git a/README.md b/README.md
index f0a1d88..21e1454 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,8 @@
- Force the removal of a pool with `./pool.sh remove-force <poolname>` all running processes will be killed and the pool will be deleted
- Additional properties can be attach to processes with `./pool.sh setp <poolname> <procid> <propname> <propvalue>` Defaults properties are `<cmd>`,`<procpid>`,`<startat>`.
- Properties can be retrieve with `./pool.sh getp <poolname> <procid> <propname>`
+- Processes in a pool can be paused with `./pool.sh pause <poolname>`
+- Processes in a pool can be resumed with `./pool.sh resume <poolname>`
- Available pools can be retrieve with `./pool.sh ls`
- All the processes output file can be retrieve with `./pool.sh ls-output <poolname>`
diff --git a/pool.sh b/pool.sh
index 9e97d86..7336545 100755
--- a/pool.sh
+++ b/pool.sh
@@ -30,7 +30,7 @@ write_status() {
}
create_properties() {
- file="${POOL}/proc_${procid}"
+ local file="${POOL}/proc_${procid}"
echo cmd=\"${PROC_CMD}\" > "$file"
echo "procpid=${procpid}" >> "$file"
echo "procid=${procid}" >> "$file"
@@ -38,19 +38,20 @@ create_properties() {
}
setp() {
- file="${POOL}/proc_${procid}"
- echo $1=$2 >> "$file"
+ local file="${POOL}/proc_${procid}"
+ sed -i "/${1}=/d" "$file"
+ echo $1=\"$2\" >> "$file"
}
getp() {
- file="${POOL}/proc_${procid}"
- source "$file"
- echo "${!1}"
+ local file="${POOL}/proc_${procid}"
+ value=$(grep "^$1=" "$file"||:)
+ [ -z "$value" ] && echo "Property $1 not found for process ${procid}" || { echo "$value" | sed "s/^$1=//" | xargs echo; }
}
create() {
- [ -d "$POOL" ] && abort "Pool \"$POOL\" already exists"
+ [ -d "$POOL" ] && abort "Pool \"$POOL\" already exists" || :
mkdir -p "$POOL"
# Write pool status
maxproc=$1
@@ -62,7 +63,7 @@ create() {
remove() {
refresh # Refresh process status and load status
- [ $nproc -gt 0 ] && abort "Processes are still running in the pool!"
+ [ $nproc -gt 0 ] && abort "Processes are still running in the pool!" || :
rm -rf "$POOL"
}
@@ -94,7 +95,7 @@ run() {
procid=$(( lastprocid + 1 ))
lastprocid=$procid
startat=$(date +"%s")
- $PROC_CMD > "$POOL/out_$procid" &
+ $PROC_CMD &> "$POOL/out_$procid" &
procpid=$!
[ -z "$procs" ] && procs="$procpid" || procs="$procs $procpid"
write_status # Update status
@@ -103,7 +104,7 @@ run() {
}
cat_output() {
- file="${POOL}/out_${procid}"
+ local file="${POOL}/out_${procid}"
cat "$file"
}
@@ -134,8 +135,31 @@ remove_force() {
rm -rf "$POOL"
}
-# Ensure pool exists
-[ ! "$CMD" == "create" ] && [ ! "$CMD" == "ls" ] && [ ! -d "$POOL" ] && abort "Pool $POOL_ID not found"
+check_pool() {
+ if [ ! -d "$POOL" ]; then abort "Pool ${POOL_ID} not found"; fi
+ if [ ! -f "$POOL_STATUS" ]; then abort "Pool ${POOL_ID} corrupted: status file not found"; fi
+ if [ $# -gt 0 ]
+ then
+ [ ! -f "${POOL}/proc_${1}" ] && echo abort "Process $1 does not exists in pool ${POOL_ID}" || :
+ fi
+}
+
+pause() {
+ refresh
+ for proc in $procs
+ do
+ kill -STOP $proc
+ done
+}
+
+resume() {
+ refresh
+ for proc in $procs
+ do
+ kill -CONT $proc
+ done
+}
+
# Launch command
case "$CMD" in
@@ -143,37 +167,54 @@ case "$CMD" in
create $1
;;
"remove")
+ check_pool
remove
;;
"run")
+ check_pool
run
;;
"cat")
+ check_pool $1
procid=$1
refresh
- [ $procid -gt $lastprocid ] && abort "Processus $procid not found"
- cat_output
+ [ $procid -gt $lastprocid ] && abort "Processus $procid not found" || cat_output
;;
"ls-output")
+ check_pool
list_output
;;
"ls")
+ check_pool
list_pool
;;
"wait")
+ check_pool
wait_pool
;;
"remove-force")
+ check_pool
remove_force
;;
"setp")
+ check_pool $1
procid=$1
setp $2 $3
;;
"getp")
+ check_pool $1
procid=$1
getp $2
;;
+ "pause")
+ check_pool
+ pause
+ ;;
+ "resume")
+ check_pool
+ resume
+ ;;
*)
abort "Command $CMD unknown"
esac
+