Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save phuongdnguyen/ded54df7ad78b13a983bf5019bf90f5b to your computer and use it in GitHub Desktop.

Select an option

Save phuongdnguyen/ded54df7ad78b13a983bf5019bf90f5b 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.

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