From 4491b9726ac75c21904079527d1f1bde7675f086 Mon Sep 17 00:00:00 2001 From: felixlohmeier Date: Tue, 6 Dec 2022 11:39:08 +0000 Subject: [PATCH] fix tmpdir trap --- orcli | 24 ++++++++++++------------ src/lib/init_import.sh | 2 +- src/run_command.sh | 10 +++++----- src/test_command.sh | 12 ++++++------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/orcli b/orcli index 08e93bc..1107d92 100755 --- a/orcli +++ b/orcli @@ -698,7 +698,7 @@ function get_id() { # common import tasks to support multiple files and URLs # shellcheck shell=bash function init_import() { - local files file tmpdir + local files file # catch args, convert the space delimited string to an array files=() eval "files=(${args[file]})" @@ -1051,6 +1051,11 @@ orcli_test_command() { error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?" fi + # check if OpenRefine is already running + if curl -fs "${OPENREFINE_URL}" &>/dev/null; then + error "OpenRefine is already running on port 3333." "Please stop the other process." + fi + # create tmp directory OPENREFINE_TMPDIR="$(mktemp -d)" trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15 @@ -1065,17 +1070,12 @@ orcli_test_command() { unzip -q -j orcli.zip "*/tests/data/*" -d "tests/data/" fi - # check if OpenRefine is already running - if curl -fs "${OPENREFINE_URL}" &>/dev/null; then - error "OpenRefine is already running on port 3333." "Please stop the other process." - fi - # start OpenRefine with tmp workspace $openrefine -d "$OPENREFINE_TMPDIR" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" & OPENREFINE_PID="$!" # update trap to kill OpenRefine on error or exit - trap '{ rm -rf "$OPENREFINE_TMPDIR"; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15 + trap '{ rm -rf "$OPENREFINE_TMPDIR"; rm -rf /tmp/jetty-127_0_0_1-3333*; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15 # wait until OpenRefine is running (timeout 20s) if ! curl -fs --retry 20 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then @@ -1294,21 +1294,21 @@ orcli_run_command() { error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?" fi - # create tmp directory - OPENREFINE_TMPDIR="$(mktemp -d)" - trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15 - # check if OpenRefine is already running if curl -fs "${OPENREFINE_URL}" &>/dev/null; then error "OpenRefine is already running on port ${args[--port]}." "Hint: Stop the other process or use another port." fi + # create tmp directory + OPENREFINE_TMPDIR="$(mktemp -d)" + trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15 + # start OpenRefine with tmp workspace and autosave period 25 hours REFINE_AUTOSAVE_PERIOD=1440 $openrefine -d "$OPENREFINE_TMPDIR" -m "${args[--memory]}" -p "${args[--port]}" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" & OPENREFINE_PID="$!" # update trap to kill OpenRefine on error or exit - trap '{ rm -rf "$OPENREFINE_TMPDIR"; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15 + trap '{ rm -rf "$OPENREFINE_TMPDIR"; rm -rf /tmp/jetty-127_0_0_1-${OPENREFINE_URL##*:}*; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15 # wait until OpenRefine is running (timeout 20s) if ! curl -fs --retry 20 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then diff --git a/src/lib/init_import.sh b/src/lib/init_import.sh index 976af81..283acfc 100644 --- a/src/lib/init_import.sh +++ b/src/lib/init_import.sh @@ -1,7 +1,7 @@ # common import tasks to support multiple files and URLs # shellcheck shell=bash function init_import() { - local files file tmpdir + local files file # catch args, convert the space delimited string to an array files=() eval "files=(${args[file]})" diff --git a/src/run_command.sh b/src/run_command.sh index c2480fc..1747d89 100644 --- a/src/run_command.sh +++ b/src/run_command.sh @@ -38,21 +38,21 @@ else error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?" fi -# create tmp directory -OPENREFINE_TMPDIR="$(mktemp -d)" -trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15 - # check if OpenRefine is already running if curl -fs "${OPENREFINE_URL}" &>/dev/null; then error "OpenRefine is already running on port ${args[--port]}." "Hint: Stop the other process or use another port." fi +# create tmp directory +OPENREFINE_TMPDIR="$(mktemp -d)" +trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15 + # start OpenRefine with tmp workspace and autosave period 25 hours REFINE_AUTOSAVE_PERIOD=1440 $openrefine -d "$OPENREFINE_TMPDIR" -m "${args[--memory]}" -p "${args[--port]}" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" & OPENREFINE_PID="$!" # update trap to kill OpenRefine on error or exit -trap '{ rm -rf "$OPENREFINE_TMPDIR"; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15 +trap '{ rm -rf "$OPENREFINE_TMPDIR"; rm -rf /tmp/jetty-127_0_0_1-${OPENREFINE_URL##*:}*; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15 # wait until OpenRefine is running (timeout 20s) if ! curl -fs --retry 20 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then diff --git a/src/test_command.sh b/src/test_command.sh index 82f7e48..a06d8a2 100644 --- a/src/test_command.sh +++ b/src/test_command.sh @@ -8,6 +8,11 @@ else error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?" fi +# check if OpenRefine is already running +if curl -fs "${OPENREFINE_URL}" &>/dev/null; then + error "OpenRefine is already running on port 3333." "Please stop the other process." +fi + # create tmp directory OPENREFINE_TMPDIR="$(mktemp -d)" trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15 @@ -22,17 +27,12 @@ if ! [[ -f "tests/help.sh" ]]; then unzip -q -j orcli.zip "*/tests/data/*" -d "tests/data/" fi -# check if OpenRefine is already running -if curl -fs "${OPENREFINE_URL}" &>/dev/null; then - error "OpenRefine is already running on port 3333." "Please stop the other process." -fi - # start OpenRefine with tmp workspace $openrefine -d "$OPENREFINE_TMPDIR" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" & OPENREFINE_PID="$!" # update trap to kill OpenRefine on error or exit -trap '{ rm -rf "$OPENREFINE_TMPDIR"; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15 +trap '{ rm -rf "$OPENREFINE_TMPDIR"; rm -rf /tmp/jetty-127_0_0_1-3333*; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15 # wait until OpenRefine is running (timeout 20s) if ! curl -fs --retry 20 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then