Example #1
0
func SetVips(vips []core.Vip) error {
	// in case of failure
	oldVips, err := database.GetVips()
	if err != nil {
		return err
	}

	// apply vips to vipmgr
	err = vipmgr.SetVips(vips)
	if err != nil {
		return err
	}

	if !database.CentralStore {
		// save to backend
		err = database.SetVips(vips)
		if err != nil {
			// undo vipmgr action
			if uerr := vipmgr.SetVips(oldVips); uerr != nil {
				err = fmt.Errorf("%v - %v", err.Error(), uerr.Error())
			}
			return err
		}
	}
	return nil
}
Example #2
0
func sigHandle() {
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
	go func() {
		switch <-sigs {
		default:
			// clear balancer rules - (stop balancing if we are offline)
			balance.SetServices(make([]core.Service, 0, 0))
			// clear vips
			vipmgr.SetVips(make([]core.Vip, 0, 0))
			fmt.Println()
			os.Exit(0)
		}
	}()
}