2020-10-26 18:12:37 +01:00
# Set up a systemd service
2020-08-06 11:55:57 +02:00
2020-10-26 18:12:37 +01: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
2023-04-11 17:42:35 +02:00
`systemd` is used in order to have a command or a program run when your device boots (i.e. add it as a service).
Once this is done, you can start/stop enable/disable from the linux prompt.
2020-08-06 11:55:57 +02:00
2023-03-02 17:22:07 +01:00
!!! abstract "`systemd` "
2023-04-11 17:42:35 +02:00
[`systemd` ](https://systemd.io/ ) is a service manager designed specifically for Linux - it cannot be used on Windows / Mac.
You can find out more about `systemd` [here ](https://fedoramagazine.org/what-is-an-init-system/ )
2020-08-06 11:55:57 +02:00
2023-03-02 17:22:07 +01:00
!!! note "Package manager installations"
When installing Nimbus via your [package manager ](./binaries.md ), a user and service will already have been created for you and you can skip straight to the configuration section.
2020-08-06 11:55:57 +02:00
2022-06-17 17:28:13 +02:00
### 1. Create a dedicated user
2020-12-21 17:59:20 +01:00
2023-04-11 17:42:35 +02:00
We will start by creating a dedicated user and [data directory ](./data-dir.md ) for Nimbus.
The same user can also be used for the execution client.
2020-08-06 11:55:57 +02:00
2022-06-19 09:24:01 +02:00
```sh
2022-06-17 17:28:13 +02:00
# Create the `nimbus` group
sudo groupadd nimbus
2022-07-21 20:19:47 +02:00
# Create the `nimbus` user in the `nimbus` group - we will use /var/lib/nimbus as data directory.
2022-06-17 17:28:13 +02:00
sudo useradd -g nimbus nimbus -m -d /var/lib/nimbus
```
2021-05-18 18:42:51 +02:00
2022-06-17 17:28:13 +02:00
### 2. Create the service file
2020-08-06 11:55:57 +02:00
2022-06-17 17:28:13 +02:00
`systemd` services are created by placing a [service ](https://www.freedesktop.org/software/systemd/man/systemd.service.html ) file in `/etc/systemd/system` , or, if Nimbus was installed by a package manager, `/usr/lib/systemd/system` .
2020-08-06 11:55:57 +02:00
2022-08-26 14:16:38 +02:00
A good starting point is the [example service file ](https://raw.githubusercontent.com/status-im/nimbus-eth2/stable/scripts/package_src/nimbus_beacon_node/image/lib/systemd/system/nimbus_beacon_node.service ) in the Nimbus repository.
2022-06-17 17:28:13 +02:00
2022-06-19 09:24:01 +02:00
```sh
2022-06-17 17:28:13 +02:00
# Download example service file and save it to `/etc/systemd/system/nimbus_beacon_node.service`
2022-08-26 14:16:38 +02:00
curl -s https://raw.githubusercontent.com/status-im/nimbus-eth2/stable/scripts/package_src/nimbus_beacon_node/image/lib/systemd/system/nimbus_beacon_node.service | sudo tee /etc/systemd/system/nimbus_beacon_node.service > /dev/null
2020-11-20 18:27:08 +02:00
```
2020-08-06 11:55:57 +02:00
2022-06-17 17:28:13 +02:00
The format of service files is documented in the [systemd manual ](https://www.freedesktop.org/software/systemd/man/systemd.service.html ).
2022-07-22 21:47:24 +02:00
!!! tip
2022-08-17 09:13:55 +03:00
Automatic restarts increase the risk that the doppelganger detection fails - set `RestartPreventExitStatus=129` to prevent this from happening
2022-06-17 17:28:13 +02:00
### 3. Configure your service
Services are configured either by editing the service file directly or using `systemctl edit` to create an override.
2022-06-19 09:24:01 +02:00
```sh
2022-06-17 17:28:13 +02:00
# Edit the systemd file to match your installation
sudo vi /etc/systemd/system/nimbus_beacon_node.service
2020-08-06 11:55:57 +02:00
2022-06-17 17:28:13 +02:00
# If you installed nimbus via the package manager, use `systemctl edit` instead
sudo systemctl edit nimbus_beacon_node.service
```
2020-08-06 11:55:57 +02:00
2023-04-11 17:42:35 +02:00
The service file contains several options for controlling Nimbus.
Important options include:
2020-08-06 11:55:57 +02:00
2022-12-05 09:15:00 +00:00
* `Environment=NETWORK` : set this to `mainnet` , `prater` or `sepolia` , depending on which network you want to connect to
2023-04-11 17:42:35 +02:00
* `Environment=WEB3_URL` : point this to your execution client, see the [Execution Client ](./eth1.md ) setup guide
* `Environment=REST_ENABLED` : REST is used to interact with the beacon node, in particular when setting up a separate Validator Client, see the [REST API ](./rest-api.md ) guide
* `Environment=METRICS_ENABLED` : metrics are used for monitoring the node, see the [metrics ](./metrics-pretty-pictures.md ) setup guide
* `ExecStart=` : custom options, see the [options ](./options.md ) guide
2021-05-18 18:42:51 +02:00
2022-07-22 21:47:24 +02:00
!!! note
2023-04-11 17:42:35 +02:00
The example assumes Nimbus was installed in `/usr/bin/nimbus_beacon_node` .
If you installed Nimbus elsewhere, make sure to update this path.
2020-08-06 11:55:57 +02:00
2022-06-17 17:28:13 +02:00
### 4. Notify systemd of the newly added service
2020-08-06 11:55:57 +02:00
2022-06-17 17:28:13 +02:00
Every time you add or update a service, the `systemd` daemon must be notified of the changes:
2020-08-06 11:55:57 +02:00
2022-06-19 09:24:01 +02:00
```sh
2020-11-20 18:27:08 +02:00
sudo systemctl daemon-reload
2020-11-20 23:25:51 +01:00
```
2022-06-17 17:28:13 +02:00
### 4. Start the service
2022-06-19 09:24:01 +02:00
```sh
2022-06-17 17:28:13 +02:00
# start the beacon node
sudo systemctl start nimbus_beacon_node
# (Optional) Set the beacon node to start automatically at boot
sudo systemctl enable nimbus_beacon_node
```
### 5. Check the status of the service
`systemctl status` will show if your beacon node is up and running, or has stopped for some reason.
2020-11-20 23:25:51 +01:00
2022-06-19 09:24:01 +02:00
```sh
2022-06-17 17:28:13 +02:00
sudo systemctl status nimbus_beacon_node.service
2020-08-06 11:55:57 +02:00
```
2021-05-18 18:42:51 +02:00
2022-06-19 09:24:01 +02:00
You can also follow the logs using the following command:
2021-05-18 18:42:51 +02:00
2022-06-19 09:24:01 +02:00
```sh
sudo journalctl -uf nimbus_beacon_node.service
2021-05-18 18:42:51 +02:00
```
2023-04-11 17:42:35 +02:00
This will show you the Nimbus logs at the default setting — it should include regular "slot start" messages which will show your [sync progress ](./keep-an-eye.md#keep-track-of-your-syncing-progress ).
Press `ctrl-c` to stop following the logs.
2021-05-18 18:42:51 +02:00
2023-04-11 17:42:35 +02:00
To rewind logs — by one day, say — run:
2021-05-22 11:13:27 +02:00
2022-06-19 09:24:01 +02:00
```sh
2022-06-17 17:28:13 +02:00
sudo journalctl -u nimbus_beacon_node.service --since yesterday
2021-06-03 14:43:20 +02:00
```
2021-05-22 11:13:27 +02:00
2022-07-21 20:19:47 +02:00
## Import validator keys
2023-04-11 17:42:35 +02:00
When using a service, the beacon node is running as a different user.
The key import must be performed as this user in order for the key files to have the correct permission:
2022-07-21 20:19:47 +02:00
```
# Run import command as the `nimbus` user
sudo -u nimbus /usr/bin/nimbus_beacon_node deposit import --data-dir=/var/lib/nimbus/shared_mainnet_0 /path/to/keys
```
2022-07-22 21:47:24 +02:00
!!! note
2023-04-11 17:42:35 +02:00
Make sure to use the same `--data-dir` option as is used in the service file!
Some guides use `--data-dir=/var/lib/nimbus` instead.
2022-07-21 20:19:47 +02:00
2022-06-17 17:28:13 +02:00
## Running multiple beacon nodes
You can run multiple beacon nodes on the same machine simply by copying the `.service` file and adjusting the parameters.
When running multiple beacon nodes, make sure that each service:
* has its own `.service` file
* has its own `--data-dir`
* has its own `--*-port` settings
2021-06-11 13:56:15 +02:00
## Further examples
2023-04-11 17:42:35 +02:00
- A [service template file ](https://github.com/chfast/ethereum-node/blob/main/nimbus%40.service ) by Pawel Bylica which allows you to start two services at the same time, e.g. `nimbus@prater.service` and `nimbus@mainnet.service` .
2022-06-17 17:28:13 +02:00
- The [EthereumOnARM ](https://github.com/diglos/ethereumonarm/blob/main/fpm-package-builder/nimbus/extras/nimbus.service ) project maintains a service file as part of their Ethereum installation package repository.