fix tmpdir trap

This commit is contained in:
felixlohmeier 2022-12-06 11:39:08 +00:00
parent d1486c5929
commit 4491b9726a
4 changed files with 24 additions and 24 deletions

24
orcli
View File

@ -698,7 +698,7 @@ function get_id() {
# common import tasks to support multiple files and URLs # common import tasks to support multiple files and URLs
# shellcheck shell=bash # shellcheck shell=bash
function init_import() { function init_import() {
local files file tmpdir local files file
# catch args, convert the space delimited string to an array # catch args, convert the space delimited string to an array
files=() files=()
eval "files=(${args[file]})" 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?" error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?"
fi 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 # create tmp directory
OPENREFINE_TMPDIR="$(mktemp -d)" OPENREFINE_TMPDIR="$(mktemp -d)"
trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15 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/" unzip -q -j orcli.zip "*/tests/data/*" -d "tests/data/"
fi 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 # start OpenRefine with tmp workspace
$openrefine -d "$OPENREFINE_TMPDIR" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" & $openrefine -d "$OPENREFINE_TMPDIR" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" &
OPENREFINE_PID="$!" OPENREFINE_PID="$!"
# update trap to kill OpenRefine on error or exit # 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) # 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 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?" error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?"
fi fi
# create tmp directory
OPENREFINE_TMPDIR="$(mktemp -d)"
trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15
# check if OpenRefine is already running # check if OpenRefine is already running
if curl -fs "${OPENREFINE_URL}" &>/dev/null; then 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." error "OpenRefine is already running on port ${args[--port]}." "Hint: Stop the other process or use another port."
fi 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 # 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" & 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="$!" OPENREFINE_PID="$!"
# update trap to kill OpenRefine on error or exit # 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) # 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 if ! curl -fs --retry 20 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then

View File

@ -1,7 +1,7 @@
# common import tasks to support multiple files and URLs # common import tasks to support multiple files and URLs
# shellcheck shell=bash # shellcheck shell=bash
function init_import() { function init_import() {
local files file tmpdir local files file
# catch args, convert the space delimited string to an array # catch args, convert the space delimited string to an array
files=() files=()
eval "files=(${args[file]})" eval "files=(${args[file]})"

View File

@ -38,21 +38,21 @@ else
error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?" error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?"
fi fi
# create tmp directory
OPENREFINE_TMPDIR="$(mktemp -d)"
trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15
# check if OpenRefine is already running # check if OpenRefine is already running
if curl -fs "${OPENREFINE_URL}" &>/dev/null; then 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." error "OpenRefine is already running on port ${args[--port]}." "Hint: Stop the other process or use another port."
fi 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 # 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" & 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="$!" OPENREFINE_PID="$!"
# update trap to kill OpenRefine on error or exit # 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) # 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 if ! curl -fs --retry 20 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then

View File

@ -8,6 +8,11 @@ else
error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?" error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?"
fi 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 # create tmp directory
OPENREFINE_TMPDIR="$(mktemp -d)" OPENREFINE_TMPDIR="$(mktemp -d)"
trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15 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/" unzip -q -j orcli.zip "*/tests/data/*" -d "tests/data/"
fi 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 # start OpenRefine with tmp workspace
$openrefine -d "$OPENREFINE_TMPDIR" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" & $openrefine -d "$OPENREFINE_TMPDIR" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" &
OPENREFINE_PID="$!" OPENREFINE_PID="$!"
# update trap to kill OpenRefine on error or exit # 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) # 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 if ! curl -fs --retry 20 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then