code: func (c *Cluster) Cleanup() {
  	c.controlMutex.Lock()
  	defer c.controlMutex.Unlock()
  
  	c.mu.Lock()
  	node := c.nr
  	if node == nil {
  		c.mu.Unlock()
  		return
  	}
  	state := c.currentNodeState()
  	c.mu.Unlock()
  
  	if state.IsActiveManager() {
  		active, reachable, unreachable, err := managerStats(state.controlClient, state.NodeID())
  		if err == nil {
  			singlenode := active && isLastManager(reachable, unreachable)
  			if active && !singlenode && removingManagerCausesLossOfQuorum(reachable, unreachable) {
  				logrus.Errorf("Leaving cluster with %v managers left out of %v. Raft quorum will be lost.", reachable-1, reachable+unreachable)
  			}
  		}
  	}
  
  	if err := node.Stop(); err != nil {
  		logrus.Errorf("failed to shut down cluster node: %v", err)
  		signal.DumpStacks("")
  	}
  
  	c.mu.Lock()
  	c.nr = nil
  	c.mu.Unlock()
  }
docs: // Cleanup stops active swarm node. This is run before daemon shutdown.