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.
- 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 addTimeoutStopSec=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.
I put the 3 minutes timeout but geth still seems to shutdown in a non-proper way. Any suggestions? Is it maybe because I am running it on a RPi4 which needs more time? See log below..