From 29a73e59636be5042bb4f4740d4a78b26b01b66c Mon Sep 17 00:00:00 2001 From: Marcin Jachymiak Date: Thu, 5 Mar 2020 12:07:37 -0500 Subject: [PATCH] Add health-check setup script --- setup-scripts/health-checker.py | 24 ++++++++++++++++----- setup-scripts/setup-health-check-scripts.sh | 13 +++++++++++ setup-scripts/sia.env | 3 +++ 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 setup-scripts/setup-health-check-scripts.sh diff --git a/setup-scripts/health-checker.py b/setup-scripts/health-checker.py index 13fb8982..59bab3aa 100755 --- a/setup-scripts/health-checker.py +++ b/setup-scripts/health-checker.py @@ -1,7 +1,25 @@ #!/usr/bin/env python3 from urllib.request import urlopen, Request -import urllib, json, os, traceback, discord +from dotenv import load_dotenv +from pathlib import Path + +import urllib, json, os, traceback, discord, sys + + +# sc_precision is the number of hastings per siacoin +sc_precision = 10 ** 24 + +# Environment variable globals +api_endpoint, port, portal_name, bot_token, password = None, None, None, None, None + +# Load dotenv file if possible. +if len(sys.argv) > 1: + env_path = Path(sys.argv[1]) + load_dotenv(dotenv_path=env_path) + +bot_token = os.environ["DISCORD_BOT_TOKEN"] +portal_name = os.getenv("PORTAL_NAME") # Get a port or use default port = os.getenv("API_PORT") @@ -9,13 +27,9 @@ if not port: port = "9980" api_endpoint = "http://localhost:{}".format(port) -portal_name = os.getenv("PORTAL_NAME") -# sc_precision is the number of hastings per siacoin -sc_precision = 10 ** 24 # Discord bot initialization -bot_token = os.environ["DISCORD_BOT_TOKEN"] client = discord.Client() channel_name = "skynet-portal-health-check" diff --git a/setup-scripts/setup-health-check-scripts.sh b/setup-scripts/setup-health-check-scripts.sh new file mode 100644 index 00000000..f635c68a --- /dev/null +++ b/setup-scripts/setup-health-check-scripts.sh @@ -0,0 +1,13 @@ +#! /usr/bin/env bash +set -e + +sudo apt-get update +sudo apt-get -y install python3-pip + +pip3 install discord.py + +downloadCheck="0 0,8,16 * * * ~/skynet-webportal/setup-scripts/health-checker.py ~/.sia/sia.env" +uploadCheck="0 0,8,16 * * * ~/skynet-webportal/setup-scripts/health-checker.py ~/.sia/sia-upload.env" + +(crontab -u userhere -l; echo "$downloadCheck" ) | crontab -u userhere - +(crontab -u userhere -l; echo "$uploadCheck" ) | crontab -u userhere - diff --git a/setup-scripts/sia.env b/setup-scripts/sia.env index cc986b46..5b971918 100644 --- a/setup-scripts/sia.env +++ b/setup-scripts/sia.env @@ -1,3 +1,6 @@ SIA_DATA_DIR="" SIA_API_PASSWORD="" SIA_WALLET_PASSWORD="" +API_PORT="" +PORTAL_NAME="" +DISCORD_BOT_TOKEN=""