5

Unlike SIGINT it gives no output to console except "terminated". I tried it with testnet and it seemed ok. But is it safe to do so?

2
  • 1
  • 1
    Thank you @BadrBellaj. -HUP signal works fine, but it outputs "Hangup" instead of "Got interrupt, shutting down..., sync stopped..., db is closed.., etc." Does it mean it exits gracefully?
    – takeshi
    Dec 13, 2016 at 7:30

1 Answer 1

3

(I was wondering about this today... )

From the code, the safest and cleanest way to shut Geth down is using a SIGINT, either in the form of a CTRL+C, or by sending the signal directly to the process using kill -INT <pid>. Geth doesn't handle SIGTERMs in the same, clean way.

SIGTERMs and SIGHUPs do not lead to graceful shut down.

At various places in the code, Geth registers for notification of interrupt signals (i.e. SIGINTs):

    sigc := make(chan os.Signal, 1)
    signal.Notify(sigc, os.Interrupt)

Depending on what Geth is doing, it can then handle SIGINTs gracefully, for example:


Outside of Geth, there are examples where SIGTERMs are handled gracefully:

In the Swarm code, and, more importantly perhaps, in the C++ implementation, which registers the same exit handler for both SIGTERMs and SIGINTs in its main() function:

signal(SIGABRT, &ExitHandler::exitHandler);
signal(SIGTERM, &ExitHandler::exitHandler);
signal(SIGINT, &ExitHandler::exitHandler);
2
  • I tried to kill geth with SIGTERM and it seems it worked ok. The chain data remained valid and the node started again with no problems. I guess I was just lucky) AFAIU there is no handler for SIGTERM inside geth?
    – takeshi
    Feb 16, 2017 at 5:35
  • 1
    I think you were just lucky :) If your node had been part-way through writing a database record, or something similar, you would have likely ended up with corrupt chaindata. Inside Geth there don't appear to be any SIGTERM handlers, no. The underlying OS will be handling the signal and killing the process. Feb 16, 2017 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.