/Ether1NodeGuard

Ether1 node guardian

Primary LanguageJavaScript

Ether1NodeGuard

1. About

Ether1NodeGuard is a guardian process that monitors over the geth daemon. It can catch daemon errors and also monitors if the block count is increasing. In case an error is detected or the block count is stale it restarts the daemon and notifies the devs on the Discord over a web hook.

2. Installation

To install and run it you first need to install dependencies. There are two:

You can see how to install it here.

When you have it installed you can run the guardian by simply doing:

  1. npm install
  2. node index.js

Before doing that however its wise to check the config.json and set the correct settings. Sample of config.json

{
	"node": {
	  "args": ["--rpc", "--rpcaddr", "0.0.0.0", "--rpcport", "8545", "--rpccorsdomain", "*", "--rpcapi",      "admin,db,eth,debug,net,txpool,personal,web3"],
		"path": "C:\\Projects\\XXX\\geth",
		"port": 8545,
		"name": "TestNode"
	},
	"notify": {
		"url": "URL to your Discord WebHook"
	},
	"restart": {
		"errorForgetTime": 600,
		"maxCloseErrors": 3,
		"maxBlockTime": 1800,
		"maxInitTime": 600
	},
	"api": {
		"port": 8080
	}	
}

The explanation of config options:

  • node
    • args: The arguments that get appended to the monitored process.
    • path: The path of the process. If omited it uses the same path where the guardian is located
    • port: The port on which geth is running
    • name: Name of the node. If omited it uses the hostname.
  • notify
    • url: the ulr of the Discord web hook, where the error reports are send.
  • restart
    • errorForgetTime: The time in seconds after which the error is forgoten and error count decreased by 1.
    • maxCloseErrors: Maximum number of errors. After that the guardian stops as there is a serious issue with the daemon.
    • maxBlockTime: Maximum time in seconds between block number increase. If afrer this time the block is still the same its considered an error.
    • maxInitTime: Maximum time in secords in which the node should be initialized.
  • api
    • port: port of the api on which to listen. If not specified the guardian will not listen for incoming requests

To run as a service use systemctl

[Unit]
Description=NodeGuardian

[Service]
Type=simple
# Another Type option: forking
User=nodeguard
WorkingDirectory=/usr/bin
ExecStart=/usr/bin/node /path/to/guardian/index.js
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Copy NodeGuardian.service.sample to /etc/systemd/system/NodeGuardian.service and edit it approprietly.

Now you can start it or stop it with:

  • start: sudo systemctl start NodeGuardian
  • stop: sudo systemctl stop NodeGuardian
  • status: sudo systemctl status NodeGuardian
  • print log: journalctl -e -u NodeGuardian.service
  • reload conf: systemctl daemon-reload

3. API

The Guardian can have an api that listens for incoming requests and returns some info about the node. The api only has one handler (all other request are considered invalid and return 403):

  • getInfo

The result is for example:

{
   "status":{
      "name":"TestNode",
      "errors":0,
      "startTime":"2019-02-24T16:34:53.636Z",
      "blockHeight":188023,
      "nodeVersion":"5.2.1"
   }
}