示例#1
0
func (m *Manager) Stop() error {
	// custom event to signal shutdown
	evt := &dockerclient.Event{
		Id:     "",
		Status: "interlock-stop",
		From:   "interlock",
		Time:   time.Now().UnixNano(),
	}
	plugins.DispatchEvent(m.Config, m.Client, evt, eventsErrChan)
	return nil
}
示例#2
0
func (m *Manager) Run() error {
	if err := m.connect(); err != nil {
		return err
	}

	go func() {
		for {
			err := <-eventsErrChan
			log.Error(err)
		}
	}()

	// plugins
	allPlugins := plugins.GetPlugins()
	if len(allPlugins) == 0 || len(m.Config.EnabledPlugins) == 0 {
		log.Warnf("no plugins enabled")
	}

	enabledPlugins := make(map[string]*plugins.RegisteredPlugin)

	for _, v := range m.Config.EnabledPlugins {
		if p, ok := allPlugins[v]; ok {
			log.Infof("loading plugin name=%s version=%s",
				p.Info().Name,
				p.Info().Version)
			enabledPlugins[v] = p
		}
	}

	plugins.SetEnabledPlugins(enabledPlugins)

	// custom event to signal startup
	evt := &dockerclient.Event{
		Id:     "",
		Status: "interlock-start",
		From:   "interlock",
		Time:   time.Now().UnixNano(),
	}
	plugins.DispatchEvent(m.Config, m.Client, evt, eventsErrChan)
	return nil
}
示例#3
0
// Handle sends events on to the Manager
func (l *EventHandler) Handle(e *dockerclient.Event, ec chan error, args ...interface{}) {
	plugins.Log("interlock", log.DebugLevel,
		fmt.Sprintf("event: date=%d type=%s image=%s container=%s", e.Time, e.Status, e.From, e.Id))

	go plugins.DispatchEvent(l.Manager.Config, l.Manager.Client, e, ec)
}