release v1.10, safe cleanup handler issue #4

This commit is contained in:
Felix Lohmeier 2017-11-05 18:09:41 +01:00
parent 9471abc35f
commit 978344a55c
2 changed files with 40 additions and 24 deletions

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# openrefine-batch-docker.sh, Felix Lohmeier, v1.9, 2017-11-05 # openrefine-batch-docker.sh, Felix Lohmeier, v1.10, 2017-11-05
# https://github.com/felixlohmeier/openrefine-batch # https://github.com/felixlohmeier/openrefine-batch
# check system requirements # check system requirements
@ -128,6 +128,10 @@ if [ -z "$outputdir" ]; then
echo 1>&2 "example: ./openrefine-batch-docker.sh -c output/" echo 1>&2 "example: ./openrefine-batch-docker.sh -c output/"
exit 1 exit 1
fi fi
if [ "$(ls -A "$outputdir" 2>/dev/null)" ];then
echo 1>&2 "path to directory for exported files (and OpenRefine workspace) is not empty"
exit 1
fi
if [ "$format" = "xml" ] || [ "$format" = "json" ] && [ -z "$inputoptions" ]; then if [ "$format" = "xml" ] || [ "$format" = "json" ] && [ -z "$inputoptions" ]; then
echo 1>&2 "error: you specified the inputformat $format but did not provide mandatory input options" echo 1>&2 "error: you specified the inputformat $format but did not provide mandatory input options"
echo 1>&2 "please provide recordpath in multiple arguments without slashes" echo 1>&2 "please provide recordpath in multiple arguments without slashes"
@ -173,6 +177,21 @@ checkpointdate[$((checkpoints + 1))]=$(date +%s)
checkpointname[$((checkpoints + 1))]="Start process" checkpointname[$((checkpoints + 1))]="Start process"
memoryload=() memoryload=()
# safe cleanup handler
cleanup()
{
echo ""
echo "cleanup..."
docker stop -t=5000 ${uuid}
docker rm ${uuid}
rm -r -f "${outputdir:?}"/workspace*.json
# delete duplicates from copied projects
if [ -n "$crossprojects" ]; then
for i in "${crossprojects[@]}" ; do rm -r -f "${outputdir}/${i}" ; done
fi
}
trap cleanup EXIT
# launch server # launch server
checkpoints=${#checkpointdate[@]} checkpoints=${#checkpointdate[@]}
checkpointdate[$((checkpoints + 1))]=$(date +%s) checkpointdate[$((checkpoints + 1))]=$(date +%s)
@ -325,17 +344,6 @@ if [ -n "$jsonfiles" ] || [ "$export" = "true" ]; then
fi fi
fi fi
# cleanup
echo "cleanup..."
docker stop -t=5000 ${uuid}
docker rm ${uuid}
rm -r -f "${outputdir:?}"/workspace*.json
# delete duplicates from copied projects
if [ -n "$crossprojects" ]; then
for i in "${crossprojects[@]}" ; do rm -r -f "${outputdir}/${i}" ; done
fi
echo ""
# calculate and print checkpoints # calculate and print checkpoints
echo "=== Statistics ===" echo "=== Statistics ==="
echo "" echo ""

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# openrefine-batch.sh, Felix Lohmeier, v1.9, 2017-11-05 # openrefine-batch.sh, Felix Lohmeier, v1.10, 2017-11-05
# https://github.com/felixlohmeier/openrefine-batch # https://github.com/felixlohmeier/openrefine-batch
# declare download URLs for OpenRefine and OpenRefine client # declare download URLs for OpenRefine and OpenRefine client
@ -153,6 +153,10 @@ if [ -z "$outputdir" ]; then
echo 1>&2 "example: ./openrefine-batch.sh -c output/" echo 1>&2 "example: ./openrefine-batch.sh -c output/"
exit 1 exit 1
fi fi
if [ "$(ls -A "$outputdir" 2>/dev/null)" ];then
echo 1>&2 "path to directory for exported files (and OpenRefine workspace) is not empty"
exit 1
fi
if [ "$format" = "xml" ] || [ "$format" = "json" ] && [ -z "$inputoptions" ]; then if [ "$format" = "xml" ] || [ "$format" = "json" ] && [ -z "$inputoptions" ]; then
echo 1>&2 "error: you specified the inputformat $format but did not provide mandatory input options" echo 1>&2 "error: you specified the inputformat $format but did not provide mandatory input options"
echo 1>&2 "please provide recordpath in multiple arguments without slashes" echo 1>&2 "please provide recordpath in multiple arguments without slashes"
@ -196,6 +200,21 @@ checkpointdate[$((checkpoints + 1))]=$(date +%s)
checkpointname[$((checkpoints + 1))]="Start process" checkpointname[$((checkpoints + 1))]="Start process"
memoryload=() memoryload=()
# safe cleanup handler
cleanup()
{
echo ""
echo "cleanup..."
kill ${pid}
wait
rm -r -f "${outputdir:?}"/workspace*.json
# delete duplicates from copied projects
if [ -n "$crossprojects" ]; then
for i in "${crossprojects[@]}" ; do rm -r -f "${outputdir}/${i}" ; done
fi
}
trap cleanup EXIT
# launch server # launch server
checkpoints=${#checkpointdate[@]} checkpoints=${#checkpointdate[@]}
checkpointdate[$((checkpoints + 1))]=$(date +%s) checkpointdate[$((checkpoints + 1))]=$(date +%s)
@ -351,17 +370,6 @@ if [ -n "$jsonfiles" ] || [ "$export" = "true" ]; then
fi fi
fi fi
# cleanup
echo "cleanup..."
kill ${pid}
wait
rm -r -f "${outputdir:?}"/workspace*.json
# delete duplicates from copied projects
if [ -n "$crossprojects" ]; then
for i in "${crossprojects[@]}" ; do rm -r -f "${outputdir}/${i}" ; done
fi
echo ""
# calculate and print checkpoints # calculate and print checkpoints
echo "=== Statistics ===" echo "=== Statistics ==="
echo "" echo ""