Ethereum: Always on Geth Node on Ubuntu 16.04

The following script will install the Ethereum client “Geth” and configure it to run as a daemon/service running in the background using Supervisor. It has been upgraded to include instructions to upgrade supervisor to 3.3.3 (or whatever is newer) because the Ubuntu package sucks and has bugs.

Please read this entire post BEFORE following the instructions because the configuration of the Supervisor Service file geth.conf is an important piece and I provide additional suggestions and insights near the bottom of the post.

Add the Geth repository

apt install software-properties-common
add-apt-repository -y ppa:ethereum/ethereum

Update apt and install Geth and Supervisor (for running Geth as a service)

apt update
apt -y install ethereum supervisor python-pip curl

Upgrade pip & Supervisor

pip install pip --upgrade
pip install supervisor --upgrade
sed -i "s#usr/bin#usr/local/bin#g" /lib/systemd/system/supervisor.service

Configure Geth Supervisor Service – Copy and paste this into /etc/supervisor/conf.d/geth.conf

vi /etc/supervisor/conf.d/geth.conf
[program:geth]
command=bash -c '/usr/bin/geth'
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/geth.err.log
stdout_logfile=/var/log/supervisor/geth.out.log

Start supervisor, which will auto-start Geth

systemctl enable supervisor
systemctl start supervisor

That’s it. Geth should now be running and starting its sync process.

A few things to note that you may want to change in /etc/supervisor/conf.d/geth.conf:
#1. As of v1.6.0, fast sync is the new default, you don’t need to include it…
#2. You might want to modify the geth.conf to include user= so it doesn’t run as root…?
#3. You WILL certainly want to modify the command= line to include additional Command Line Options

Here’s my setup:

[program:geth]
command=bash -c '/usr/bin/geth --datadir /geth/.ethereum --rpc --rpccorsdomain "*" --cache 1024 --txpool.nolocals --nat extip:$(curl -s ipinfo.io/ip) --maxpeers 50 --port 30303 --lightserv 50 --lightpeers 50 --ethstats=MysticRyuujin-Geth:SECRET@ethstats.net'
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/geth.err.log
stdout_logfile=/var/log/supervisor/geth.out.log
user=geth

I created an account called geth and created a directory called geth for the database and my network doesn’t support UPnP so I use the –nat to specify my external IP. I also increased the peer count and changed the port number that it’s running on…

adduser --system --no-create-home --group geth
mkdir /geth
chown -R geth:geth /geth

You can connect to the geth console via:

geth attach ipc:/geth/.ethereum/geth.ipc

2 thoughts on “Ethereum: Always on Geth Node on Ubuntu 16.04

  1. In this example systemd starts supervisor which then starts geth. Can you elaborate your preference for supervisor over systemd? Thanks

    1. Ok so part of the reason is that I’m not exactly an expert on Linux and systemd and I was a bit lazy trying to piece it all together. Primarily I found that supervisor was easy to configure custom properties such as which user I wanted it to run under (at the time I didn’t want it to run under root), and define my custom command line options. Now maybe systemd is the correct way to do it, and I’d be happy to update my guide for it with some guidance, but I had all kinds of command line options I wanted to include and other various settings I wanted to do in the service that I wasn’t sure how to do with systemd 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.