From 42a6d41d702d7da63851070b533003dbcec2aded Mon Sep 17 00:00:00 2001 From: kompotkot Date: Wed, 19 Jan 2022 21:58:51 +0000 Subject: [PATCH] Added bor and geth service files for control via deployment --- nodes/deploy/ethereum/deploy.bash | 1 + nodes/deploy/ethereum/geth.service | 10 +++++-- nodes/deploy/polygon/bor.service | 44 ++++++++++++++++++++++++++++++ nodes/deploy/polygon/deploy.bash | 32 ++++++++++++++++++++++ nodes/deploy/polygon/variables.env | 3 ++ 5 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 nodes/deploy/polygon/bor.service create mode 100644 nodes/deploy/polygon/variables.env diff --git a/nodes/deploy/ethereum/deploy.bash b/nodes/deploy/ethereum/deploy.bash index 4a7abbc9..640bf96f 100755 --- a/nodes/deploy/ethereum/deploy.bash +++ b/nodes/deploy/ethereum/deploy.bash @@ -73,3 +73,4 @@ cp "${SCRIPT_DIR}/${ETHEREUM_GETH_SERVICE_FILE}" "/etc/systemd/system/${ETHEREUM systemctl daemon-reload systemctl disable "${ETHEREUM_GETH_SERVICE_FILE}" systemctl status "${ETHEREUM_GETH_SERVICE_FILE}" +echo -e "${PREFIX_WARN} Geth service updated, but not restarted!" diff --git a/nodes/deploy/ethereum/geth.service b/nodes/deploy/ethereum/geth.service index 1a576862..5dc26f3d 100644 --- a/nodes/deploy/ethereum/geth.service +++ b/nodes/deploy/ethereum/geth.service @@ -1,10 +1,12 @@ [Unit] Description=Ethereum node Geth client +StartLimitIntervalSec=500 +StartLimitBurst=5 After=network.target [Service] -User=ubuntu -Group=www-data +Restart=on-failure +RestartSec=5s EnvironmentFile=/home/ubuntu/moonstream-secrets/app.env ExecStart=/usr/bin/geth --syncmode snap --cache 4096 \ --datadir /mnt/disks/nodes/ethereum \ @@ -13,7 +15,9 @@ ExecStart=/usr/bin/geth --syncmode snap --cache 4096 \ --http.addr "${AWS_LOCAL_IPV4}" \ --http.port 8545 \ --http.vhosts "*" -ExecStop=/bin/kill -s SIGINT -$MAINPID +Type=simple +User=ubuntu +KillSignal=SIGINT TimeoutStopSec=300 SyslogIdentifier=geth diff --git a/nodes/deploy/polygon/bor.service b/nodes/deploy/polygon/bor.service new file mode 100644 index 00000000..a24e9bbd --- /dev/null +++ b/nodes/deploy/polygon/bor.service @@ -0,0 +1,44 @@ +[Unit] +Description=bor +StartLimitIntervalSec=500 +StartLimitBurst=5 +After=network.target + +[Service] +Restart=on-failure +RestartSec=5s +WorkingDirectory=$HOME/node +EnvironmentFile=/etc/matic/metadata +EnvironmentFile=$HOME/node/variables.env +EnvironmentFile=/home/ubuntu/moonstream-secrets/app.env +ExecStart=/home/ubuntu/go/bin/bor --datadir "${MOUNT_DATA_DIR}/.bor/data" \ + --port 30303 \ + --http --http.addr "${AWS_LOCAL_IPV4}" \ + --http.vhosts '*' \ + --http.corsdomain '*' \ + --http.port 8545 \ + --ipcpath "${MOUNT_DATA_DIR}/.bor/data/bor.ipc" \ + --http.api 'eth,net,web3,txpool,bor' \ + --syncmode 'full' \ + --networkid '137' \ + --miner.gasprice '30000000000' \ + --miner.gaslimit '20000000' \ + --miner.gastarget '20000000' \ + --txpool.nolocals \ + --txpool.accountslots 16 \ + --txpool.globalslots 131072 \ + --txpool.accountqueue 64 \ + --txpool.globalqueue 131072 \ + --txpool.lifetime '1h30m0s' \ + --maxpeers 200 \ + --metrics \ + --pprof --pprof.port 7071 --pprof.addr '0.0.0.0' \ + --bootnodes "${BOR_BOOTNODES}" +Type=simple +User=ubuntu +KillSignal=SIGINT +TimeoutStopSec=300 +SyslogIdentifier=bor + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/nodes/deploy/polygon/deploy.bash b/nodes/deploy/polygon/deploy.bash index ff0d6ab0..94b9b4e4 100755 --- a/nodes/deploy/polygon/deploy.bash +++ b/nodes/deploy/polygon/deploy.bash @@ -26,6 +26,13 @@ HEIMDALL_HOME="/mnt/disks/nodes/${BLOCKCHAIN}/.heimdalld" # Node status server service file NODE_STATUS_SERVER_SERVICE_FILE="node-status.service" +# Polygon bor service file +POLYGON_BOR_SERVICE_FILE="bor.service" + +# Node startup variables +NODE_STARTUP_DIRECTORY="/home/ubuntu/node" +NODE_STARTUP_VARIABLES_FILE="variables.env" + set -eu echo @@ -63,6 +70,21 @@ systemctl daemon-reload systemctl restart "${NODE_STATUS_SERVER_SERVICE_FILE}" systemctl status "${NODE_STATUS_SERVER_SERVICE_FILE}" +echo +echo +echo -e "${PREFIX_INFO} Copy node startup environment variables to ${NODE_STARTUP_DIRECTORY} directory" +cp "${SCRIPT_DIR}/${NODE_STARTUP_VARIABLES_FILE}" "${NODE_STARTUP_DIRECTORY}/${NODE_STARTUP_VARIABLES_FILE}" + +echo +echo +echo -e "${PREFIX_INFO} Source startup environment variables" +. "${NODE_STARTUP_DIRECTORY}/${NODE_STARTUP_VARIABLES_FILE}" + +echo +echo +echo -e "${PREFIX_INFO} Modify heimdall config with seeds" +sed -i "s|^seeds =.*|$SEEDS_LINE|" "${MOUNT_DATA_DIR}/.heimdalld/config/config.toml" + echo echo echo -e "${PREFIX_INFO} Source extracted parameters" @@ -83,3 +105,13 @@ MOONSTREAM_NODE_ETHEREUM_IPC_URI="http://$RETRIEVED_NODE_ETHEREUM_IP_ADDR:8545" echo -e "${PREFIX_INFO} Update heimdall config file with Ethereum URI ${C_GREEN}${MOONSTREAM_NODE_ETHEREUM_IPC_URI}${C_RESET}" sed -i "s|^eth_rpc_url =.*|eth_rpc_url = \"$MOONSTREAM_NODE_ETHEREUM_IPC_URI\"|" "${HEIMDALL_HOME}/config/heimdall-config.toml" echo -e "${PREFIX_INFO} Updated ${C_GREEN}eth_rpc_url = $MOONSTREAM_NODE_ETHEREUM_IPC_URI${C_RESET} for heimdall" + +echo +echo +echo -e "${PREFIX_INFO} Replacing existing Polygon Bor service definition with ${POLYGON_BOR_SERVICE_FILE}" +chmod 644 "${SCRIPT_DIR}/${POLYGON_BOR_SERVICE_FILE}" +cp "${SCRIPT_DIR}/${POLYGON_BOR_SERVICE_FILE}" "/etc/systemd/system/${POLYGON_BOR_SERVICE_FILE}" +systemctl daemon-reload +systemctl disable "${POLYGON_BOR_SERVICE_FILE}" +systemctl status "${POLYGON_BOR_SERVICE_FILE}" +echo -e "${PREFIX_WARN} Bor service updated, but not restarted!" diff --git a/nodes/deploy/polygon/variables.env b/nodes/deploy/polygon/variables.env new file mode 100644 index 00000000..48ead926 --- /dev/null +++ b/nodes/deploy/polygon/variables.env @@ -0,0 +1,3 @@ +MOUNT_DATA_DIR="/mnt/disks/nodes/polygon" +SEEDS_LINE='seeds = "f4f605d60b8ffaaf15240564e58a81103510631c@159.203.9.164:26656,4fb1bc820088764a564d4f66bba1963d47d82329@44.232.55.71:26656"' +BOR_BOOTNODES="enode://0cb82b395094ee4a2915e9714894627de9ed8498fb881cec6db7c65e8b9a5bd7f2f25cc84e71e89d0947e51c76e85d0847de848c7782b13c0255247a6758178c@44.232.55.71:30303,enode://88116f4295f5a31538ae409e4d44ad40d22e44ee9342869e7d68bdec55b0f83c1530355ce8b41fbec0928a7d75a5745d528450d30aec92066ab6ba1ee351d710@159.203.9.164:30303"