kopia lustrzana https://github.com/bugout-dev/moonstream
				
				
				
			
						commit
						570f3d43d6
					
				| 
						 | 
				
			
			@ -0,0 +1,76 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
# Deployment script - intended to run on Moonstream Gnosis node server
 | 
			
		||||
 | 
			
		||||
# 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"
 | 
			
		||||
SECRETS_DIR="${SECRETS_DIR:-/home/ubuntu/moonstream-secrets}"
 | 
			
		||||
PARAMETERS_ENV_PATH="${SECRETS_DIR}/app.env"
 | 
			
		||||
SCRIPT_DIR="$(realpath $(dirname $0))"
 | 
			
		||||
 | 
			
		||||
# Node status server service file
 | 
			
		||||
NODE_STATUS_SERVER_SERVICE_FILE="node-status.service"
 | 
			
		||||
 | 
			
		||||
# Gnosis nethermind service file
 | 
			
		||||
XDAI_NETHERMIND_SERVICE_FILE="xdai.service"
 | 
			
		||||
 | 
			
		||||
set -eu
 | 
			
		||||
 | 
			
		||||
echo
 | 
			
		||||
echo
 | 
			
		||||
echo -e "${PREFIX_INFO} Building executable server of node status server"
 | 
			
		||||
EXEC_DIR=$(pwd)
 | 
			
		||||
cd "${APP_NODES_DIR}/server"
 | 
			
		||||
HOME=/root /usr/local/go/bin/go build -o "${APP_NODES_DIR}/server/nodestatus" "${APP_NODES_DIR}/server/main.go"
 | 
			
		||||
cd "${EXEC_DIR}"
 | 
			
		||||
 | 
			
		||||
echo
 | 
			
		||||
echo
 | 
			
		||||
echo -e "${PREFIX_INFO} Create secrets directory"
 | 
			
		||||
mkdir -p "${SECRETS_DIR}"
 | 
			
		||||
 | 
			
		||||
echo
 | 
			
		||||
echo
 | 
			
		||||
echo -e "${PREFIX_INFO} Install checkenv"
 | 
			
		||||
HOME=/root /usr/local/go/bin/go install github.com/bugout-dev/checkenv@latest
 | 
			
		||||
 | 
			
		||||
echo
 | 
			
		||||
echo
 | 
			
		||||
echo -e "${PREFIX_INFO} Retrieving deployment parameters"
 | 
			
		||||
AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" /root/go/bin/checkenv show aws_ssm+Product:moonstream,Node:true > "${PARAMETERS_ENV_PATH}"
 | 
			
		||||
 | 
			
		||||
echo
 | 
			
		||||
echo
 | 
			
		||||
echo -e "${PREFIX_INFO} Add instance local IP to parameters"
 | 
			
		||||
AWS_LOCAL_IPV4="$(ec2metadata --local-ipv4)"
 | 
			
		||||
echo "AWS_LOCAL_IPV4=$AWS_LOCAL_IPV4" >> "${PARAMETERS_ENV_PATH}"
 | 
			
		||||
 | 
			
		||||
echo
 | 
			
		||||
echo
 | 
			
		||||
echo -e "${PREFIX_INFO} Replacing existing node status server definition with ${NODE_STATUS_SERVER_SERVICE_FILE}"
 | 
			
		||||
chmod 644 "${SCRIPT_DIR}/${NODE_STATUS_SERVER_SERVICE_FILE}"
 | 
			
		||||
cp "${SCRIPT_DIR}/${NODE_STATUS_SERVER_SERVICE_FILE}" "/etc/systemd/system/${NODE_STATUS_SERVER_SERVICE_FILE}"
 | 
			
		||||
systemctl daemon-reload
 | 
			
		||||
systemctl restart "${NODE_STATUS_SERVER_SERVICE_FILE}"
 | 
			
		||||
 | 
			
		||||
echo
 | 
			
		||||
echo
 | 
			
		||||
echo -e "${PREFIX_INFO} Replacing existing Gnosis nethermind service definition with ${XDAI_NETHERMIND_SERVICE_FILE}"
 | 
			
		||||
chmod 644 "${SCRIPT_DIR}/${XDAI_NETHERMIND_SERVICE_FILE}"
 | 
			
		||||
cp "${SCRIPT_DIR}/${XDAI_NETHERMIND_SERVICE_FILE}" "/etc/systemd/system/${XDAI_NETHERMIND_SERVICE_FILE}"
 | 
			
		||||
systemctl daemon-reload
 | 
			
		||||
systemctl disable "${XDAI_NETHERMIND_SERVICE_FILE}"
 | 
			
		||||
echo -e "${PREFIX_WARN} Nethermind service updated, but not restarted!"
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
[Unit]
 | 
			
		||||
Description=Moonstream node status server
 | 
			
		||||
After=network.target
 | 
			
		||||
 | 
			
		||||
[Service]
 | 
			
		||||
User=ubuntu
 | 
			
		||||
Group=www-data
 | 
			
		||||
WorkingDirectory=/home/ubuntu/moonstream/nodes/server
 | 
			
		||||
EnvironmentFile=/home/ubuntu/moonstream-secrets/app.env
 | 
			
		||||
ExecStart=/home/ubuntu/moonstream/nodes/server/nodestatus \
 | 
			
		||||
    -blockchain xdai \
 | 
			
		||||
    -host "${AWS_LOCAL_IPV4}" \
 | 
			
		||||
    -port "${MOONSTREAM_NODES_SERVER_PORT}"
 | 
			
		||||
SyslogIdentifier=node-status
 | 
			
		||||
 | 
			
		||||
[Install]
 | 
			
		||||
WantedBy=multi-user.target
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,25 @@
 | 
			
		|||
[Unit]
 | 
			
		||||
Description=Gnosis node nethermind client
 | 
			
		||||
StartLimitIntervalSec=500
 | 
			
		||||
StartLimitBurst=5
 | 
			
		||||
After=network.target
 | 
			
		||||
 | 
			
		||||
[Service]
 | 
			
		||||
Restart=on-failure
 | 
			
		||||
RestartSec=5s
 | 
			
		||||
EnvironmentFile=/home/ubuntu/moonstream-secrets/app.env
 | 
			
		||||
ExecStart=/usr/bin/nethermind \
 | 
			
		||||
    --config /usr/share/nethermind/configs/xdai.cfg \
 | 
			
		||||
    --datadir /mnt/disks/nodes/xdai \
 | 
			
		||||
    --JsonRpc.Enabled true \
 | 
			
		||||
    --JsonRpc.EnabledModules Eth,Web3,TxPool \
 | 
			
		||||
    --JsonRpc.Host "${AWS_LOCAL_IPV4}" \
 | 
			
		||||
    --JsonRpc.Port 8545
 | 
			
		||||
Type=simple
 | 
			
		||||
User=ubuntu
 | 
			
		||||
ExecStop=/bin/kill -s SIGINT -$MAINPID
 | 
			
		||||
TimeoutStopSec=180
 | 
			
		||||
SyslogIdentifier=xdai
 | 
			
		||||
 | 
			
		||||
[Install]
 | 
			
		||||
WantedBy=multi-user.target
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +32,7 @@ func (es *extendedServer) pingGethRoute(w http.ResponseWriter, req *http.Request
 | 
			
		|||
		http.Error(w, http.StatusText(500), http.StatusInternalServerError)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if es.blockchain != "ethereum" && es.blockchain != "polygon" {
 | 
			
		||||
	if es.blockchain != "ethereum" && es.blockchain != "polygon" && es.blockchain != "xdai" {
 | 
			
		||||
		log.Printf("Unaccepted blockchain type: %s", es.blockchain)
 | 
			
		||||
		http.Error(w, http.StatusText(400), http.StatusBadRequest)
 | 
			
		||||
		return
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,7 +17,7 @@ func InitServer() {
 | 
			
		|||
	var blockchain string
 | 
			
		||||
	flag.StringVar(&listeningAddr, "host", "127.0.0.1", "Server listening address")
 | 
			
		||||
	flag.StringVar(&listeningPort, "port", "8080", "Server listening port")
 | 
			
		||||
	flag.StringVar(&blockchain, "blockchain", "", "Blockchain to work with (Ethereum/Polygon)")
 | 
			
		||||
	flag.StringVar(&blockchain, "blockchain", "", "Blockchain to work with (ethereum/polygon/xdai)")
 | 
			
		||||
	flag.Parse()
 | 
			
		||||
 | 
			
		||||
	es := extendedServer{blockchain: blockchain}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue