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
+49 -11
View File
@@ -75,18 +75,46 @@ if [ -z "$directory_name" ]; then
echo "directory name required (-d)"
exit 1
fi
working_directory="$base_directory/$directory_name"
if [ ! -d "$working_directory" ]; then
echo "working directory $working_directory not found"
exit 1
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"
if [ ! -d "$input_directory" ]; then
echo "input directory $input_directory not found"
exit 1
fi
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
if [ ! -d "$input_directory" ]; then
echo "input directory $input_directory not found"
exit 1
fi
fi
## Process task
if [ "$task" = "launch" ]; then
# verify process isn't running yet
@@ -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)