From dd37aaf9ab3f99da3bcb2011d57b62a4340d35c7 Mon Sep 17 00:00:00 2001 From: Dmitry Smirnov Date: Fri, 27 Dec 2024 17:57:55 +0200 Subject: [PATCH] fix shell errors --- lib/process_manager.sh | 18 ++++++++++-------- src/scripts/process_example.sh | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/process_manager.sh b/lib/process_manager.sh index 919a2d96..d643b118 100644 --- a/lib/process_manager.sh +++ b/lib/process_manager.sh @@ -17,15 +17,16 @@ should_generate_config() { # Helper function to parse and process each service configuration parse_service_info() { local service_json="$1" - local name=$(echo "$service_json" | jq -r '.name') - local command=$(echo "$service_json" | jq -r '.command') - local autostart=$(echo "$service_json" | jq -r '.autostart // "false"') - local autorestart=$(echo "$service_json" | jq -r '.autorestart // "false"') - local stderr_logfile=$(echo "$service_json" | jq -r '.stderr_logfile // ""') - local stdout_logfile=$(echo "$service_json" | jq -r '.stdout_logfile // ""') - local environment=$(echo "$service_json" | jq -r '.environment // [] | join(",")') + local name command autostart autorestart stderr_logfile stdout_logfile environment + + name=$(echo "$service_json" | jq -r '.name') + command=$(echo "$service_json" | jq -r '.command') + autostart=$(echo "$service_json" | jq -r '.autostart // "false"') + autorestart=$(echo "$service_json" | jq -r '.autorestart // "false"') + stderr_logfile=$(echo "$service_json" | jq -r '.stderr_logfile // ""') + stdout_logfile=$(echo "$service_json" | jq -r '.stdout_logfile // ""') + environment=$(echo "$service_json" | jq -r '.environment // [] | join(",")') - # For each service, replace placeholders and append to FINAL_CONFIG sed "s|\${process_name}|$name|g; \ s|\${command}|$command|g; \ s|\${autostart}|$autostart|g; \ @@ -52,6 +53,7 @@ configure_and_execute_services() { cp "$TEMPLATE_FILE" "$FINAL_CONFIG" # Remove the template [program:x] section from FINAL_CONFIG + # shellcheck disable=SC2154 sed -i '/\[program:\${process_name}\]/,/^$/d' "$FINAL_CONFIG" # Convert services to JSON and process each. diff --git a/src/scripts/process_example.sh b/src/scripts/process_example.sh index 175897b9..e786ee67 100644 --- a/src/scripts/process_example.sh +++ b/src/scripts/process_example.sh @@ -1,10 +1,10 @@ #!/bin/bash -# Script to run as a systemd service in a loop +# Script to run as a supervisor service in a loop end_time=$(($(date +%s) + 30)) # Calculate end_time as current epoch time plus 30 seconds. -while [ $(date +%s) -lt $end_time ]; do +while [ "$(date +%s)" -lt $end_time ]; do echo "Service is running at $(date)" sleep 5 done