nimbus-eth2/docs/the_nimbus_book/src/beacon-node-systemd.md

118 lines
3.0 KiB
Markdown
Raw Normal View History

# Set up a systemd service
2020-08-06 11:55:57 +02:00
This page will take you through how to set up a `systemd` service for your beacon node.
2020-08-06 11:55:57 +02:00
> [`systemd`](https://www.freedesktop.org/wiki/Software/systemd/) is a service manager designed specifically for Linux. There is no port to Mac OS.
## Prerequisites
NBC's [external dependencies](./install.md#external-dependencies) and a working [Go](https://golang.org/doc/install) installation (v1.11 or later).
### 1. Clone repositories
Clone the [nimbus-eth2](https://github.com/status-im/nimbus-eth2) and [eth2stats](https://github.com/Alethio/eth2stats-client) repositories in the same directory (so that both repositories are adjacent to each other).
2020-08-06 11:55:57 +02:00
```console
git clone https://github.com/status-im/nimbus-eth2.git
2020-08-06 11:55:57 +02:00
git clone https://github.com/Alethio/eth2stats-client.git
```
### 2. Build repositories
Build both repositories by following their respective build instructions.
*nimbus-eth2*
2020-08-06 11:55:57 +02:00
```console
cd nimbus-eth2
make nimbus_beacon_node
2020-08-06 11:55:57 +02:00
```
*eth2stats*
```console
cd eth2stats-client
make build
```
The resulting binaries should appear in `nimbus-eth2/build/nimbus_beacon_node` and `eth2stats-client/eth2stats-client`, respectively.
2020-08-06 11:55:57 +02:00
### 3. Create an executable script
2020-08-06 11:55:57 +02:00
Create an executable script, `run_nimbus_node.sh`, and place it adjacent to the repositories you cloned in step 1 (same directory level).
```bash
#!/bin/bash
set +e
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
cd $(dirname "$0")
cd nimbus-eth2
2020-08-06 11:55:57 +02:00
NETWORK=$1
NODE_NAME=${NODE_NAME:-$(whoami)}
if [[ "$2" == "" ]]; then
NODE_ID=0
else
NODE_ID=$2
NODE_NAME=$NODE_NAME-$2
fi
let METRICS_PORT=8008+${NODE_ID}
let RPC_PORT=9190+${NODE_ID}
# add your node to eth2stats and run a data collector app that connects to your beacon chain client
mkdir -p /tmp/${NODE_NAME}
2020-08-06 11:55:57 +02:00
../eth2stats-client/eth2stats-client run \
--data.folder=/tmp/${NODE_NAME} \
--eth2stats.node-name="${NODE_NAME}" \
--eth2stats.addr="grpc.${NETWORK}.eth2stats.io:443" --eth2stats.tls=true \
--beacon.type="nimbus" \
--beacon.addr="http://localhost:$RPC_PORT" \
--beacon.metrics-addr="http://localhost:$METRICS_PORT/metrics" > /tmp/ethstats.$NODE_NAME.log 2>&1 &
# build and run the beacon node
2020-08-06 11:55:57 +02:00
make NIMFLAGS="-d:insecure" NODE_ID=$NODE_ID ${NETWORK}
```
> Tip: don't forget to mark the script as executable by running `chmod +x` on it.
### 4. Create a systemd service unit file
2020-08-06 11:55:57 +02:00
Create a `systemd` service unit file, `nbc.service`, and save it in `/etc/systemd/system/`.
```txt
[Unit]
Description=Nimbus beacon node
[Service]
ExecStart=<BASE-DIRECTORY>/run_nimbus_node.sh pyrmont
2020-08-06 11:55:57 +02:00
User=<USERNAME>
Group=<USERNAME>
Restart=always
RuntimeMaxSec=10800
[Install]
WantedBy=default.target
```
Replace:
`<BASE-DIRECTORY>` with the location of the repository in which you performed the `git clone` command in step 1.
`<USERNAME>` with the username of the system user responsible for running the launched processes.
### 5. Notify systemd of the newly added service
2020-08-06 11:55:57 +02:00
```console
sudo systemctl daemon-reload
```
### 6. Start the nim beacon chain service
2020-08-06 11:55:57 +02:00
```console
sudo systemctl enable nbc --now
```