Skip to content

Instantly share code, notes, and snippets.

@yorickdowne
Last active February 14, 2023 10:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yorickdowne/27d4a96174562377d86e4df5d8de654f to your computer and use it in GitHub Desktop.
Save yorickdowne/27d4a96174562377d86e4df5d8de654f to your computer and use it in GitHub Desktop.
A systemd unit file for clean Geth restart

Overview

Geth, and other execution clients such as Erigon, Nethermind, and Besu, take some time on shutdown to cleanly close their database. When not given that time, they will need to resync upon restart, often for hours. This gist describes the systemd service file parameter to give them up to 5 minutes of time for a clean shutdown.

Steps

  • Find your service file. It may be called /etc/systemd/system/geth.service or /etc/systemd/system/eth1.service.
  • Edit it using sudo nano FILENAME, and add TimeoutStopSec=300 to the [Service] section. Here is an example of a service file after the change:
[Unit]
Description=Go Ethereum Client
After=network.target
Wants=network.target

[Service]
User=goeth
Group=goeth
Type=simple
Restart=always
RestartSec=5
TimeoutStopSec=300
ExecStart=geth --http --datadir /var/lib/goethereum

[Install]
WantedBy=default.target
  • Tell systemd that the file has changed: sudo systemctl daemon-reload

Done! Next time you stop Geth, or any other client you made this change for, it should cleany persist the database to disk and start up without a lengthy resync.

@yorickdowne
Copy link
Author

Yeah it's possible 3 minutes is not enough on RPi4. Just give it however much time it needs for a clean shutdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment