From a63d0cc614459c0b75d77bae8648a3bafa721774 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Tue, 30 Jan 2018 16:16:46 +1300 Subject: [PATCH 01/11] feat: route to shutdown daemon --- src/core/index.js | 1 + src/http/api/resources/shutdown.js | 9 +++++++++ src/http/api/routes/index.js | 1 + src/http/api/routes/shutdown.js | 13 +++++++++++++ 4 files changed, 24 insertions(+) create mode 100644 src/http/api/resources/shutdown.js create mode 100644 src/http/api/routes/shutdown.js diff --git a/src/core/index.js b/src/core/index.js index b0e5719b2f..83cc20cd37 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -77,6 +77,7 @@ class IPFS extends EventEmitter { this.preStart = components.preStart(this) this.start = components.start(this) this.stop = components.stop(this) + this.shutdown = this.stop this.isOnline = components.isOnline(this) // - interface-ipfs-core defined API this.version = components.version(this) diff --git a/src/http/api/resources/shutdown.js b/src/http/api/resources/shutdown.js new file mode 100644 index 0000000000..6c1ae45c66 --- /dev/null +++ b/src/http/api/resources/shutdown.js @@ -0,0 +1,9 @@ +'use strict' + +exports = module.exports + +exports.do = (request, reply) => { + const server = request.server + setImmediate(() => server.stop(() => {})) + return reply() +} diff --git a/src/http/api/routes/index.js b/src/http/api/routes/index.js index 9e405ae6b5..aeba5f1427 100644 --- a/src/http/api/routes/index.js +++ b/src/http/api/routes/index.js @@ -2,6 +2,7 @@ module.exports = (server) => { require('./version')(server) + require('./shutdown')(server) require('./id')(server) require('./bootstrap')(server) require('./block')(server) diff --git a/src/http/api/routes/shutdown.js b/src/http/api/routes/shutdown.js new file mode 100644 index 0000000000..f4c57a2371 --- /dev/null +++ b/src/http/api/routes/shutdown.js @@ -0,0 +1,13 @@ +'use strict' + +const resources = require('./../resources') + +module.exports = (server) => { + const api = server.select('API') + + api.route({ + method: '*', + path: '/api/v0/shutdown', + handler: resources.shutdown.do + }) +} From d0772efbdfb72104b976959cc7bc5ef042dd9ec5 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Wed, 31 Jan 2018 09:34:08 +1300 Subject: [PATCH 02/11] feat: cli and http-api shutdown --- src/cli/commands/shutdown.js | 17 +++++++++++++++++ src/http/api/resources/index.js | 1 + src/http/api/resources/shutdown.js | 23 ++++++++++++++--------- src/http/api/routes/shutdown.js | 26 +++++++++++++------------- 4 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 src/cli/commands/shutdown.js diff --git a/src/cli/commands/shutdown.js b/src/cli/commands/shutdown.js new file mode 100644 index 0000000000..99c6e8d6a7 --- /dev/null +++ b/src/cli/commands/shutdown.js @@ -0,0 +1,17 @@ +'use strict' + +module.exports = { + command: 'shutdown', + + describe: 'Shut down the ipfs daemon', + + builder: {}, + + handler (argv) { + argv.ipfs.shutdown((err) => { + if (err) { + throw err + } + }) + } +} diff --git a/src/http/api/resources/index.js b/src/http/api/resources/index.js index 42eec1d0b0..efc7785dbd 100644 --- a/src/http/api/resources/index.js +++ b/src/http/api/resources/index.js @@ -1,6 +1,7 @@ 'use strict' exports.version = require('./version') +exports.shutdown = require('./shutdown') exports.id = require('./id') exports.bootstrap = require('./bootstrap') exports.repo = require('./repo') diff --git a/src/http/api/resources/shutdown.js b/src/http/api/resources/shutdown.js index 6c1ae45c66..56f137cc91 100644 --- a/src/http/api/resources/shutdown.js +++ b/src/http/api/resources/shutdown.js @@ -1,9 +1,14 @@ -'use strict' - -exports = module.exports - -exports.do = (request, reply) => { - const server = request.server - setImmediate(() => server.stop(() => {})) - return reply() -} +'use strict' + +exports = module.exports + +/* + * Stop the daemon. + * + * Returns an empty response to the caller then + * on the next 'tick' emits SIGTERM. + */ +exports.do = (request, reply) => { + setImmediate(() => process.emit('SIGTERM')) + return reply() +} diff --git a/src/http/api/routes/shutdown.js b/src/http/api/routes/shutdown.js index f4c57a2371..b3d8c9f8ef 100644 --- a/src/http/api/routes/shutdown.js +++ b/src/http/api/routes/shutdown.js @@ -1,13 +1,13 @@ -'use strict' - -const resources = require('./../resources') - -module.exports = (server) => { - const api = server.select('API') - - api.route({ - method: '*', - path: '/api/v0/shutdown', - handler: resources.shutdown.do - }) -} +'use strict' + +const resources = require('./../resources') + +module.exports = (server) => { + const api = server.select('API') + + api.route({ + method: '*', + path: '/api/v0/shutdown', + handler: resources.shutdown.do + }) +} From e1aed02c78e179143e8f806f43e63afc43fc679f Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Wed, 31 Jan 2018 22:04:33 +1300 Subject: [PATCH 03/11] chore: argggh fix the command count --- test/cli/commands.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/test/cli/commands.js b/test/cli/commands.js index 1fabdc857f..fd40d3d008 100644 --- a/test/cli/commands.js +++ b/test/cli/commands.js @@ -1,21 +1 @@ -/* eslint-env mocha */ -'use strict' - -const expect = require('chai').expect -const runOnAndOff = require('../utils/on-and-off') - const commandCount = 67 -describe('commands', () => runOnAndOff((thing) => { - let ipfs - - before(function () { - this.timeout(30 * 1000) - ipfs = thing.ipfs - }) - - it('list the commands', () => { - return ipfs('commands').then((out) => { - expect(out.split('\n')).to.have.length(commandCount + 1) - }) - }) -})) From d012abbe777a9e931f0fd95f0710fb3abd71e775 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Wed, 31 Jan 2018 22:07:45 +1300 Subject: [PATCH 04/11] chore: merge conflicts --- package.json | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/package.json b/package.json index 9878ce947f..506e677221 100644 --- a/package.json +++ b/package.json @@ -97,13 +97,19 @@ "byteman": "^1.3.5", "cids": "~0.5.2", "debug": "^3.1.0", +<<<<<<< HEAD "file-type": "^7.5.0", "filesize": "^3.6.0", +======= + "file-type": "^7.4.0", + "filesize": "^3.5.11", +>>>>>>> chore: merge conflicts "fsm-event": "^2.1.0", "get-folder-size": "^1.0.1", "glob": "^7.1.2", "hapi": "^16.6.2", "hapi-set-header": "^1.0.2", +<<<<<<< HEAD "hoek": "^5.0.3", "ipfs-api": "^18.0.0", "ipfs-bitswap": "~0.19.0", @@ -111,11 +117,21 @@ "ipfs-block-service": "~0.13.0", "ipfs-multipart": "~0.1.0", "ipfs-repo": "~0.18.7", +======= + "hoek": "^5.0.2", + "ipfs-api": "^17.3.0", + "ipfs-bitswap": "~0.18.0", + "ipfs-block": "~0.6.1", + "ipfs-block-service": "~0.13.0", + "ipfs-multipart": "~0.1.0", + "ipfs-repo": "~0.18.5", +>>>>>>> chore: merge conflicts "ipfs-unixfs": "~0.1.14", "ipfs-unixfs-engine": "~0.24.2", "ipld-resolver": "~0.14.1", "is-ipfs": "^0.3.2", "is-stream": "^1.1.0", +<<<<<<< HEAD "joi": "^13.1.2", "libp2p": "~0.16.5", "libp2p-circuit": "~0.1.4", @@ -129,21 +145,46 @@ "libp2p-tcp": "~0.11.5", "libp2p-webrtc-star": "~0.13.3", "libp2p-websocket-star": "~0.7.6", +======= + "joi": "^13.1.0", + "libp2p": "~0.15.0", + "libp2p-circuit": "~0.1.4", + "libp2p-floodsub": "~0.13.1", + "libp2p-kad-dht": "~0.6.0", + "libp2p-keychain": "~0.3.0", + "libp2p-mdns": "~0.9.2", + "libp2p-multiplex": "~0.5.1", + "libp2p-railing": "~0.7.1", + "libp2p-secio": "~0.9.0", + "libp2p-tcp": "~0.11.2", + "libp2p-webrtc-star": "~0.13.3", + "libp2p-websocket-star": "~0.7.2", +>>>>>>> chore: merge conflicts "libp2p-websockets": "~0.10.4", "lodash.flatmap": "^4.5.0", "lodash.get": "^4.4.2", "lodash.sortby": "^4.7.0", "lodash.values": "^4.3.0", +<<<<<<< HEAD "mafmt": "^4.0.0", +======= + "mafmt": "^3.0.2", +>>>>>>> chore: merge conflicts "mime-types": "^2.1.17", "mkdirp": "~0.5.1", "multiaddr": "^3.0.2", "multihashes": "~0.4.13", "once": "^1.4.0", "path-exists": "^3.0.0", +<<<<<<< HEAD "peer-book": "~0.5.4", "peer-id": "~0.10.6", "peer-info": "~0.11.6", +======= + "peer-book": "~0.5.2", + "peer-id": "~0.10.4", + "peer-info": "~0.11.4", +>>>>>>> chore: merge conflicts "progress": "^2.0.0", "promisify-es6": "^1.0.3", "pull-abortable": "^4.1.1", @@ -157,15 +198,24 @@ "pull-stream-to-stream": "^1.3.4", "pull-zip": "^2.0.1", "read-pkg-up": "^3.0.0", +<<<<<<< HEAD "readable-stream": "2.3.4", +======= + "readable-stream": "2.3.3", +>>>>>>> chore: merge conflicts "safe-buffer": "^5.1.1", "stream-to-pull-stream": "^1.7.2", "tar-stream": "^1.5.5", "temp": "~0.8.3", "through2": "^2.0.3", "update-notifier": "^2.3.0", +<<<<<<< HEAD "yargs": "^11.0.0", "yargs-parser": "^9.0.2" +======= + "yargs": "^10.1.1", + "yargs-parser": "^8.1.0" +>>>>>>> chore: merge conflicts }, "optionalDependencies": { "prom-client": "^10.2.2", From 315121a2deeab6b1ff3ee91b298a0f1918c1ac37 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Thu, 1 Feb 2018 09:49:35 +1300 Subject: [PATCH 05/11] chore: rebasing --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 506e677221..6d20578a9c 100644 --- a/package.json +++ b/package.json @@ -151,7 +151,6 @@ "libp2p-circuit": "~0.1.4", "libp2p-floodsub": "~0.13.1", "libp2p-kad-dht": "~0.6.0", - "libp2p-keychain": "~0.3.0", "libp2p-mdns": "~0.9.2", "libp2p-multiplex": "~0.5.1", "libp2p-railing": "~0.7.1", From de05349d8ae50dfc74f5b156f7306e8ca813d8eb Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Thu, 1 Feb 2018 10:13:23 +1300 Subject: [PATCH 06/11] chore: fix rebase errors --- package.json | 39 +++++---------------------------------- test/cli/commands.js | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index 6d20578a9c..8ff86c9a80 100644 --- a/package.json +++ b/package.json @@ -73,8 +73,13 @@ "form-data": "^2.3.2", "go-ipfs-dep": "^0.4.13", "hat": "0.0.3", +<<<<<<< HEAD "interface-ipfs-core": "~0.50.1", "ipfsd-ctl": "~0.28.0", +======= + "interface-ipfs-core": "~0.42.1", + "ipfsd-ctl": "~0.27.2", +>>>>>>> chore: fix rebase errors "left-pad": "^1.2.0", "lodash": "^4.17.5", "mocha": "^5.0.1", @@ -131,7 +136,6 @@ "ipld-resolver": "~0.14.1", "is-ipfs": "^0.3.2", "is-stream": "^1.1.0", -<<<<<<< HEAD "joi": "^13.1.2", "libp2p": "~0.16.5", "libp2p-circuit": "~0.1.4", @@ -145,45 +149,21 @@ "libp2p-tcp": "~0.11.5", "libp2p-webrtc-star": "~0.13.3", "libp2p-websocket-star": "~0.7.6", -======= - "joi": "^13.1.0", - "libp2p": "~0.15.0", - "libp2p-circuit": "~0.1.4", - "libp2p-floodsub": "~0.13.1", - "libp2p-kad-dht": "~0.6.0", - "libp2p-mdns": "~0.9.2", - "libp2p-multiplex": "~0.5.1", - "libp2p-railing": "~0.7.1", - "libp2p-secio": "~0.9.0", - "libp2p-tcp": "~0.11.2", - "libp2p-webrtc-star": "~0.13.3", - "libp2p-websocket-star": "~0.7.2", ->>>>>>> chore: merge conflicts "libp2p-websockets": "~0.10.4", "lodash.flatmap": "^4.5.0", "lodash.get": "^4.4.2", "lodash.sortby": "^4.7.0", "lodash.values": "^4.3.0", -<<<<<<< HEAD "mafmt": "^4.0.0", -======= - "mafmt": "^3.0.2", ->>>>>>> chore: merge conflicts "mime-types": "^2.1.17", "mkdirp": "~0.5.1", "multiaddr": "^3.0.2", "multihashes": "~0.4.13", "once": "^1.4.0", "path-exists": "^3.0.0", -<<<<<<< HEAD "peer-book": "~0.5.4", "peer-id": "~0.10.6", "peer-info": "~0.11.6", -======= - "peer-book": "~0.5.2", - "peer-id": "~0.10.4", - "peer-info": "~0.11.4", ->>>>>>> chore: merge conflicts "progress": "^2.0.0", "promisify-es6": "^1.0.3", "pull-abortable": "^4.1.1", @@ -197,24 +177,15 @@ "pull-stream-to-stream": "^1.3.4", "pull-zip": "^2.0.1", "read-pkg-up": "^3.0.0", -<<<<<<< HEAD "readable-stream": "2.3.4", -======= - "readable-stream": "2.3.3", ->>>>>>> chore: merge conflicts "safe-buffer": "^5.1.1", "stream-to-pull-stream": "^1.7.2", "tar-stream": "^1.5.5", "temp": "~0.8.3", "through2": "^2.0.3", "update-notifier": "^2.3.0", -<<<<<<< HEAD "yargs": "^11.0.0", "yargs-parser": "^9.0.2" -======= - "yargs": "^10.1.1", - "yargs-parser": "^8.1.0" ->>>>>>> chore: merge conflicts }, "optionalDependencies": { "prom-client": "^10.2.2", diff --git a/test/cli/commands.js b/test/cli/commands.js index fd40d3d008..50afc3240e 100644 --- a/test/cli/commands.js +++ b/test/cli/commands.js @@ -1 +1,21 @@ -const commandCount = 67 +/* eslint-env mocha */ +'use strict' + +const expect = require('chai').expect +const runOnAndOff = require('../utils/on-and-off') + +const commandCount = 68 +describe('commands', () => runOnAndOff((thing) => { + let ipfs + + before(function () { + this.timeout(30 * 1000) + ipfs = thing.ipfs + }) + + it('list the commands', () => { + return ipfs('commands').then((out) => { + expect(out.split('\n')).to.have.length(commandCount + 1) + }) + }) +})) From 48f37e20e30e052d868262657d65863127dabc59 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Thu, 1 Feb 2018 14:50:34 +1300 Subject: [PATCH 07/11] docs: add ipfs.shutdown --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cb3373644f..75c74ca409 100644 --- a/README.md +++ b/README.md @@ -329,6 +329,7 @@ A complete API definition is in the works. Meanwhile, you can learn how to you u - [miscellaneous operations](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/MISCELLANEOUS.md) - [`ipfs.id([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/MISCELLANEOUS.md#id) - [`ipfs.version([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/MISCELLANEOUS.md#version) + - [`ipfs.shutdown([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/MISCELLANEOUS.md#shutdown) - `ipfs.ping()` - `ipfs.init([options], callback)` - `ipfs.start([callback])` From 2c7f36b68a66f52a12fcb135fd8964e50630e41b Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Thu, 1 Feb 2018 14:53:42 +1300 Subject: [PATCH 08/11] fix: always report state error when stopping --- src/core/components/stop.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/core/components/stop.js b/src/core/components/stop.js index ad3957b546..b885d55537 100644 --- a/src/core/components/stop.js +++ b/src/core/components/stop.js @@ -23,10 +23,6 @@ module.exports = (self) => { callback() } - if (self.state.state() !== 'running') { - return done(new Error('Not able to stop from state: ' + self.state.state())) - } - self.state.stop() self._blockService.unsetExchange() self._bitswap.stop() From 8ecb1b4a1b8ea9edfbff7409a454e95cc12fc2b3 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Tue, 6 Feb 2018 19:56:40 +1300 Subject: [PATCH 09/11] chore: documentation is 'stop' not 'shutdown' --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 75c74ca409..e82d81d104 100644 --- a/README.md +++ b/README.md @@ -329,11 +329,10 @@ A complete API definition is in the works. Meanwhile, you can learn how to you u - [miscellaneous operations](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/MISCELLANEOUS.md) - [`ipfs.id([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/MISCELLANEOUS.md#id) - [`ipfs.version([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/MISCELLANEOUS.md#version) - - [`ipfs.shutdown([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/MISCELLANEOUS.md#shutdown) - `ipfs.ping()` - `ipfs.init([options], callback)` - `ipfs.start([callback])` - - `ipfs.stop([callback])` + - [`ipfs.stop([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/MISCELLANEOUS.md#stop) - `ipfs.isOnline()` - [config](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/CONFIG.md) From c710605085db63218cca891066e7740784d01f26 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Wed, 14 Feb 2018 12:51:27 +1300 Subject: [PATCH 10/11] fix: generic stop --- src/core/components/stop.js | 4 ++++ test/core/interface/generic.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/components/stop.js b/src/core/components/stop.js index b885d55537..a39900d09c 100644 --- a/src/core/components/stop.js +++ b/src/core/components/stop.js @@ -13,6 +13,10 @@ module.exports = (self) => { return callback(new Error('Already stopped')) } + if (self.state.state() !== 'running') { + return callback(new Error('Not able to stop from state: ' + self.state.state())) + } + const done = (err) => { if (err) { self.emit('error', err) diff --git a/test/core/interface/generic.js b/test/core/interface/generic.js index b1b4fcca72..2393eed5f0 100644 --- a/test/core/interface/generic.js +++ b/test/core/interface/generic.js @@ -26,7 +26,7 @@ const common = { }) }, teardown: function (callback) { - // Stopped by the tests themselves + // No need to stop, because the test suite does a 'stop' test. // parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) callback() } From 50c078adcdaf9f284aa8e2186532881c1b24a172 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 15 Feb 2018 10:25:00 +0100 Subject: [PATCH 11/11] fix: package.json --- package.json | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/package.json b/package.json index 8ff86c9a80..9878ce947f 100644 --- a/package.json +++ b/package.json @@ -73,13 +73,8 @@ "form-data": "^2.3.2", "go-ipfs-dep": "^0.4.13", "hat": "0.0.3", -<<<<<<< HEAD "interface-ipfs-core": "~0.50.1", "ipfsd-ctl": "~0.28.0", -======= - "interface-ipfs-core": "~0.42.1", - "ipfsd-ctl": "~0.27.2", ->>>>>>> chore: fix rebase errors "left-pad": "^1.2.0", "lodash": "^4.17.5", "mocha": "^5.0.1", @@ -102,19 +97,13 @@ "byteman": "^1.3.5", "cids": "~0.5.2", "debug": "^3.1.0", -<<<<<<< HEAD "file-type": "^7.5.0", "filesize": "^3.6.0", -======= - "file-type": "^7.4.0", - "filesize": "^3.5.11", ->>>>>>> chore: merge conflicts "fsm-event": "^2.1.0", "get-folder-size": "^1.0.1", "glob": "^7.1.2", "hapi": "^16.6.2", "hapi-set-header": "^1.0.2", -<<<<<<< HEAD "hoek": "^5.0.3", "ipfs-api": "^18.0.0", "ipfs-bitswap": "~0.19.0", @@ -122,15 +111,6 @@ "ipfs-block-service": "~0.13.0", "ipfs-multipart": "~0.1.0", "ipfs-repo": "~0.18.7", -======= - "hoek": "^5.0.2", - "ipfs-api": "^17.3.0", - "ipfs-bitswap": "~0.18.0", - "ipfs-block": "~0.6.1", - "ipfs-block-service": "~0.13.0", - "ipfs-multipart": "~0.1.0", - "ipfs-repo": "~0.18.5", ->>>>>>> chore: merge conflicts "ipfs-unixfs": "~0.1.14", "ipfs-unixfs-engine": "~0.24.2", "ipld-resolver": "~0.14.1",