Skip to content

Commit

Permalink
release v1.10, safe cleanup handler issue #4
Browse files Browse the repository at this point in the history
  • Loading branch information
felixlohmeier committed Nov 5, 2017
1 parent 9471abc commit 978344a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
32 changes: 20 additions & 12 deletions openrefine-batch-docker.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/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

# check system requirements
Expand Down Expand Up @@ -128,6 +128,10 @@ if [ -z "$outputdir" ]; then
echo 1>&2 "example: ./openrefine-batch-docker.sh -c output/"
exit 1
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
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"
Expand Down Expand Up @@ -173,6 +177,21 @@ checkpointdate[$((checkpoints + 1))]=$(date +%s)
checkpointname[$((checkpoints + 1))]="Start process"
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
checkpoints=${#checkpointdate[@]}
checkpointdate[$((checkpoints + 1))]=$(date +%s)
Expand Down Expand Up @@ -325,17 +344,6 @@ if [ -n "$jsonfiles" ] || [ "$export" = "true" ]; then
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
echo "=== Statistics ==="
echo ""
Expand Down
32 changes: 20 additions & 12 deletions openrefine-batch.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/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

# declare download URLs for OpenRefine and OpenRefine client
Expand Down Expand Up @@ -153,6 +153,10 @@ if [ -z "$outputdir" ]; then
echo 1>&2 "example: ./openrefine-batch.sh -c output/"
exit 1
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
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"
Expand Down Expand Up @@ -196,6 +200,21 @@ checkpointdate[$((checkpoints + 1))]=$(date +%s)
checkpointname[$((checkpoints + 1))]="Start process"
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
checkpoints=${#checkpointdate[@]}
checkpointdate[$((checkpoints + 1))]=$(date +%s)
Expand Down Expand Up @@ -351,17 +370,6 @@ if [ -n "$jsonfiles" ] || [ "$export" = "true" ]; then
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
echo "=== Statistics ==="
echo ""
Expand Down

0 comments on commit 978344a

Please sign in to comment.