Created
July 29, 2019 20:31
-
-
Save dana-at-cp/75893539c4f8ba1f8fb589569be39ed7 to your computer and use it in GitHub Desktop.
A simple script to open up the Gaia web API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# open-web-api.sh | |
LOG_FILE=/var/log/open-web-api.log | |
start_time=$(date) | |
echo "$start_time" > $LOG_FILE | |
while true; do | |
api_status=$(api status |grep "Overall API Status" |awk -F ": " '{ print $2 }') | |
if [ "$api_status" == "Started" ]; then | |
echo "API has been started" >> $LOG_FILE | |
api_access=$(api status |grep "Access" |awk -F "ip " '{ print $2 }' |tr -d '[:space:]') | |
if [ "$api_access" == "127.0.0.1" ]; then | |
echo "API access set to localhost only" >> $LOG_FILE | |
mgmt_cli -r true set api-settings accepted-api-calls-from "All IP addresses" --domain 'System Data' --format json >> $LOG_FILE 2>&1 | |
api restart >> $LOG_FILE 2>&1 | |
else | |
api_access=$(api status |grep "Access") | |
echo "$api_access" >> $LOG_FILE | |
fi | |
break | |
else | |
echo "API not started" >> $LOG_FILE | |
sleep 5 | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can have this script run on startup by adding the following lines at the end of /etc/rc.local
# Allow incoming web API calls
/home/admin/bin/open-web-api.sh &