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?
-
1ethereum.stackexchange.com/questions/709/…– Badr Bellaj ♦Dec 8, 2016 at 9:04
-
1Thank 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?– takeshiDec 13, 2016 at 7:30
1 Answer
(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 SIGTERM
s in the same, clean way.
SIGTERM
s and SIGHUP
s do not lead to graceful shut down.
At various places in the code, Geth registers for notification of interrupt signals (i.e. SIGINT
s):
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt)
Depending on what Geth is doing, it can then handle SIGINT
s gracefully, for example:
- It can gracefully abort the import of chaindata, by calling
checkInterrupt()
before each block of data is imported. - If the interrupt happens early enough, the node can be shut down before anything meaty has happened at all.
Outside of Geth, there are examples where SIGTERM
s are handled gracefully:
In the Swarm code, and, more importantly perhaps, in the C++ implementation, which registers the same exit handler for both SIGTERM
s and SIGINT
s 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?– takeshiFeb 16, 2017 at 5:35
-
1I 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