Пример #1
0
func Init(persist bool, pub push.Pusher) {
	cli := GetDockerClient()

	// setup service state change publisher
	if v := reflect.ValueOf(pub); !v.IsValid() || v.IsNil() {
		log.Warning("not publishing service status")
		report = &push.NullPusher{}
	} else {
		report = pub
	}

	// Advertise host URI
	Advertise, _, _ = net.SplitHostPort(disc.Advertise)

	if persist {
		if r, err := libkv.Load(DEFAULT_SYNC_PATH); err != nil {
			log.WithFields(log.Fields{"err": err}).Warning("load failed")
			rec = libkv.NewStore()
		} else {
			rec = r
		}
	} else {
		rec = libkv.NewStore()
	}

	containers, err := cli.ListContainers(docker.ListContainersOptions{All: true})
	if err != nil {
		log.WithFields(log.Fields{"err": err}).Warning(err)
		return
	}
	for _, c := range containers {
		NewContainerRecord(c.ID)
	}
}
Пример #2
0
func init() {
	RootContext, Cancel = ctx.WithCancel(ctx.Background())

	Store = libkv.NewStore()
}