kopia lustrzana https://github.com/bugout-dev/moonstream
Version, env variables check, deployment script
rodzic
905dcbf71a
commit
8d32540666
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Deployment script
|
||||
|
||||
# Colors
|
||||
C_RESET='\033[0m'
|
||||
C_RED='\033[1;31m'
|
||||
C_GREEN='\033[1;32m'
|
||||
C_YELLOW='\033[1;33m'
|
||||
|
||||
# Logs
|
||||
PREFIX_INFO="${C_GREEN}[INFO]${C_RESET} [$(date +%d-%m\ %T)]"
|
||||
PREFIX_WARN="${C_YELLOW}[WARN]${C_RESET} [$(date +%d-%m\ %T)]"
|
||||
PREFIX_CRIT="${C_RED}[CRIT]${C_RESET} [$(date +%d-%m\ %T)]"
|
||||
|
||||
# Main
|
||||
AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION:-us-east-1}"
|
||||
APP_DIR="${APP_DIR:-/home/ubuntu/moonstream}"
|
||||
APP_NODES_DIR="${APP_DIR}/nodes"
|
||||
PYTHON_ENV_DIR="${PYTHON_ENV_DIR:-/home/ubuntu/moonstream-env}"
|
||||
PYTHON="${PYTHON_ENV_DIR}/bin/python"
|
||||
PIP="${PYTHON_ENV_DIR}/bin/pip"
|
||||
SECRETS_DIR="${SECRETS_DIR:-/home/ubuntu/moonstream-secrets}"
|
||||
PARAMETERS_ENV_PATH="${SECRETS_DIR}/app.env"
|
||||
AWS_SSM_PARAMETER_PATH="${AWS_SSM_PARAMETER_PATH:-/moonstream/prod}"
|
||||
SCRIPT_DIR="$(realpath $(dirname $0))"
|
||||
|
||||
# Parameters scripts
|
||||
PARAMETERS_SCRIPT="${SCRIPT_DIR}/parameters.py"
|
||||
CHECKENV_PARAMETERS_SCRIPT="${SCRIPT_DIR}/parameters.bash"
|
||||
CHECKENV_NODES_CONNECTIONS_SCRIPT="${SCRIPT_DIR}/nodes-connections.bash"
|
||||
|
||||
# Service file
|
||||
NODE_BALANCER_SERVICE_FILE="node-balancer.service"
|
||||
|
||||
set -eu
|
||||
|
||||
echo
|
||||
echo
|
||||
echo -e "${PREFIX_INFO} Building executable load balancer for nodes script with Go"
|
||||
EXEC_DIR=$(pwd)
|
||||
cd "${APP_NODES_DIR}/node_balancer"
|
||||
HOME=/root /usr/local/go/bin/go build -o "${APP_NODES_DIR}/node_balancer/nodebalancer" "${APP_NODES_DIR}/node_balancer/main.go"
|
||||
cd "${EXEC_DIR}"
|
||||
|
||||
echo
|
||||
echo
|
||||
echo -e "${PREFIX_INFO} Retrieving deployment parameters"
|
||||
mkdir -p "${SECRETS_DIR}"
|
||||
AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" "${PYTHON}" "${PARAMETERS_SCRIPT}" extract -p "${AWS_SSM_PARAMETER_PATH}" -o "${PARAMETERS_ENV_PATH}"
|
||||
|
||||
echo
|
||||
echo
|
||||
echo -e "${PREFIX_INFO} Retrieving addition deployment parameters"
|
||||
bash "${CHECKENV_PARAMETERS_SCRIPT}" -v -p "moonstream" -o "${PARAMETERS_ENV_PATH}"
|
||||
|
||||
echo
|
||||
echo
|
||||
echo -e "${PREFIX_INFO} Updating nodes connection parameters"
|
||||
bash "${CHECKENV_NODES_CONNECTIONS_SCRIPT}" -v -f "${PARAMETERS_ENV_PATH}"
|
||||
|
||||
echo
|
||||
echo
|
||||
echo -e "${PREFIX_INFO} Replacing existing load balancer for nodes service definition with ${NODE_BALANCER_SERVICE_FILE}"
|
||||
chmod 644 "${SCRIPT_DIR}/${NODE_BALANCER_SERVICE_FILE}"
|
||||
cp "${SCRIPT_DIR}/${NODE_BALANCER_SERVICE_FILE}" "/etc/systemd/system/${NODE_BALANCER_SERVICE_FILE}"
|
||||
systemctl daemon-reload
|
||||
systemctl restart "${NODE_BALANCER_SERVICE_FILE}"
|
|
@ -0,0 +1,18 @@
|
|||
[Unit]
|
||||
Description=Load balancer for blockchain nodes
|
||||
After=network.target
|
||||
StartLimitIntervalSec=300
|
||||
StartLimitBurst=3
|
||||
|
||||
[Service]
|
||||
User=ubuntu
|
||||
Group=www-data
|
||||
WorkingDirectory=/home/ubuntu/moonstream/nodes/node_balancer
|
||||
EnvironmentFile=/home/ubuntu/moonstream-secrets/app.env
|
||||
Restart=on-failure
|
||||
RestartSec=15s
|
||||
ExecStart=/home/ubuntu/moonstream/nodes/node_balancer/nodebalancer -host 0.0.0.0 -port 8544 -healthcheck
|
||||
SyslogIdentifier=node-balancer
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -12,7 +12,7 @@ import (
|
|||
"net/url"
|
||||
"sync/atomic"
|
||||
|
||||
configs "bugout.dev/app-node-balancer/configs"
|
||||
configs "github.com/bugout-dev/moonstream/nodes/node_balancer/configs"
|
||||
)
|
||||
|
||||
// Main variable of pool of blockchains which contains pool of nodes
|
|
@ -13,8 +13,8 @@ import (
|
|||
"net/url"
|
||||
"time"
|
||||
|
||||
configs "bugout.dev/app-node-balancer/configs"
|
||||
humbug "github.com/bugout-dev/humbug/go/pkg"
|
||||
configs "github.com/bugout-dev/moonstream/nodes/node_balancer/configs"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
|
@ -94,12 +94,19 @@ func InitServer() {
|
|||
var listeningPort string
|
||||
var enableHealthCheck bool
|
||||
var enableDebug bool
|
||||
var showVersion bool
|
||||
flag.StringVar(&listeningAddr, "host", "127.0.0.1", "Server listening address")
|
||||
flag.StringVar(&listeningPort, "port", "8544", "Server listening port")
|
||||
flag.BoolVar(&enableHealthCheck, "healthcheck", false, "To enable healthcheck ser healthcheck flag")
|
||||
flag.BoolVar(&enableDebug, "debug", false, "To enable debug mode with extended log set debug flag")
|
||||
flag.BoolVar(&showVersion, "version", false, "Print version")
|
||||
flag.Parse()
|
||||
|
||||
if showVersion {
|
||||
fmt.Printf("Node balancer version: v%s\n", configs.NODE_BALANCER_VERSION)
|
||||
return
|
||||
}
|
||||
|
||||
// Configure Humbug reporter to handle errors
|
||||
var err error
|
||||
sessionID := uuid.New().String()
|
|
@ -38,6 +38,10 @@ var MOONSTREAM_NODES_SERVER_PORT = os.Getenv("MOONSTREAM_NODES_SERVER_PORT")
|
|||
|
||||
// Return list of NodeConfig structures
|
||||
func (nc *NodeConfigList) InitNodeConfigList() {
|
||||
if MOONSTREAM_NODES_SERVER_PORT == "" || MOONSTREAM_NODE_ETHEREUM_A_IPC_ADDR == "" || MOONSTREAM_NODE_ETHEREUM_B_IPC_ADDR == "" || MOONSTREAM_NODE_ETHEREUM_IPC_PORT == "" || MOONSTREAM_NODE_POLYGON_A_IPC_ADDR == "" || MOONSTREAM_NODE_POLYGON_B_IPC_ADDR == "" || MOONSTREAM_NODE_POLYGON_IPC_PORT == "" {
|
||||
log.Fatal("Some of environment variables not set")
|
||||
}
|
||||
|
||||
// Define available blockchain nodes
|
||||
blockchainConfigList := make([]BlockchainConfig, 0, 2)
|
||||
blockchainConfigList = append(blockchainConfigList, BlockchainConfig{
|
|
@ -0,0 +1,3 @@
|
|||
package configs
|
||||
|
||||
var NODE_BALANCER_VERSION = "0.0.1"
|
|
@ -1,4 +1,4 @@
|
|||
module bugout.dev/app-node-balancer
|
||||
module github.com/bugout-dev/moonstream/nodes/node_balancer
|
||||
|
||||
go 1.17
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bugout.dev/app-node-balancer/cmd"
|
||||
"github.com/bugout-dev/moonstream/nodes/node_balancer/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
Plik binarny nie jest wyświetlany.
Ładowanie…
Reference in New Issue