0

The requirement is keep a geth node synchronised almost always for a DAPP . The geth node is running on a ubuntu machine. The command being used to expose the geth rpc server is

geth --testnet --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3 --rpcport 8545 --rpccorsdomain "*" --rpcaddr "127.0.0.1" --rpc

I usually connect to the server using putty . But when I close the putty session , the geth process also gets killed .I need to avoid this. What is required is to keep the geth syncing continuously , so that any user who uses the DAPP can make a transaction anytime.

0

First thing is to make sure you started the process in fast mode so the chain is always up to date. You can use geth's --fast command for quickest possible syncs.

Also, increase cache size to --cache=1024 instead of the default 128

To keep the process running after your putty logout, you can obviously try screen or use tmux which is a superior way of doing this.

  • I have already used tmux to achieve this successfully . Thanks for your response. – Webdev May 8 at 6:01
2

Setting up geth as a service - https://github.com/bas-vk/config/blob/master/geth-systemd-service.md

Create a file geth.service:

[Unit]
Description=Ethereum go client

[Service]
Type=simple
ExecStart=geth 2>%h/.ethereum/geth.log

[Install]
WantedBy=default.target

Enable service

$ systemctl --user enable geth.service
$ systemctl --user start geth.service
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – Ismael May 7 at 17:22
  • Changed. Thanks for the feedback. – eth7 May 7 at 18:24
1

When you close SSH session, all processes you've run, either in background or foreground, receive SIGHUP (SIGnal Hang UP). Most applications, including geth, react to this signal by gracefully terminating themselves.

There are several ways how you may prevent your applications from terminating on SSH session close:

  1. Prevent them from receiving SIGHUP via nohup utility: nohup geth <your geth options here> &. Note this & at the end, it sends the process into background.
  2. Run geth inside virtual screen terminal that will stay alive after SSH session close. To do so, run screen then run your geth inside, then press Ctrl+A then press 'D' to detach your SSH session from virtual screen. Then close SSH session.

Though, if your want your geth not only to survive SSH session close, but also to automatically restart after system reboot, you need to configure it as a system service:

  1. Create file /etc/systemd/system/geth.service with the following content:
[Unit]
Description=Go Ethereum (geth)

[Service]
Type=simple
ExecStart=geth <your geth options here>

[Install]
WantedBy=default.target
  1. Execute command systemctl daemon-reload to load geth service
  2. Execute command systemctl enable geth.service to enable geth service
  3. Execute command systemctl start geth.service to start geth service

You will probably need superuser privileges to do all these steps.

0

Try screen. Set it up, start your node and detach (don't exit). When you log out from putty, your node should still be running

0

Best way is to run as systemd:

Create geth.service file (/etc/systemd/system/geth.service):

sudo nano /etc/systemd/system/geth.service

Paste the below

[Unit]
Description=Geth

[Service]
Type=simple
User={$USER}
Restart=always
RestartSec=12
ExecStart=/bin/geth --syncmode "full" --rpc --rpcaddr "0.0.0.0"

[Install]
WantedBy=default.target

Replace {$USER} with username above. Use useradd to create a newUser if required.

sudo useradd -d /home/newUser -m --uid 10000 newUser

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable geth.service
sudo systemctl daemon-reload

service geth status
sudo service geth start

Check the status:

service geth status

Attaching to geth instance:

geth attach

Stop and disable the service:

sudo service geth stop
sudo systemctl disable geth.service
sudo systemctl daemon-reload

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.