func (d *deployer) deployUnit(wantedUnit *schema.Unit) error { currentUnit, err := d.fleetapi.Unit(wantedUnit.Name) if err != nil { return err } if currentUnit == nil { err := d.fleetapi.CreateUnit(wantedUnit) if err != nil { return err } return nil } wuf := schema.MapSchemaUnitOptionsToUnitFile(wantedUnit.Options) cuf := schema.MapSchemaUnitOptionsToUnitFile(currentUnit.Options) if wuf.Hash() != cuf.Hash() { log.Printf("INFO Service %s differs from the cluster version", wantedUnit.Name) wantedUnit.DesiredState = "inactive" err = d.fleetapi.DestroyUnit(wantedUnit.Name) if err != nil { return err } err = d.fleetapi.CreateUnit(wantedUnit) if err != nil { return err } } return nil }
func mapJobToSchema(j *job.Job) (*schema.Unit, error) { su := schema.Unit{ Name: j.Name, FileHash: j.Unit.Hash().String(), FileContents: encodeUnitContents(&j.Unit), TargetMachineID: j.TargetMachineID, } if j.State != nil { su.CurrentState = string(*(j.State)) } if j.UnitState != nil { su.Systemd = &schema.SystemdState{ LoadState: j.UnitState.LoadState, ActiveState: j.UnitState.ActiveState, SubState: j.UnitState.SubState, } if j.UnitState.MachineState != nil { su.Systemd.MachineID = j.UnitState.MachineState.ID } } if j.TargetState != nil { su.DesiredState = string(*j.TargetState) } return &su, nil }