本文整理汇总了Golang中github.com/coreos/fleet/unit.UnitFile类的典型用法代码示例。如果您正苦于以下问题:Golang UnitFile类的具体用法?Golang UnitFile怎么用?Golang UnitFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UnitFile类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: storeOrGetUnitFile
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: Load
// 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
}
示例3: getUnitFromObjectNode
// getUnitFromObject takes a *etcd.Node containing a Unit's jobModel, and
// instantiates and returns a representative *job.Unit, transitively fetching the
// associated UnitFile as necessary
func (r *EtcdRegistry) getUnitFromObjectNode(node *etcd.Node) (*job.Unit, error) {
var err error
var jm jobModel
if err = unmarshal(node.Value, &jm); err != nil {
return nil, err
}
var unit *unit.UnitFile
// New-style Jobs should have a populated UnitHash, and the contents of the Unit are stored separately in the Registry
if !jm.UnitHash.Empty() {
unit = r.getUnitByHash(jm.UnitHash)
if unit == nil {
log.Warningf("No Unit found in Registry for Job(%s)", jm.Name)
return nil, nil
}
} else {
// Old-style Jobs had "Payloads" instead of Units, also stored separately in the Registry
unit, err = r.getUnitFromLegacyPayload(jm.Name)
if err != nil {
log.Errorf("Error retrieving legacy payload for Job(%s)", jm.Name)
return nil, nil
} else if unit == nil {
log.Warningf("No Payload found in Registry for Job(%s)", jm.Name)
return nil, nil
}
log.Infof("Migrating legacy Payload(%s)", jm.Name)
if err := r.storeOrGetUnitFile(*unit); err != nil {
log.Warningf("Unable to migrate legacy Payload: %v", err)
}
jm.UnitHash = unit.Hash()
log.Infof("Updating Job(%s) with legacy payload Hash(%s)", jm.Name, jm.UnitHash)
if err := r.updateJobObjectNode(&jm, node.ModifiedIndex); err != nil {
log.Warningf("Unable to update Job(%s) with legacy payload Hash(%s): %v", jm.Name, jm.UnitHash, err)
}
}
ju := &job.Unit{
Name: jm.Name,
Unit: *unit,
}
return ju, nil
}
示例4: Load
// 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: storeOrGetUnitFile
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: storeOrGetUnitFile
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
}