Skip to content

Commit

Permalink
fixed services config parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
fqjony committed Dec 26, 2024
1 parent 93a7f42 commit 57e99df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 17 additions & 4 deletions lib/process_manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ should_enable_systemd() {
# Function to parse service information from YAML configuration
parse_service_info() {
local service_yaml="$1"
name=$(echo "$service_yaml" | yq e '.name' -)
exec_start=$(echo "$service_yaml" | yq e '.exec_start' -)
after=$(echo "$service_yaml" | yq e '.after' -)
name=$(echo "$service_yaml" | jq -r '.name' -)
exec_start=$(echo "$service_yaml" | jq -r '.exec_start' -)
after=$(echo "$service_yaml" | jq -r '.after' -)
}

# Function to create a systemd service file from a template
Expand All @@ -35,7 +35,20 @@ generate_and_activate_services() {

echo "services.yml found. Generating and managing systemd service files..."

yq e '.services[]' "$CONFIG_FILE" | while IFS= read -r service_yaml; do
local services_yaml
services_yaml=$(yq eval -o=json '.services[]' "$CONFIG_FILE" | jq -c .)

# Use a temporary file to avoid a subshell
local services_file
services_file=$(mktemp)
echo "$services_yaml" > "$services_file"

# Read all lines into an array, then delete the file
mapfile -t services_array < "$services_file"
rm -f "$services_file"

# Process each service in the array
for service_yaml in "${services_array[@]}"; do
parse_service_info "$service_yaml"

if [[ -n "$name" && -n "$exec_start" && -n "$after" ]]; then
Expand Down
6 changes: 3 additions & 3 deletions src/configs/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
kind: workerService
version: udx.io/worker-v1/service
services:
- name: myservice1
exec_start: /usr/local/scripts/process_example.sh
after: network.target
- name: "myservice1"
exec_start: "/usr/local/scripts/process_example.sh"
after: "network.target"

0 comments on commit 57e99df

Please sign in to comment.