code: func (n *Node) Stop() error {
  	n.lock.Lock()
  	defer n.lock.Unlock()
  
  	// Short circuit if the node's not running
  	if n.server == nil {
  		return ErrNodeStopped
  	}
  
  	// Terminate the API, services and the p2p server.
  	n.stopWS()
  	n.stopHTTP()
  	n.stopIPC()
  	n.rpcAPIs = nil
  	failure := &StopError{
  		Services: make(map[reflect.Type]error),
  	}
  	for kind, service := range n.services {
  		if err := service.Stop(); err != nil {
  			failure.Services[kind] = err
  		}
  	}
  	n.server.Stop()
  	n.services = nil
  	n.server = nil
  
  	// Release instance directory lock.
  	if n.instanceDirLock != nil {
  		if err := n.instanceDirLock.Release(); err != nil {
  			n.log.Error("Can't release datadir lock", "err", err)
  		}
  		n.instanceDirLock = nil
  	}
  
  	// unblock n.Wait
  	close(n.stop)
  
  	// Remove the keystore if it was created ephemerally.
  	var keystoreErr error
  	if n.ephemeralKeystore != "" {
  		keystoreErr = os.RemoveAll(n.ephemeralKeystore)
  	}
  
  	if len(failure.Services) > 0 {
  		return failure
  	}
  	if keystoreErr != nil {
  		return keystoreErr
  	}
  	return nil
  }
docs: // Stop terminates a running node along with all it's services. In the node was
  // not started, an error is returned.