github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/utils/syslog/cmd.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package syslog
     5  
     6  import (
     7  	"bytes"
     8  	"fmt"
     9  	"os"
    10  	"os/exec"
    11  )
    12  
    13  func Restart() error {
    14  	if os.Geteuid() == 0 {
    15  		return runCommand("restart", "rsyslog")
    16  	}
    17  	return fmt.Errorf("must be root")
    18  }
    19  
    20  func runCommand(args ...string) error {
    21  	out, err := exec.Command(args[0], args[1:]...).CombinedOutput()
    22  	if err == nil {
    23  		return nil
    24  	}
    25  	out = bytes.TrimSpace(out)
    26  	if len(out) > 0 {
    27  		return fmt.Errorf("exec %q: %v (%s)", args, err, out)
    28  	}
    29  	return fmt.Errorf("exec %q: %v", args, err)
    30  }