// Apply implements plan.Resource.
Apply implements plan.Resource.
// Apply implements plan . Resource .
func (p *Service) Apply(r plan.Runner, diff plan.Diff) (bool, error) {
	var err error
	var output string
	current := diff.CurrentState
	if !current.Bool("enabled") && p.Enabled {
		output, err = systemd(r, "enable %s", p.Name)
	} else if current.Bool("enabled") && !p.Enabled {
		output, err = systemd(r, "disable %s", p.Name)
	}
	if err != nil {
		return false, fmt.Errorf("%s: %s", output, err.Error())
	}
	if p.Status == ServiceActive && current.String("status") == "inactive" {
		output, err = systemd(r, "start %s", p.Name)
	} else if p.Status == ServiceInactive && current.String("status") != "inactive" {
		output, err = systemd(r, "stop %s", p.Name)
	}
	if err != nil {
		return false, fmt.Errorf("%s: %s", output, err.Error())
	}
	return true, nil
}
func ( p * Service ) Apply ( r plan . Runner , diff plan . Diff ) ( bool , error ) { var err error var output string current := diff . CurrentState if ! current . Bool ( " " ) && p . Enabled { output , err = systemd ( r , " " , p . Name ) } else if current . Bool ( " " ) && ! p . Enabled { output , err = systemd ( r , " " , p . Name ) } if err != nil { return false , fmt . Errorf ( " " , output , err . Error ( ) ) } if p . Status == ServiceActive && current . String ( " " ) == " " { output , err = systemd ( r , " " , p . Name ) } else if p . Status == ServiceInactive && current . String ( " " ) != " " { output , err = systemd ( r , " " , p . Name ) } if err != nil { return false , fmt . Errorf ( " " , output , err . Error ( ) ) } return true , nil }
Apply implements plan.Resource.
Apply implements plan . Resource .
// Enabled // Active // XXX: We need to think about what happens when a unit is in failed status // (current["status"] is "failed").