├── .nvmrc ├── .gitignore ├── README.md ├── TODO.adoc ├── package.json ├── ethup ├── index.js └── README.adoc /.nvmrc: -------------------------------------------------------------------------------- 1 | 8.9 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ethup 2 | 3 | A command line utility to start your ethereum nodes and stop them once they have finished synchronizing the chain. It works with both parity and geth. 4 | 5 | See more at https://github.com/chevdor/ethup -------------------------------------------------------------------------------- /TODO.adoc: -------------------------------------------------------------------------------- 1 | 2 | == Future 3 | 4 | May be generalized and renamed to syncup or listenup later. 5 | 6 | It could become: 7 | 8 | $ listenup --cmd parity --exp Imported --run "kill " 9 | 10 | or 11 | 12 | $ listenup --cmd parity --exp Imported && kill $! -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ethup", 3 | "version": "0.1.2", 4 | "description": "Utility to let your ethereum node sync and stop", 5 | "main": "ethup", 6 | "bin": "./ethup", 7 | "scripts": { 8 | "test": "mocha" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/chevdor/ethup" 13 | }, 14 | "keywords": [ 15 | "ethereum" 16 | ], 17 | "author": "chevdor ", 18 | "license": "ISC", 19 | "dependencies": { 20 | "yargs": "^11.0.0" 21 | } 22 | } -------------------------------------------------------------------------------- /ethup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const pkg = require('./package.json') 3 | console.log(`${pkg.name} v${pkg.version}`) 4 | 5 | const argv = require('yargs') 6 | .usage('Usage: $0 [options]') 7 | // .command('start', 'start a process') 8 | .example('$0 -c geth', 'Run Geth until the chain is synced') 9 | .example('$0 -c parity', 'Run Parity until the chain is synced') 10 | .alias('c', 'command') 11 | .nargs('c', 1) 12 | .describe('c', 'Run a command') 13 | .demandOption(['c']) 14 | .help('h') 15 | .alias('h', 'help') 16 | .epilog('chevdor-(C)2018') 17 | .argv 18 | 19 | var Ethup = require('./index.js') 20 | var ethup = new Ethup() 21 | 22 | const regexp = '(Imported \#|Imported.*blocks=1\\s)' 23 | 24 | ethup.run(argv.command, [], regexp, (status) => { 25 | console.log('Exiting') 26 | process.exit(status) 27 | }) 28 | 29 | process.on('SIGINT', function() { 30 | console.log("Caught interrupt signal"); 31 | ethup.kill() 32 | }); -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { spawn } = require('child_process') 2 | 3 | class Ethup { 4 | constructor() { 5 | this.proc = null 6 | } 7 | 8 | checkAndKill(data, regexp, done) { 9 | var re = new RegExp(regexp) 10 | 11 | if (re.test(data.toString())) { 12 | this.proc.kill() 13 | if (done) done(0) 14 | } 15 | } 16 | 17 | run(executable, args, regexp, done) { 18 | this.proc = spawn(executable, args, { shell: true }) 19 | 20 | this.proc.stdout.on('data', (data) => { 21 | process.stdout.write(data.toString()) 22 | this.checkAndKill(data.toString(), regexp, done) 23 | }) 24 | 25 | this.proc.stderr.on('data', (data) => { 26 | process.stdout.write(data.toString()) 27 | this.checkAndKill(data.toString(), regexp, done) 28 | }) 29 | 30 | this.proc.on('exit', (status) => { 31 | console.log(`Child exited with code ${status}`) 32 | if (done) done(status) 33 | }) 34 | } 35 | 36 | kill() { 37 | this.proc.kill() 38 | } 39 | } 40 | 41 | module.exports = Ethup -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = ethup 2 | 3 | A command line utility to start your ethereum nodes and stop them once they have finished synchronizing the chain. 4 | It works with both parity and geth. 5 | 6 | == Install 7 | 8 | $ npm install -g ethup 9 | 10 | == Usage 11 | 12 | Call the following command for the doc: 13 | 14 | $ ethup --help 15 | 16 | Samples: 17 | 18 | $ ethup -c "geth --rinkeby" 19 | $ ethup -c "parity --chain kovan" 20 | $ ethup -c "parity --chain ropsten" 21 | $ ethup -c "parity" 22 | 23 | If, like me, you like to keep you chains in sync, you may build a recipe similar to (assuming you have both geth and parity installed): 24 | 25 | $ time ethup -c "parity --chain kovan"; \ 26 | time ethup -c "parity --chain ropsten"; \ 27 | time ethup -c "parity"; \ 28 | time ethup -c "geth --rinkeby" 29 | 30 | == How does it work? 31 | 32 | It works by starting the node with the command you provide (so you may use the options you want) and applying some very complex magic to guess when the sync is complete. It will then stop the node and exit. 33 | 34 | == Can I trust you? 35 | 36 | Nop. Never. You should check the code, it is really not that long anyway... 37 | --------------------------------------------------------------------------------