не валится на сервисах без прописанных hack_id

main
Sergey Revyakin 2 weeks ago
parent bc1f6ce578
commit a54e6ae3da

@ -24,6 +24,8 @@ SDR_UNITS=(
dronedetector-sdr-2400.service dronedetector-sdr-2400.service
) )
CONFIGURED_SDR_UNITS=()
log() { log() {
printf '[install_all] %s\n' "$*" printf '[install_all] %s\n' "$*"
} }
@ -33,6 +35,51 @@ die() {
exit 1 exit 1
} }
sdr_unit_env_key() {
local unit="$1"
local band="${unit#dronedetector-sdr-}"
band="${band%.service}"
printf 'hack_%s\n' "$band"
}
get_env_value() {
local key="$1"
awk -F= -v key="$key" '
$1 == key {
value = substr($0, index($0, "=") + 1)
sub(/^[[:space:]]+/, "", value)
sub(/[[:space:]]+$/, "", value)
gsub(/^"/, "", value)
gsub(/"$/, "", value)
gsub(/^'\''/, "", value)
gsub(/'\''$/, "", value)
print value
exit
}
' "${PROJECT_ROOT}/.env"
}
populate_configured_sdr_units() {
CONFIGURED_SDR_UNITS=()
local unit env_key env_value
for unit in "${SDR_UNITS[@]}"; do
env_key="$(sdr_unit_env_key "$unit")"
env_value="$(get_env_value "$env_key")"
if [[ -n "$env_value" ]]; then
CONFIGURED_SDR_UNITS+=("$unit")
else
log "Skipping ${unit}: ${env_key} is empty in .env"
fi
done
if [[ "${#CONFIGURED_SDR_UNITS[@]}" -eq 0 ]]; then
log "No SDR units are configured in .env"
else
log "Configured SDR units: ${CONFIGURED_SDR_UNITS[*]}"
fi
}
print_failure_logs() { print_failure_logs() {
log "Collecting diagnostics..." log "Collecting diagnostics..."
systemctl --no-pager --full status dronedetector-compose.service || true systemctl --no-pager --full status dronedetector-compose.service || true
@ -216,7 +263,7 @@ install_systemd_units() {
systemctl enable dronedetector-compose.service systemctl enable dronedetector-compose.service
systemctl restart dronedetector-compose.service systemctl restart dronedetector-compose.service
for unit in "${SDR_UNITS[@]}"; do for unit in "${CONFIGURED_SDR_UNITS[@]}"; do
systemctl enable "$unit" systemctl enable "$unit"
systemctl restart "$unit" systemctl restart "$unit"
done done
@ -241,7 +288,7 @@ verify_installation() {
log "Verifying services" log "Verifying services"
wait_for_systemd_active dronedetector-compose.service 30 || die "dronedetector-compose.service is not active" wait_for_systemd_active dronedetector-compose.service 30 || die "dronedetector-compose.service is not active"
for unit in "${SDR_UNITS[@]}"; do for unit in "${CONFIGURED_SDR_UNITS[@]}"; do
wait_for_systemd_active "$unit" 45 || die "$unit is not active" wait_for_systemd_active "$unit" 45 || die "$unit is not active"
done done
@ -251,7 +298,7 @@ verify_installation() {
running_services="$(docker compose -f "$COMPOSE_FILE" ps --status running --services || true)" running_services="$(docker compose -f "$COMPOSE_FILE" ps --status running --services || true)"
printf '%s\n' "$running_services" | grep -Fxq "dronedetector-server-to-master" || die "server_to_master is not running" printf '%s\n' "$running_services" | grep -Fxq "dronedetector-server-to-master" || die "server_to_master is not running"
printf '%s\n' "$running_services" | grep -Fxq "dronedetector-nn-server" || die "NN_server is not running" printf '%s\n' "$running_services" | grep -Fxq "dronedetector-telemetry-server" || die "telemetry_server is not running"
log "Verification completed" log "Verification completed"
} }
@ -264,6 +311,7 @@ main() {
extract_local_source_archives extract_local_source_archives
preflight preflight
populate_configured_sdr_units
install_host_non_python_deps install_host_non_python_deps
setup_sdr_python_env setup_sdr_python_env
install_docker_if_needed install_docker_if_needed

@ -17,10 +17,51 @@ SDR_UNITS=(
dronedetector-sdr-2400.service dronedetector-sdr-2400.service
) )
CONFIGURED_SDR_UNITS=()
log() { log() {
printf '[restart_all] %s\n' "$*" printf '[restart_all] %s\n' "$*"
} }
sdr_unit_env_key() {
local unit="$1"
local band="${unit#dronedetector-sdr-}"
band="${band%.service}"
printf 'hack_%s\n' "$band"
}
get_env_value() {
local key="$1"
awk -F= -v key="$key" '
$1 == key {
value = substr($0, index($0, "=") + 1)
sub(/^[[:space:]]+/, "", value)
sub(/[[:space:]]+$/, "", value)
gsub(/^"/, "", value)
gsub(/"$/, "", value)
gsub(/^'\''/, "", value)
gsub(/'\''$/, "", value)
print value
exit
}
' "${PROJECT_ROOT}/.env"
}
populate_configured_sdr_units() {
CONFIGURED_SDR_UNITS=()
local unit env_key env_value
for unit in "${SDR_UNITS[@]}"; do
env_key="$(sdr_unit_env_key "$unit")"
env_value="$(get_env_value "$env_key")"
if [[ -n "$env_value" ]]; then
CONFIGURED_SDR_UNITS+=("$unit")
else
log "Skipping ${unit}: ${env_key} is empty in .env"
fi
done
}
if [[ -x /usr/bin/sudo ]]; then if [[ -x /usr/bin/sudo ]]; then
SUDO=(sudo) SUDO=(sudo)
else else
@ -39,7 +80,7 @@ restart_docker_services() {
restart_sdr_services() { restart_sdr_services() {
log "Restarting SDR systemd units" log "Restarting SDR systemd units"
for unit in "${SDR_UNITS[@]}"; do for unit in "${CONFIGURED_SDR_UNITS[@]}"; do
${SUDO[@]} systemctl restart "$unit" ${SUDO[@]} systemctl restart "$unit"
done done
} }
@ -49,7 +90,7 @@ print_status() {
docker compose -f "$COMPOSE_FILE" ps || true docker compose -f "$COMPOSE_FILE" ps || true
log "SDR status" log "SDR status"
for unit in "${SDR_UNITS[@]}"; do for unit in "${CONFIGURED_SDR_UNITS[@]}"; do
if ${SUDO[@]} systemctl is-active --quiet "$unit"; then if ${SUDO[@]} systemctl is-active --quiet "$unit"; then
printf '%s: active\n' "$unit" printf '%s: active\n' "$unit"
else else
@ -59,6 +100,7 @@ print_status() {
} }
main() { main() {
populate_configured_sdr_units
restart_docker_services restart_docker_services
restart_sdr_services restart_sdr_services
print_status print_status

Loading…
Cancel
Save