Пример #1
0
Файл: unit.go Проект: pulcy/j2
func (r *EtcdRegistry) storeOrGetUnitFile(u unit.UnitFile) (err error) {
	um := unitModel{
		Raw: u.String(),
	}

	val, err := marshal(um)
	if err != nil {
		return err
	}

	key := r.hashedUnitPath(u.Hash())
	opts := &etcd.SetOptions{
		PrevExist: etcd.PrevNoExist,
	}
	start := time.Now()
	_, err = r.kAPI.Set(context.Background(), key, val, opts)
	// unit is already stored
	if isEtcdError(err, etcd.ErrorCodeNodeExist) {
		// TODO(jonboulle): verify more here?
		err = nil
	}
	if err != nil {
		metrics.ReportRegistryOpFailure(metrics.Set)
		return
	}
	metrics.ReportRegistryOpSuccess(metrics.Set, start)
	return
}
Пример #2
0
// Load writes the given Unit to disk, subscribing to relevant dbus
// events and caching the Unit's Hash.
func (m *systemdUnitManager) Load(name string, u unit.UnitFile) error {
	m.mutex.Lock()
	defer m.mutex.Unlock()
	err := m.writeUnit(name, u.String())
	if err != nil {
		return err
	}
	m.hashes[name] = u.Hash()
	return nil
}
Пример #3
0
// Load writes the given Unit to disk, subscribing to relevant dbus
// events, caching the Unit's Hash, and, if necessary, instructing the systemd
// daemon to reload.
func (m *systemdUnitManager) Load(name string, u unit.UnitFile) error {
	m.mutex.Lock()
	defer m.mutex.Unlock()
	err := m.writeUnit(name, u.String())
	if err != nil {
		return err
	}
	m.hashes[name] = u.Hash()
	if m.unitRequiresDaemonReload(name) {
		return m.daemonReload()
	}
	return nil
}
Пример #4
0
// Load writes the given Unit to disk, subscribing to relevant dbus
// events and caching the Unit's Hash.
func (m *systemdUnitManager) Load(name string, u unit.UnitFile) error {
	m.mutex.Lock()
	defer m.mutex.Unlock()
	err := m.writeUnit(name, u.String())
	if err != nil {
		return err
	}
	if _, exists := u.Contents["Install"]; exists {
		log.Debugf("Detected [Install] section in the systemd unit (%s)", name)
		ok, err := m.enableUnit(name)
		if err != nil || !ok {
			m.removeUnit(name)
			return fmt.Errorf("Failed to enable systemd unit %s: %v", name, err)
		}
	}
	m.hashes[name] = u.Hash()
	return nil
}
Пример #5
0
func (r *EtcdRegistry) storeOrGetUnitFile(u unit.UnitFile) (err error) {
	um := unitModel{
		Raw: u.String(),
	}

	val, err := marshal(um)
	if err != nil {
		return err
	}

	key := r.hashedUnitPath(u.Hash())
	opts := &etcd.SetOptions{
		PrevExist: etcd.PrevNoExist,
	}
	_, err = r.kAPI.Set(r.ctx(), key, val, opts)
	// unit is already stored
	if isEtcdError(err, etcd.ErrorCodeNodeExist) {
		// TODO(jonboulle): verify more here?
		err = nil
	}
	return
}
Пример #6
0
func (r *EtcdRegistry) storeOrGetUnitFile(u unit.UnitFile) (err error) {
	um := unitModel{
		Raw: u.String(),
	}

	json, err := marshal(um)
	if err != nil {
		return err
	}

	req := etcd.Create{
		Key:   r.hashedUnitPath(u.Hash()),
		Value: json,
	}
	_, err = r.etcd.Do(&req)
	// unit is already stored
	if err != nil && isNodeExist(err) {
		// TODO(jonboulle): verify more here?
		err = nil
	}
	return
}