adjust scripts

This commit is contained in:
Karol Wypchlo 2020-09-14 17:40:18 +02:00
parent 4efff4776f
commit a02c27664b
7 changed files with 30 additions and 82 deletions

View File

@ -11,11 +11,8 @@ countdown() {
done done
} }
# first stop healh-check so the server is taken our of load balancer # stop healh-check so the server is taken our of load balancer
docker-compose stop health-check docker exec health-check cli/disable
# then wait 5 minutes for the load balancer to propagate the dns records # then wait 5 minutes for the load balancer to propagate the dns records
countdown 300 countdown 300
# now stop sia process
docker-compose stop sia

6
scripts/portal-up.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
set -e # exit on first error
# start the health-checks service
docker exec health-check cli/enable

14
scripts/portal-upgrade.sh Executable file
View File

@ -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

View File

@ -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 - [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 - [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 - [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 ### 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` > `docker-compose down`
- Accessing siac - Accessing siac
> `docker exec -it sia siac` > `docker exec -it sia siac`
- Stopping sia service - Portal maintenance
- safe method - stops health-check service and wait for dns propagation - Pulling portal out for maintenance
> `setup-scripts/sia-stop.sh` > `scripts/portal-down.sh`
- unsafe (force stop) - Putting portal back into place after maintenance
> `docker-compose down sia` > `scripts/portal-up.sh`
- Restarting sia service - Upgrading portal containers (takes care of pulling it and putting it back)
- safe method - stops health-check service and wait for dns propagation > `scripts/portal-upgrade.sh`
> `setup-scripts/sia-restart.sh`
- unsafe (force restart)
> `docker-compose down sia`
> `docker compose up -d sia`
- Restarting caddy gracefully after making changes to Caddyfile (no downtime) - Restarting caddy gracefully after making changes to Caddyfile (no downtime)
> `docker exec caddy caddy reload --config /etc/caddy/Caddyfile` > `docker exec caddy caddy reload --config /etc/caddy/Caddyfile`
- Restarting nginx gracefully after making changes to nginx configs (no downtime) - Restarting nginx gracefully after making changes to nginx configs (no downtime)

View File

@ -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

View File

@ -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