Beat me to it!
In any case… I’ll post what I was writing anyway…
A bash script to check if a file exists on GNU/Linux systems with bash installed:
#!/bin/bash
if [ ! -f is_connected ]; then
echo -e "WARNING! Storage is disconnected.\nShutting down Node...\n"
# iptables -I INPUT -p tcp --dport 28967 -j REJECT
docker stop -t 300 storagenode &&
exit 0
fi
echo -e "Storage is connected.\n"
#if [[ $(iptables -C INPUT -p tcp --dport 28967 -j REJECT) ]]; then
# iptables -D INPUT -p tcp --dport 28967 -j REJECT
#fi
Notes:
-
I have not debugged the script. And the path for the empty file needs to set properly for whatever system and directory setup applies.
-
The
is_connected
file should be located in the configuration directory of your storage node. This directory will need to be accessible by whichever user is running the script. In the case of docker install, the simplest method to run the script is probably creating acron
job for root that runs every 15 minutes. However, it could be set to run every minute without any system problems.
To run every minute via cron:
As root:
crontab -e
* * * * * connected.sh
Tests
Run script without the file created:
$ ./connected.sh
WARNING! Storage is disconnected.
Shutting down Node...
Create an empty file and run the script:
$ touch is_connected
$ ./connected.sh
Storage is connected.
Delete the file and run the script:
$ rm is_connected
$ ./connected.sh
WARNING! Storage is disconnected.
Shutting down Node...
EDIT
Added closing ports via iptables to the script. To open and close the port, uncomment the iptables lines… remove the #