diff --git a/setup-scripts/blacklist-skylink.sh b/scripts/blacklist-skylink.sh similarity index 100% rename from setup-scripts/blacklist-skylink.sh rename to scripts/blacklist-skylink.sh diff --git a/setup-scripts/sia-stop.sh b/scripts/portal-down.sh similarity index 65% rename from setup-scripts/sia-stop.sh rename to scripts/portal-down.sh index 1bbe2ce5..b2a9593c 100755 --- a/setup-scripts/sia-stop.sh +++ b/scripts/portal-down.sh @@ -11,11 +11,8 @@ countdown() { done } -# first stop healh-check so the server is taken our of load balancer -docker-compose stop health-check +# stop healh-check so the server is taken our of load balancer +docker exec health-check cli/disable # then wait 5 minutes for the load balancer to propagate the dns records countdown 300 - -# now stop sia process -docker-compose stop sia diff --git a/scripts/portal-up.sh b/scripts/portal-up.sh new file mode 100755 index 00000000..1a287f2f --- /dev/null +++ b/scripts/portal-up.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -e # exit on first error + +# start the health-checks service +docker exec health-check cli/enable diff --git a/scripts/portal-upgrade.sh b/scripts/portal-upgrade.sh new file mode 100755 index 00000000..b2973809 --- /dev/null +++ b/scripts/portal-upgrade.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e # exit on first error + +# put the server down for maintenance +. ${cwd}/portal-down.sh + +# rebuild and restart all docker containers +docker-compose build --no-cache +docker-compose down +docker-compose up -d + +# enable the server again +. ${cwd}/portal-up.sh diff --git a/setup-scripts/README.md b/setup-scripts/README.md index 5536517c..e1a743a0 100644 --- a/setup-scripts/README.md +++ b/setup-scripts/README.md @@ -23,7 +23,7 @@ You may want to fork this repository and replace ssh keys in - [funds-checker](funds-checker.py): script that checks wallet balance and sends status messages to discord periodically - [health-checker](health-checker.py): script that monitors health-check service for server health issues and reports them to discord periodically - [log-checker](log-checker.py): script that scans siad logs for critical errors and reports them to discord periodically -- [blacklist-skylink](blacklist-skylink.sh): script that can be run locally from a machine that has access to all your skynet portal servers that blacklists provided skylink and prunes nginx cache to ensure it's not available any more (that is a bit much but that's the best we can do right now without paid nginx version) - if you want to use it, make sure to adjust the server addresses +- [blacklist-skylink](../scripts/blacklist-skylink.sh): script that can be run locally from a machine that has access to all your skynet portal servers that blacklists provided skylink and prunes nginx cache to ensure it's not available any more (that is a bit much but that's the best we can do right now without paid nginx version) - if you want to use it, make sure to adjust the server addresses ### Step 1: setting up server user @@ -96,17 +96,13 @@ At this point we have almost everything running, we just need to set up your wal > `docker-compose down` - Accessing siac > `docker exec -it sia siac` -- Stopping sia service - - safe method - stops health-check service and wait for dns propagation - > `setup-scripts/sia-stop.sh` - - unsafe (force stop) - > `docker-compose down sia` -- Restarting sia service - - safe method - stops health-check service and wait for dns propagation - > `setup-scripts/sia-restart.sh` - - unsafe (force restart) - > `docker-compose down sia` - > `docker compose up -d sia` +- Portal maintenance + - Pulling portal out for maintenance + > `scripts/portal-down.sh` + - Putting portal back into place after maintenance + > `scripts/portal-up.sh` + - Upgrading portal containers (takes care of pulling it and putting it back) + > `scripts/portal-upgrade.sh` - Restarting caddy gracefully after making changes to Caddyfile (no downtime) > `docker exec caddy caddy reload --config /etc/caddy/Caddyfile` - Restarting nginx gracefully after making changes to nginx configs (no downtime) diff --git a/setup-scripts/sia-restart.sh b/setup-scripts/sia-restart.sh deleted file mode 100755 index 967638ef..00000000 --- a/setup-scripts/sia-restart.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e # exit on first error - -# get running script directory -cwd=$(cd -P -- "$(dirname -- "$0")" && pwd -P) - -# run the sia-stop script -. ${cwd}/sia-stop.sh - -# start sia -docker-compose up -d sia diff --git a/setup-scripts/stats-logger.sh b/setup-scripts/stats-logger.sh deleted file mode 100755 index 9fc614de..00000000 --- a/setup-scripts/stats-logger.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash - -LOGFILE=$1 -SIA_PORT=${SIA_PORT:-9980} - -# This is a logger service that pulls some current skynet stats and appends them to json log file. -# You should probably run it using crontab, most likely as a root due to access_log read restrictions. -# -# basic usage: -# /home/user/skynet-webportal/setup-scripts/stats-logger.sh public/logs.json -# -# usage with custom sia port: -# SIA_PORT=9970 /home/user/skynet-webportal/setup-scripts/stats-logger.sh public/logs.json -# -# configuring hourly logging with crontab (run crontab -e) -# 0 * * * * /home/user/skynet-webportal/setup-scripts/stats-logger.sh /home/user/skynet-webportal/public/stats.json >/dev/null 2>&1 - -if ! [ -x "$(command -v jq)" ]; then - echo 'Error: jq is not installed. Please install with `sudo apt-get install jq`.' >&2 - exit 1 -fi - -if ! [ -x "$(command -v sponge)" ]; then - echo 'Error: sponge is not installed. Please install with `sudo apt-get install moreutils`.' >&2 - exit 1 -fi - -if [ -z "$LOGFILE" ]; then - echo 'Error: You need to specify json log file name.' >&2 - exit 1 -fi - -# create logfile if it doesn't exist and initialize it with empty array -if [ ! -f "$LOGFILE" ]; then - mkdir -p "`dirname \"$LOGFILE\"`" 2>/dev/null - echo [] > $LOGFILE -fi - -# get downloads count from nginx logs -awk -vDate=`date -d'now-1 hours' +[%d/%b/%Y:%H:%M:%S` ' { if ($4 > Date) print $0}' /var/log/nginx/access.log > /var/log/nginx/access_last_hour.log -DOWNLOADS_COUNT_LAST_HOUR=$(awk '{print $7}' /var/log/nginx/access_last_hour.log | grep -E '/[a-zA-Z0-9_-]{46}(/.*)?' | wc -l) - -# get siac output -SKYNET_LS=$(/home/user/go/bin/siac skynet ls --addr localhost:${SIA_PORT} | grep -i listing) -SKYNET_LS_REGEX="Listing (.*) files\/dirs:\s+(.*)" -if [[ "${SKYNET_LS}" =~ $SKYNET_LS_REGEX ]]; then - SKYFILES_COUNT="${BASH_REMATCH[1]}" - SKYFILES_SIZE_BYTES=$(echo ${BASH_REMATCH[2]} | sed -r 's/[ B]//g' | numfmt --from=iec) -fi - -DATE=$(date -u +"%Y-%m-%d %H:%M:%S") -LOG_ENTRY=$(echo {\"date\":\"${DATE}\", \"skyfiles_count\":${SKYFILES_COUNT}, \"skyfiles_size_bytes\":${SKYFILES_SIZE_BYTES}, \"downloads_count_last_hour\":${DOWNLOADS_COUNT_LAST_HOUR}}) -jq -c ". += [${LOG_ENTRY}]" $LOGFILE | sponge $LOGFILE \ No newline at end of file