MCPcopy Create free account
hub / github.com/CPChain/chain / Stop

Method Stop

node/node.go:395–444  ·  view source on GitHub ↗

Stop terminates a running node along with all it's services. In the node was not started, an error is returned.

()

Source from the content-addressed store, hash-verified

393// Stop terminates a running node along with all it's services. In the node was
394// not started, an error is returned.
395func (n *Node) Stop() error {
396 n.lock.Lock()
397 defer n.lock.Unlock()
398
399 // Short circuit if the node's not running
400 if n.server == nil {
401 return ErrNodeStopped
402 }
403
404 // terminate the api, services and the p2p server.
405
406 n.stopRPC()
407 n.rpcAPIs = nil
408 failure := &StopError{
409 Services: make(map[reflect.Type]error),
410 }
411 for kind, service := range n.services {
412 if err := service.Stop(); err != nil {
413 failure.Services[kind] = err
414 }
415 }
416 n.server.Stop()
417 n.services = nil
418 n.server = nil
419
420 // Release instance directory lock.
421 if n.instanceDirLock != nil {
422 if err := n.instanceDirLock.Release(); err != nil {
423 n.log.Error("Can't release datadir lock", "err", err)
424 }
425 n.instanceDirLock = nil
426 }
427
428 // unblock n.Wait
429 close(n.quitCh)
430
431 // Remove the keystore if it was created ephemerally.
432 var keystoreErr error
433 if n.ephemeralKeystore != "" {
434 keystoreErr = os.RemoveAll(n.ephemeralKeystore)
435 }
436
437 if len(failure.Services) > 0 {
438 return failure
439 }
440 if keystoreErr != nil {
441 return keystoreErr
442 }
443 return nil
444}
445
446// Wait blocks the thread until the node is stopped. If the node is not running
447// at the time of invocation, the method immediately returns.

Callers 1

RestartMethod · 0.95

Calls 5

stopRPCMethod · 0.95
LockMethod · 0.80
UnlockMethod · 0.80
StopMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected