Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

[proposal] Allow graceful programmatic shutdown #1192

Closed
dryajov opened this issue Jan 26, 2018 · 4 comments
Closed

[proposal] Allow graceful programmatic shutdown #1192

dryajov opened this issue Jan 26, 2018 · 4 comments

Comments

@dryajov
Copy link
Member

dryajov commented Jan 26, 2018

It's currently not possible to programmatically do a graceful shutdown of ipfs daemons on windows through the use of signals, the way it's done on Unix like systems - due to windows lack of signal support. From Node.js documentation - https://nodejs.org/api/process.html#process_signal_events.

This is an issue for applications that try to interact with the daemons programmatically such as ipfsd-ctl, since sending a SIGINT to any process will not trigger a signal handler, but simply kill the process, which in turn leaves the repo locked and possibly in an inconsistent state.

One possible solution would be to add some sort of explicit shutdown command (ipfsd shutdown) - that would shutdown the daemon. So far, I think this can be implemented either as an additional HTTP endpoint or by the presence of a 0 byte file at the root of the repo:

i.e.

  • /api/v0/shutdown resource - when calling the endpoint, the daemon responds with a 200 or 202 HTTP response code and beggins the shutdown of the daemon
  • .jsipfs/shutdown file - the daemon monitors the repo for the presence of this file, if its there, it will delete the file and initiate the daemon shutdown

This is just a suggestion, and if there are better/cleaner ways of achieving this, I'd love to hear about them.

Note that anything we do here, would also have to be done in the go implementation, since it affects both daemon types - // cc - @whyrusleeping @lgierth @Stebalien

@dryajov dryajov changed the title [proposal] Allow graceful programmatic shutdown on windows [proposal] Allow graceful programmatic shutdown Jan 26, 2018
@richardschneider
Copy link
Contributor

@dryajov The docs already mention the shutdown endpoint.

IMHO, js-ipfs should implement it and then ipfsd-ctl can just call it, instead of using *nix signals.

@dryajov
Copy link
Member Author

dryajov commented Jan 26, 2018

@richardschneider thanks for finding that, however I don't see this endpoint anywhere in js-ipfs, perhaps it is implemented in go only - in which case we should simply implement it in js.

@mkg20001
Copy link
Contributor

Seems like on win10 SIGINT suddenly started to "just work" https://stackoverflow.com/a/45369603/3990041

@dryajov
Copy link
Member Author

dryajov commented Jan 28, 2018

@mkg20001 hehe - yes, node correctly emulates SIGINT when using the cmd.

From the docs:

SIGINT from the terminal is supported on all platforms, and can usually be generated with <Ctrl>+C (though this may be configurable). It is not generated when terminal raw mode is enabled.

It's when using process.kill('SIGINT') that the signal emulation degrades to killing the process immediately.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants