Skip to content

shopglobal/turtlecoind-ha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TurtleCoind High-Availability Daemon Wrapper

This project is designed to wrap the TurtleCoind daemon on a *nix system and monitor it for hangups, locks, or other events that cause the daemon to stop responding to requests

The sample service.js includes how to automatically restart the daemon if it hangs, locks, or otherwise stops responding.

Dependencies

Easy Start

git clone https://github.com/brandonlehmann/turtlecoind-ha.git
cd turtlecoind-ha

Edit the values in service.js to match your environment

var daemon = new TurtleCoind({
  path: '/path/to/turtlecoind',
  dataDir: '/path/to/blockchain',
  pollingInterval: 10000
})

Fire up the process...

node service.js

Fri, 16 Mar 2018 01:13:12 GMT: TurtleCoind has started...
Fri, 16 Mar 2018 01:13:12 GMT: TurtleCoind is attempting to synchronize with the network...
Fri, 16 Mar 2018 01:13:33 GMT: TurtleCoind is synchronized with the network...
Fri, 16 Mar 2018 01:13:44 GMT: TurtleCoind is waiting for connections at 268422 @ 261348121 - 7111111 H/s

Keep it Running

I'm a big fan of PM2 so if you don't have it installed, the setup is quite simple.

npm install -g pm2

pm2 startup
pm2 install pm2-logrotate

pm2 start service.js --watch --name turtlecoind
pm2 save

Documentation

Initialization

Practically all TurtleCoind command line arguments are exposed in the construtor method. Simply include them in your list of options to get activate or use them. Default values are defined below.

The only required option is the path attribute.

var daemon = new TurtleCoind({
  path: '~/TurtleCoind', // Where can I find TurtleCoind?
  dataDir: '~/.TurtleCoin', // Where do you store your blockchain?
  pollingInterval: 2000, // How often to check the daemon in milliseconds
  timeout: 2000, // How long to wait for RPC responses in milliseconds
  testnet: false, // Use the testnet?
  enableCors: false, // Enable CORS support for the domain in this value
  enableBlockExplorer: false, // Enable the block explorer
  rpcBindIp: '127.0.0.1', // What IP to bind the RPC server to
  rpcBindPort: 11898, // What Port to bind the RPC server to
  p2pBindIp: '0.0.0.0', // What IP to bind the P2P network to
  p2pBindPort: 11897, // What Port to bind the P2P network to
  p2pExternalPort: 0, // What External Port to bind the P2P network to for those behind NAT
  allowLocalIp: false, // Add our own IP to the peer list?
  peers: false, // Manually add the peer(s) to the list. Allows for a string or an Array of strings.
  priorityNodes: false, // Manually add the priority node(s) to the peer list. Allows for a string or an Array of strings.
  exclusiveNodes: false, // Only add these node(s) to the peer list. Allows for a string or an Array of strings.
  seedNode: false, // Connect to this node to get the peer list then quit. Allows for a string.
  hideMyPort: false, // Hide from the rest of the network
  dbThreads: 2, // Number of database background threads
  dbMaxOpenFiles: 100, // Number of allowed open files for the DB
  dbWriteBufferSize: 256, // Size of the DB write buffer in MB
  dbReadCacheSize: 10 // Size of the DB read cache in MB
})

Methods

daemon.start()

Starts up the daemon and starts monitoring the process.

daemon.start()

daemon.stop()

Stops the daemon and halts all monitoring processes.

daemon.stop()

daemon.write(text)

Allows you to send a line of text to the daemon console

daemon.write('help')

Events

Event - data

Feeds back the stdout of the daemon process. You can use this to monitor the progress of the application or hook and do your own development.

daemon.on('data', (data) => {
  // do something
})

Event - start

This event is emitted when the daemon starts. The callback contains the command line arguments supplied to TurtleCoind.

daemon.on('start', (args) => {
  // do something
})

Event - synced

This event is emitted when the daemon has synchronized with the TurtleCoin network.

daemon.on('synced', () => {
  // do something
})

Event - ready

This event is emitted when the daemon is synchronized with the TurtleCoin network and is passing all the checks we have for it. It returns the equivalent of a /getinfo call to the RPC server with a few minor additions.

daemon.on('ready', (info) => {
  // do something
})

Sample info

{
  "alt_blocks_count": 6,
  "difficulty": 250306555,
  "grey_peerlist_size": 3611,
  "height": 268368,
  "incoming_connections_count": 32,
  "last_known_block_index": 268366,
  "outgoing_connections_count": 8,
  "status": "OK",
  "tx_count": 262381,
  "tx_pool_size": 0,
  "white_peerlist_size": 214,
  "cached": false,
  "globalHashRate": 7123123
}

Event - down

This event is emitted when the daemon is not responding to RPC requests or local console checks. We believe at that point that the daemon is hung.

daemon.on('down', () => {
  // do something
})

Event - stopped

This event is emitted when the daemon is stopped.

daemon.on('stopped', () => {
  // do something
})

Event - error

This event is emitted when the daemon or our service encounters an error.

daemon.on('error', (err) => {
  // do something
})

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published