#!/bin/bash
# Set CWD to where this shell script is located
cd "$(dirname "$0")"
# Set the PATH variable explicitly to include any necessary directories
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/your/custom/path
# Kills all screen sessions, then kills any processes using tcp connections, excluding ssh
screen -ls | awk '/[0-9]+\./ {print $1}' | xargs -r -n1 screen -S {} -X quit
kill -9 $(comm -23 <(sudo lsof -t -iTCP -sTCP:LISTEN | sort) <(sudo lsof -t -iTCP:22 | sort))
echo "Waiting for 1 second to let everything shut down"
sleep 1
echo "Done waiting!"
screen -dmS blackbox_exporter ./exporter_blackbox/blackbox_exporter --config.file=exporter_blackbox/blackbox.yml
screen -dmS graphite_exporter ./exporter_graphite/graphite_exporter --graphite.listen-address=0.0.0.0:2003 --graphite.mapping-config=exporter_graphite/graphite_mappings.conf
screen -dmS json_exporter ./exporter_json/json_exporter --config.file=exporter_json/json_exporter.yml
screen -dmS telegraf_resxtop ./resxtop/telegraf --config resxtop/telegraf.conf
screen -dmS apcups_exporter ./exporter_apcups/apcups_exporter --metrics-interval 5 --metrics-address 192.168.4.9 --metrics-port 5000
screen -dmS ipmi_exporter ./exporter_ipmi/ipmi_exporter --config.file=exporter_ipmi/ipmi.yml
screen -dmS prowlarr_exportarr ./exporter_exportarr/exportarr "prowlarr" --backfill true --port 9714 --url "http://192.168.5.4:9696" --api-key "APIKEYHERE" --enable-additional-metrics true
screen -dmS radarr_exportarr ./exporter_exportarr/exportarr "radarr" --port 9711 --url "http://192.168.5.4:7878" --api-key "APIKEYHERE" --enable-additional-metrics true
screen -dmS sabnzbd_exportarr ./exporter_exportarr/exportarr "sabnzbd" --port 9710 --url "http://192.168.5.4:8080" --api-key "APIKEYHERE"
screen -dmS sonarr_exportarr ./exporter_exportarr/exportarr "sonarr" --port 9712 --url "http://192.168.5.4:8989" --api-key "APIKEYHERE" --enable-additional-metrics true
screen -dmS sonarrAnime_exportarr ./exporter_exportarr/exportarr "sonarr" --port 9713 --url "http://192.168.5.4:8990" --api-key "APIKEYHERE" --enable-additional-metrics true
# start prometheus last so *hopefully* the data sources are up before it is
screen -dmS prometheus ./prometheus/prometheus --config.file=prometheus/prometheus.yml --web.enable-admin-api