Cleaning
This commit is contained in:
parent
550b99022b
commit
be4c8b2f37
1 changed files with 24 additions and 24 deletions
48
pool.sh
48
pool.sh
|
@ -11,11 +11,11 @@ then
|
|||
fi
|
||||
|
||||
# Config: feel free to change at your own risks
|
||||
tmpdir=/tmp
|
||||
pool_format="pool_${POOL_ID}"
|
||||
pool="${tmpdir}/${pool_format}/"
|
||||
pool_status="${pool}/status"
|
||||
REFRESH_EVERY=1
|
||||
TMPDIR=/tmp
|
||||
POOL_FORMAT="pool_${POOL_ID}"
|
||||
POOL="${TMPDIR}/${POOL_FORMAT}/"
|
||||
POOL_STATUS="${POOL}/status"
|
||||
REFRESH_EVERY=2
|
||||
|
||||
abort() {
|
||||
echo $@
|
||||
|
@ -23,14 +23,14 @@ abort() {
|
|||
}
|
||||
|
||||
write_status() {
|
||||
echo "maxproc=${maxproc}" > "$pool_status"
|
||||
echo "nproc=${nproc}" >> "$pool_status"
|
||||
echo "procs=\"${procs}\"" >> "$pool_status"
|
||||
echo "lastprocid=$lastprocid" >> "$pool_status"
|
||||
echo "maxproc=${maxproc}" > "$POOL_STATUS"
|
||||
echo "nproc=${nproc}" >> "$POOL_STATUS"
|
||||
echo "procs=\"${procs}\"" >> "$POOL_STATUS"
|
||||
echo "lastprocid=$lastprocid" >> "$POOL_STATUS"
|
||||
}
|
||||
|
||||
write_process() {
|
||||
file="${pool}/proc_${procid}"
|
||||
create_properties() {
|
||||
file="${POOL}/proc_${procid}"
|
||||
echo cmd=\"${PROC_CMD}\" > "$file"
|
||||
echo "procpid=${procpid}" >> "$file"
|
||||
echo "procid=${procid}" >> "$file"
|
||||
|
@ -38,20 +38,20 @@ write_process() {
|
|||
}
|
||||
|
||||
setp() {
|
||||
file="${pool}/proc_${procid}"
|
||||
file="${POOL}/proc_${procid}"
|
||||
echo $1=$2 >> "$file"
|
||||
}
|
||||
|
||||
getp() {
|
||||
file="${pool}/proc_${procid}"
|
||||
file="${POOL}/proc_${procid}"
|
||||
source "$file"
|
||||
echo "${!1}"
|
||||
}
|
||||
|
||||
|
||||
create() {
|
||||
[ -d "$pool" ] && abort "Pool \"$pool\" already exists"
|
||||
mkdir -p "$pool"
|
||||
[ -d "$POOL" ] && abort "Pool \"$POOL\" already exists"
|
||||
mkdir -p "$POOL"
|
||||
# Write pool status
|
||||
maxproc=$1
|
||||
nproc=0
|
||||
|
@ -63,11 +63,11 @@ create() {
|
|||
remove() {
|
||||
refresh # Refresh process status and load status
|
||||
[ $nproc -gt 0 ] && abort "Processes are still running in the pool!"
|
||||
rm -rf "$pool"
|
||||
rm -rf "$POOL"
|
||||
}
|
||||
|
||||
refresh() {
|
||||
source "$pool_status"
|
||||
source "$POOL_STATUS"
|
||||
procs_new=""
|
||||
for proc in $procs
|
||||
do
|
||||
|
@ -94,21 +94,21 @@ 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
|
||||
write_process # Create process properties
|
||||
create_properties # Create process properties
|
||||
echo $procid # Return process id
|
||||
}
|
||||
|
||||
cat_output() {
|
||||
file="${pool}/out_${procid}"
|
||||
file="${POOL}/out_${procid}"
|
||||
cat "$file"
|
||||
}
|
||||
|
||||
list_pool() {
|
||||
find "${tmpdir}" -name "${pool_format}*" -exec basename {} \; 2>/dev/null | sed "s/${pool_format}//g"
|
||||
find "${TMPDIR}" -name "${POOL_FORMAT}*" -exec basename {} \; 2>/dev/null | sed "s/${POOL_FORMAT}//g"
|
||||
}
|
||||
|
||||
wait_pool() {
|
||||
|
@ -122,7 +122,7 @@ wait_pool() {
|
|||
|
||||
list_output() {
|
||||
refresh
|
||||
find "${pool}" -name "out_*"
|
||||
find "${POOL}" -name "out_*"
|
||||
}
|
||||
|
||||
remove_force() {
|
||||
|
@ -131,11 +131,11 @@ remove_force() {
|
|||
do
|
||||
kill -9 $proc
|
||||
done
|
||||
rm -rf "$pool"
|
||||
rm -rf "$POOL"
|
||||
}
|
||||
|
||||
# Ensure pool exists
|
||||
[ ! "$CMD" == "create" ] && [ ! "$CMD" == "ls" ] && [ ! -d "$pool" ] && abort "Pool $POOL_ID not found"
|
||||
[ ! "$CMD" == "create" ] && [ ! "$CMD" == "ls" ] && [ ! -d "$POOL" ] && abort "Pool $POOL_ID not found"
|
||||
|
||||
# Launch command
|
||||
case "$CMD" in
|
||||
|
|
Loading…
Add table
Reference in a new issue