Skip to content

Commit

Permalink
fix shell errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fqjony committed Dec 27, 2024
1 parent 8f6b209 commit d3ffbb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions lib/process_manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand All @@ -52,7 +53,7 @@ configure_and_execute_services() {
cp "$TEMPLATE_FILE" "$FINAL_CONFIG"

# Remove the template [program:x] section from FINAL_CONFIG
sed -i '/\[program:\${process_name}\]/,/^$/d' "$FINAL_CONFIG"
sed -i "/[program:${process_name}]/,/^$/d" "$FINAL_CONFIG"

# Convert services to JSON and process each.
local services_yaml
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/process_example.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit d3ffbb3

Please sign in to comment.