Skip to content

Instantly share code, notes, and snippets.

@Firesphere
Created April 9, 2024 10:05
Show Gist options
  • Save Firesphere/4c3fd1e6597f43cce7532d744513ebc5 to your computer and use it in GitHub Desktop.
Save Firesphere/4c3fd1e6597f43cce7532d744513ebc5 to your computer and use it in GitHub Desktop.
#!/bin/bash
res=$(nmap 127.0.0.1 -PN -p ssh | grep open)
curl -s -m 10 --retry 5 --output /dev/null https://healthcheck.io/ping/UUID/start
curl -fsS -m 10 --retry 5 --output /dev/null --data "${res}" https://healthcheck.io/ping/UUID/log
if [[ "${res}" =~ "open" ]]; then
echo "`date` All good" >> /home/pi/ocicheck.log
curl -s -m 10 --retry 5 --output /dev/null https://healthcheck.io/ping/UUID
rm -f /home/pi/awaitingboot
else
if [ -f "/home/pi/awaitingboot" ]; then
echo "`date` Awaiting reboot" >> /home/pi/ocicheck.log
else
echo "`date` Connection failed" >> /home/pi/ocicheck.log
curl -fsS -m 10 --output /dev/null --retry 5 -q --data "`date` connection failure" https://healthcheck.io/ping/UUID/log
INSTANCE=`oci compute instance list -c ocid1.tenancy.INSTANCEID | jq .data[0]`
INSTANCE_ID=`echo $INSTANCE | jq .id`
INSTANCE_NAME=`echo $INSTANCE | jq ".[\"display-name\"]"`
echo "`date` Executing reset on instance $INSTANCE_NAME" >> /home/pi/ocicheck.log;
/usr/local/bin/oci compute instance action --instance-id ${INSTANCE_ID//\"} --action reset
touch /home/pi/awaitingboot
fi
curl -s -m 10 --retry 5 --output /dev/null https://healthcheck.io/ping/UUID/fail
fi
@Firesphere
Copy link
Author

Replace the relevant things, and your Oracle Cloud Instance will be hard-reset every time it goes down... within a minute or so...
At least, that's the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment