Exemple #1
0
func (f *File) Run() error {
	// XXX : acquire/release lock
	if f.Ensure == haiconf.ENSURE_ABSENT {
		haiconf.Output(f.rc, "Removing file %s", f.Path)
		return os.Remove(f.Path)
	}

	err := MkDir(path.Dir(f.Path), true, 0755)
	if err != nil {
		return err
	}

	haiconf.Output(f.rc, "Creating file %s", f.Path)
	err = f.storeFile()
	if err != nil {
		return err
	}

	haiconf.Output(f.rc, "Chmod %s on %s", f.Mode, f.Path)
	err = Chmod(f.Path, f.Mode)
	if err != nil {
		return err
	}

	haiconf.Output(f.rc, "Chown %s:%s on %s", f.Owner.Username, f.Group.Name, f.Path)
	err = Chown(f.Path, f.Owner, f.Group)
	if err != nil {
		return err
	}

	return nil
}
Exemple #2
0
func (d *Directory) Run() error {
	// XXX : acquire/release lock
	if d.Ensure == haiconf.ENSURE_ABSENT {
		haiconf.Output(d.rc, "Removing directory %s", d.Path)
		return RmDir(d.Path, d.Recurse)
	}

	haiconf.Output(d.rc, "Creating directory %s", d.Path)
	err := MkDir(d.Path, d.Recurse, d.Mode)
	if err != nil {
		return err
	}

	haiconf.Output(d.rc, "Chmod %s on %s", d.Mode, d.Path)
	err = Chmod(d.Path, d.Mode)
	if err != nil {
		return err
	}

	haiconf.Output(d.rc, "Chown %s:%s on %s", d.Owner.Username, d.Group.Name, d.Path)
	err = Chown(d.Path, d.Owner, d.Group)
	if err != nil {
		return err
	}

	return nil
}
Exemple #3
0
func (g *Group) Run() error {
	if g.action == ACTION_NOOP {
		return nil
	}

	mgr := NewGroupManager()
	mgr.Name = g.Name

	if g.Ensure == haiconf.ENSURE_PRESENT {
		haiconf.Output(g.rc, "Adding group %s", g.Name)
		return mgr.Add()
	}

	haiconf.Output(g.rc, "Removing group %s", g.Name)
	return mgr.Remove()
}
Exemple #4
0
func (c *Cron) Run() error {
	cj := Cronjob{
		Schedule: c.Schedule,
		Command:  c.Command,
		Env:      c.Env,
	}

	ct := NewCrontab(c.Owner)

	if c.Ensure == haiconf.ENSURE_PRESENT {
		haiconf.Output(c.rc, "Adding cronjob %s for user %s", cj.Command, c.Owner.Username)
		return ct.Add(cj)
	}

	haiconf.Output(c.rc, "Removing cronjob %s for user %s", cj.Command, c.Owner.Username)
	return ct.Remove(cj)
}
Exemple #5
0
func (h *HttpGet) Run() error {
	haiconf.Output(h.rc, "Downloading %s to %s", h.From, h.To)

	resp, err := http.Get(h.From)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	buff, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}

	f, err := os.Create(h.To)
	if err != nil {
		return err
	}

	f.Write(buff)
	return f.Close()
}
Exemple #6
0
func (t *TarGz) Run() error {
	haiconf.Output(t.rc, "Archiving %s to %s", t.Source, t.Dest)

	return tarGz(t.Source, t.Dest)
}
Exemple #7
0
func (t *UnTarGz) Run() error {
	haiconf.Output(t.rc, "Extracting %s to %s", t.Source, t.Dest)

	return unTarGz(t.Source, t.Dest)
}