Enhance configuration handling in piscal_launcher.sh and improve working directory resolution in piscal_manager.sh. Added fallback mechanisms for configuration files and refined error handling for directory checks.

This commit is contained in:
2026-03-18 22:08:23 -04:00
parent 68525ad820
commit 44fd41f0e3
2 changed files with 63 additions and 14 deletions
+14 -3
View File
@@ -19,9 +19,17 @@ cleaned_input_directory_name="clninput"
touser_directory_name="fitresult/touser"
nottouser_directory_name="fitresult/nottouser"
# import the settings from piscal.cfg
# import the settings from piscal_launcher.cfg
# $piscal_executable and $storage_directory
. "$base_directory/piscal_launcher.cfg"
piscal_launcher_cfg="$base_directory/piscal_launcher.cfg"
if [ ! -f "$piscal_launcher_cfg" ]; then
piscal_launcher_cfg="/srv/piscal_launcher.cfg"
fi
if [ ! -f "$piscal_launcher_cfg" ]; then
echo "piscal_launcher.cfg not found"
exit 1
fi
. "$piscal_launcher_cfg"
while getopts "hd:f:u:t" opt; do
case "$opt" in
@@ -100,7 +108,10 @@ if [ -z "$suppress_storage_copy" ]; then
cp "$output_directory_nottouser"/* "$storage_directory"/output/ 2>/dev/null
cp "$cleaned_input_directory"/* "$storage_directory"/input/ 2>/dev/null
mv_script=$base_directory/subdir_year.sh
mv_script="$base_directory/subdir_year.sh"
if [ ! -f "$mv_script" ]; then
mv_script="/srv/subdir_year.sh"
fi
pushd "$storage_directory"/output >> /dev/null
"$mv_script"
popd >> /dev/null
+44 -6
View File
@@ -75,17 +75,45 @@ if [ -z "$directory_name" ]; then
echo "directory name required (-d)"
exit 1
fi
working_directory="$base_directory/$directory_name"
candidate_base_directory="$base_directory/$directory_name"
# Resolve the real working directory by probing for an input/ directory.
# This makes the job orchestration resilient when containers create jobs under
# a different root (e.g. $HOME/LeafWeb) than where the manager scripts live.
working_directory=""
for candidate in \
"$candidate_base_directory" \
"$HOME/LeafWeb/$directory_name" \
"$HOME/$directory_name" \
"$PWD/$directory_name" \
"/srv/$directory_name"
do
if [ -d "$candidate/$input_directory_name" ]; then
working_directory="$candidate"
break
fi
done
# If no candidates match, fall back to the historical behavior so errors remain explainable.
if [ -z "$working_directory" ]; then
working_directory="$candidate_base_directory"
fi
input_directory="$working_directory/$input_directory_name"
pid_path="$working_directory/$pid_filename"
# Preserve fail-loud behavior for launch and status operations.
# Cleanup/kill are handled idempotently further below.
if [ "$task" = "launch" ] || [ "$task" = "get_status" ] || [ "$task" = "get_status_cleaned_input" ]; then
if [ ! -d "$working_directory" ]; then
echo "working directory $working_directory not found"
exit 1
fi
input_directory="$working_directory/$input_directory_name"
if [ ! -d "$input_directory" ]; then
echo "input directory $input_directory not found"
exit 1
fi
pid_path="$working_directory/$pid_filename"
fi
## Process task
if [ "$task" = "launch" ]; then
@@ -161,6 +189,14 @@ elif [ "$task" = "get_status" ] || [ "$task" = "get_status_cleaned_input" ]; the
fi
fi
elif [ "$task" = "cleanup" ]; then
# Idempotent cleanup: safe after partial failures.
if [ ! -d "$working_directory" ]; then
exit 0
fi
if [ ! -f "$pid_path" ]; then
exit 0
fi
pid=$(head -n 1 $pid_path 2>/dev/null)
# if the pid exists, check the process status using ps
if ps -p $pid > /dev/null; then
@@ -170,10 +206,12 @@ elif [ "$task" = "cleanup" ]; then
fi
rm -rf "$working_directory"
elif [ "$task" = "kill" ]; then
# if the pid doesn't exist, then process hasn't started
# Idempotent kill: safe after partial failures.
if [ ! -d "$working_directory" ]; then
exit 0
fi
if [ ! -f "$pid_path" ]; then
echo "not started"
exit 1
exit 0
fi
pid=$(head -n 1 $pid_path 2>/dev/null)