mycelia.blog/bin/test_static_page.sh

26 lines
538 B
Bash
Raw Normal View History

2024-02-29 19:53:49 -05:00
#!/bin/bash
2024-03-09 17:01:13 -05:00
PORT=21300
2024-03-09 17:06:30 -05:00
python3 -m http.server $PORT --directory public/ &
2024-02-29 19:53:49 -05:00
SERVER_PID=$!
# Give it a moment to start
2024-03-09 17:06:30 -05:00
sleep 5
2024-02-29 19:53:49 -05:00
# Check if the server is running
2024-03-09 17:06:30 -05:00
if ! ps -p $SERVER_PID > /dev/null; then
2024-02-29 19:53:49 -05:00
echo "HTTP server failed to start."
exit 1
fi
# Check HTTP status
status_code=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:$PORT)
# Kill the http server
kill $SERVER_PID
# Check if status code is 200
if [ "$status_code" -ne 200 ]; then
echo "Website returned a non-200 status code: $status_code"
exit 1
fi