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:
@@ -19,9 +19,17 @@ cleaned_input_directory_name="clninput"
|
|||||||
touser_directory_name="fitresult/touser"
|
touser_directory_name="fitresult/touser"
|
||||||
nottouser_directory_name="fitresult/nottouser"
|
nottouser_directory_name="fitresult/nottouser"
|
||||||
|
|
||||||
# import the settings from piscal.cfg
|
# import the settings from piscal_launcher.cfg
|
||||||
# $piscal_executable and $storage_directory
|
# $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
|
while getopts "hd:f:u:t" opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
@@ -100,7 +108,10 @@ if [ -z "$suppress_storage_copy" ]; then
|
|||||||
cp "$output_directory_nottouser"/* "$storage_directory"/output/ 2>/dev/null
|
cp "$output_directory_nottouser"/* "$storage_directory"/output/ 2>/dev/null
|
||||||
cp "$cleaned_input_directory"/* "$storage_directory"/input/ 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
|
pushd "$storage_directory"/output >> /dev/null
|
||||||
"$mv_script"
|
"$mv_script"
|
||||||
popd >> /dev/null
|
popd >> /dev/null
|
||||||
|
|||||||
@@ -75,17 +75,45 @@ if [ -z "$directory_name" ]; then
|
|||||||
echo "directory name required (-d)"
|
echo "directory name required (-d)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
working_directory="$base_directory/$directory_name"
|
candidate_base_directory="$base_directory/$directory_name"
|
||||||
if [ ! -d "$working_directory" ]; then
|
|
||||||
|
# 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"
|
echo "working directory $working_directory not found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
input_directory="$working_directory/$input_directory_name"
|
if [ ! -d "$input_directory" ]; then
|
||||||
if [ ! -d "$input_directory" ]; then
|
|
||||||
echo "input directory $input_directory not found"
|
echo "input directory $input_directory not found"
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
pid_path="$working_directory/$pid_filename"
|
|
||||||
|
|
||||||
## Process task
|
## Process task
|
||||||
if [ "$task" = "launch" ]; then
|
if [ "$task" = "launch" ]; then
|
||||||
@@ -161,6 +189,14 @@ elif [ "$task" = "get_status" ] || [ "$task" = "get_status_cleaned_input" ]; the
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
elif [ "$task" = "cleanup" ]; then
|
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)
|
pid=$(head -n 1 $pid_path 2>/dev/null)
|
||||||
# if the pid exists, check the process status using ps
|
# if the pid exists, check the process status using ps
|
||||||
if ps -p $pid > /dev/null; then
|
if ps -p $pid > /dev/null; then
|
||||||
@@ -170,10 +206,12 @@ elif [ "$task" = "cleanup" ]; then
|
|||||||
fi
|
fi
|
||||||
rm -rf "$working_directory"
|
rm -rf "$working_directory"
|
||||||
elif [ "$task" = "kill" ]; then
|
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
|
if [ ! -f "$pid_path" ]; then
|
||||||
echo "not started"
|
exit 0
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pid=$(head -n 1 $pid_path 2>/dev/null)
|
pid=$(head -n 1 $pid_path 2>/dev/null)
|
||||||
|
|||||||
Reference in New Issue
Block a user