Simple curl request to check health via API

Sonarr version (exact version): 3.0.4.1058
Mono version (if Sonarr is not running on Windows): Mono JIT compiler version 5.20.1.19 (Xamarin)
OS: Linux
Debug logs: n/a
Description of issue: Need help checking Sonarr health

I’m not a developer by any strretch, so understanding API requests is not in my skill toolbox. I’ve written a check script, below, for my seedbox that checks each component is running, and then connects via curl to ensure it’s really responding.
This works on a basic level fairly well, however there are times where the HTTP server in Sonarr (and the other *arr’s) responds 200, but the backend is hung.

Can someone help me create a similar curl request I have below that connects to the API and if a valid response is received I can decide if the application needs to be restarted.

I’m checking with the other tools’ support forums to check their API as well, but assume Sonarr will work the same as Radarr and Lidarr.

#!/bin/bash

#jackett
case "$(pgrep jackett | head -n 1 | wc -w)" in

0)  echo "$(date): Restarting Jackett" >> /home/user/launch.log
    screen -dmS jackett bash /home/user/bin/scripts/launch-jackett.sh
    ;;
1)  check=$(curl -m 10 -s -w "%{http_code}\n" -L  http://127.0.0.1:15000 -o /dev/null)
    if [[ $check == 200 || $check == 403 ]]; then
        #service online
        echo "Jackett service responding" > /dev/null
    else
        echo "$(date): Jackett not responding correctly, restarting" >> /home/user/launch.log
        screen -X -S jackett quit
        kill -9 `pgrep jackett | head -n 1`
    fi
    ;;
*)  echo "$(date): Unexpected result" >> /home/user/launch.log
    ;;
esac

#radarr
case "$(pgrep -F /home/user/.config/Radarr/radarr.pid | wc -w)" in

0)  echo "$(date): Restarting Radarr" >> /home/user/launch.log
    screen -dmS radarr bash /home/user/bin/scripts/launch-radarr.sh
    ;;
1)  check=$(curl -m 10 -s -w "%{http_code}\n" -L  http://127.0.0.1:15002 -o /dev/null)
    if [[ $check == 200 || $check == 403 ]]; then
        #service online
        echo "Radarr service responding" > /dev/null
    else
        echo "$(date): Radarr not responding correctly, restarting" >> /home/user/launch.log
        screen -X -S radarr quit
        kill -9 `pgrep -F /home/user/.config/Radarr/radarr.pid | head -n 1`
    fi
    ;;
*)  echo "$(date): Unexpected result" >> /home/user/launch.log
    ;;
esac

#sonarr
case "$(pgrep -F /home/user/.config/Sonarr/sonarr.pid | wc -w)" in

0)  echo "$(date): Restarting Sonarr" >> /home/user/launch.log
    screen -dmS sonarr bash /home/user/bin/scripts/launch-sonarr.sh
    ;;
1)  check=$(curl -m 10 -s -w "%{http_code}\n" -L  http://127.0.0.1:15001 -o /dev/null)
    if [[ $check == 200 || $check == 403 ]]; then
        #service online
        echo "Sonarr service responding" > /dev/null
    else
        echo "$(date): Sonarr not responding correctly, restarting" >> /home/user/launch.log
        screen -X -S sonarr quit
        kill -9 `pgrep -F /home/user/.config/Sonarr/sonarr.pid | head -n 1`
    fi
    ;;
*)  echo "$(date): Unexpected result" >> /home/user/launch.log
    ;;
esac

#lidarr
case "$(pgrep -F /home/user/.config/Lidarr/lidarr.pid | wc -w)" in

0)  echo "$(date): Restarting Lidarr">> /home/user/launch.log
    screen -dmS lidarr bash /home/user/bin/scripts/launch-lidarr.sh
    ;;
1)  check=$(curl -m 10 -s -w "%{http_code}\n" -L  http://127.0.0.1:15003 -o /dev/null)
    if [[ $check == 200 || $check == 403 ]]; then
        #service online
        echo "Lidarr service responding" > /dev/null
    else
        echo "$(date): Lidarr not responding correctly, restarting" >> /home/user/launch.log
        screen -X -S lidarr quit
        kill -9 `pgrep -F /home/user/.config/Lidarr/lidarr.pid | head -n 1`
    fi
    ;;
*)  echo "$(date): Unexpected result" >> /home/user/launch.log
    ;;
esac

#lazylibrarian
case "$(ps aux | grep "[L]azyLibrarian.py" | awk '{print $2}' |head -n 1 | wc -w)" in
    screen -dmS lazylibrarian bash /home/user/bin/scripts/launch-lazylibrarian.sh
    ;;
1)  check=$(curl -m 10 -s -w "%{http_code}\n" -L  http://127.0.0.1:15004 -o /dev/null)
    if [[ $check == 200 || $check == 403 ]]; then
        #service online
        echo "LazyLibrarian service responding" > /dev/null
    else
        echo "$(date): LazyLibrarian not responding correctly, restarting" >> /home/user/launch.log
        screen -X -S lazylibrarian quit
        kill -9 `ps aux | grep "[L]azyLibrarian.py" | awk '{print $2}'`
    fi
    ;;
*)  echo "$(date): Unexpected result" >> /home/user/launch.log
    ;;
esac

#nzbget
case "$( pgrep nzbget | head -n 1 | wc -w)" in

0)  echo "$(date): Restarting nzbget">> /home/user/launch.log
    screen -dmS nzbget bash /home/user/bin/scripts/launch-nzbget.sh[m
    ;;
1)  check=$(curl -m 10 -s -w "%{http_code}\n" -L  http://127.0.0.1:15010 -o /dev/null)
    if [[ $check == 200 || $check == 403 ]]; then
        #service online
        echo "nzbget service responding" > /dev/null
    else
        echo "$(date): Lidarr not responding correctly, restarting" >> /home/user/launch.log
        screen -X -S nzbget quit
        kill -9 `pgrep nzbget | head -n 1`
    fi
    ;;
*)  echo "$(date): Unexpected result" >> /home/user/launch.log
    ;;
esac

#php-fpm
case "$(pgrep php-fpm | head -n 1 | wc -w)" in

0)  echo "$(date): Restarting php-fpm">> /home/user/launch.log
    /usr/bin/php-fpm -y /home/user/.config/php-fpm/php-fpm.conf
    ;;
1)  # all ok
    ;;
*)  echo "$(date): Unexpected result" >> /home/user/launch.log
    ;;
esac

#nginx
case "$(pgrep nginx | head -n 1 | wc -w)" in

0)  echo "$(date): Restarting nginx">> /home/user/launch.log
    /usr/sbin/nginx -c /home/user/.config/nginx/nginx.conf -p /home/user/.config/nginx -g "error_log /home/user/.config/nginx/error_log;"
    ;;
1)  check=$(curl -m 10 -u admin:tMu\$Y99mI9d -s -w "%{http_code}\n" -L  http://127.0.0.1:15011 -o /dev/null)
    if [[ $check == 200 || $check == 403 ]]; then
        #service online
        echo "nginx service responding" > /dev/null
    else
        echo "$(date): Nginx not responding correctly, restarting" >> /home/user/launch.log
        kill -9 `pgrep nginx`
        kill -9 `pgrep php-fpm`
    fi
    ;;
*)  echo "$(date): Unexpected result" >> /home/user/launch.log
    ;;
esac

sleep 10

#rtorrent
case "$(pgrep rtorrent | head -n 1 | wc -w)" in

0)  echo "$(date): Restarting rtorrent">> /home/user/launch.log
    screen -dmS rtorrent bash /home/user/bin/scripts/launch-rtorrent.sh
    ;;
1)  curl -m 120 -s -L  http://127.0.0.1:15012 -o /dev/null
    if [[ $? == 52 ]]; then
        #service online
        echo "rtorrent service responding" > /dev/null
    else
        echo "$(date): rtorrent not responding correctly, restarting" >> /home/user/launch.log
        kill -9 `pgrep rtorrent`
    fi
    ;;
*)  echo "$(date): Unexpected result" >> /home/user/launch.log
    ;;
esac

type or paste code here