Ethereum Logo

Systemd Ethereum Geth Service on Ubuntu

/ Sven Boesiger / Blockchain, Ubuntu

Installing Ethereum and the blockchain with its “geth” tool on the current version on Ubuntu is rather straightforward. The same counts of course also for transferring Ethers to a local wallet. In order to keep the blockchain in sync locally at all times, it is necessary to launch the command line interface manually each time the system reboots – which may not be an interesting property when you analyzing the blockchain data. Since I constantly transfer the blockchain to my MongoDB I therefore needed  some sort of autostart. SystemD offers the an elegant solution to this problem.

Creating a Systemd Service

A systemd service is a handy way to run the command line interface at startup. Here is the content of the file /lib/systemd/system/geth.service that does exactly that:

[Unit]
Description=The Ethereum Blockchain Command Line Interface
Documentation=man:geth(1)
After=network.target

[Service]
User=[YOUR USERNAME GOES HERE]
Group=[YOUR GROUP GOES HERE]
ExecStart=/usr/bin/geth --fast --cache=1024 --rpc 2>/var/log/geth.log

[Install]
WantedBy=default.target

Please notice that you need to replace your username (or root evenutally) and password in listing above.

Enabling the Service & Launch

Finally I enable & start the service with:

sudo systemctl enable geth && sudo systemctl start geth

Disabling the Service & Stop

I case you every decide that you don’t need to terminate the service:

sudo systemctl disable geth && sudo systemctl stop geth

LEAVE A COMMENT