github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/deisctl/backend/fleet/rolling_restart.go (about)

     1  package fleet
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"sync"
     7  )
     8  
     9  // RollingRestart for instance units
    10  func (c *FleetClient) RollingRestart(component string, wg *sync.WaitGroup, out, ew io.Writer) {
    11  	if component != "router" {
    12  		fmt.Fprint(ew, "invalid component. supported for: router")
    13  		return
    14  	}
    15  
    16  	components, err := c.Units(component)
    17  	if err != nil {
    18  		io.WriteString(ew, err.Error())
    19  		return
    20  	}
    21  	if len(components) < 1 {
    22  		fmt.Fprint(ew, "rolling restart requires at least 1 component")
    23  		return
    24  	}
    25  	for num := range components {
    26  		unitName := fmt.Sprintf("%s@%v", component, num+1)
    27  
    28  		c.Stop([]string{unitName}, wg, out, ew)
    29  		wg.Wait()
    30  		c.Destroy([]string{unitName}, wg, out, ew)
    31  		wg.Wait()
    32  		c.Create([]string{unitName}, wg, out, ew)
    33  		wg.Wait()
    34  		c.Start([]string{unitName}, wg, out, ew)
    35  		wg.Wait()
    36  	}
    37  }