diff --git a/piscal-manager/piscal_launcher.sh b/piscal-manager/piscal_launcher.sh index 368c00b..b80e6b6 100755 --- a/piscal-manager/piscal_launcher.sh +++ b/piscal-manager/piscal_launcher.sh @@ -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 diff --git a/piscal-manager/piscal_manager.sh b/piscal-manager/piscal_manager.sh index 2a7feb5..5f10c63 100755 --- a/piscal-manager/piscal_manager.sh +++ b/piscal-manager/piscal_manager.sh @@ -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)