GETH as a service

Over the last few days i’ve been helping quite a few people with setting up their STRONG nodes.

I’m not going to write up a new complete guide setting up a GETH node and adding the stuff you need for a STRONG node application, Grzzdad has done a great job at that: https://medium.com/@grzzdad/how-to-make-an-ethereum-node-eligible-for-strong-5cac75ace6da

I did receive some questions about how to start up GETH as a service though, in case of a reboot or crash of your node. That i can quite easily explain for you here.

  1. we need to create a bash file to start your node from. type nano startgeth.sh or use VI if that has your preference
  2. copy your geth cmdline into the file. For me that is: geth --config config.toml 2> geth.log for some of you it will be something along the lines of: geth --rpc --rpcaddr 0.0.0.0 --rpccorsdomain '*' --rpcapi eth,net,web3,txpool,debug --ws --wsaddr 0.0.0.0 --wsorigins '*' --wsapi eth,net,web3,txpool,debug --nousb from the example from https://strongblock.com/how-to-setup-node.html. The 2> geth.log dumps all the output to a logfile that you can review or check for problems.
  3. Exit nano with ctrl-x and press Y when asked to save.
  4. Next we need to create the service file: sudo nano /lib/systemd/system/geth.service
  5. Enter the following information in that file, replacing the User and directories with your information:
[Unit]
Description=Ethereum go client
[Service]
User=<your geth user>
Type=simple
WorkingDirectory=/home/<your geth user>
ExecStart=/bin/bash /home/<your geth user>/startgeth.sh
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.target
  1. Exit nano with ctrl-x and press Y when asked to save.
  2. Now we need to enable the service: sudo systemctl enable geth
  3. And then start it (make sure geth isn’t already running!): sudo systemctl start geth

That’s it. You’ve enabled geth as a service.

To check the logs you can use: tail -F geth.log this will continuesly print out the information from geth.

If necessary you can stop or restart the service with sudo systemctl stop geth and sudo systemctl restart geth.

Hope this helps someone, if you have questions comment here or hit me up on telegram or twitter.

One Reply to “GETH as a service”

  • Leave a comment