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?


(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);
  • 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 '17 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. – Richard Horrocks Feb 16 '17 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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