diff --git a/README.md b/README.md index 36384ab..2e8194c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ Requirements are: - Mod-SVN The SVNManager needs to be able to gracefully restart Apache after configuration files have been -created. This is done by invoking `sudo apache2ctl`, and requires that this command can be performed +created. This is done by invoking `sudo apache2ctl` (or its equivalent on the OS - for example, +apachectl when running on FreeBSD), and requires that this command can be performed without having to provide a password. Add the following to `/etc/sudoers` to set this up: Cmnd_Alias GRACEFUL = /usr/sbin/apache2ctl configtest, /usr/sbin/apache2ctl graceful diff --git a/apache/control.go b/apache/control.go index 1950e68..5573813 100644 --- a/apache/control.go +++ b/apache/control.go @@ -4,6 +4,7 @@ package apache import ( "context" "os/exec" + "runtime" "strings" "sync" "time" @@ -26,12 +27,22 @@ type Restarter interface { PerformRestart() } +func getApacheCtrl() string { + if runtime.GOOS == "freebsd" { + return "apachectl" + } + + return "apache2ctl" +} + func apachectl(subcmd string) (string, error) { deadline := time.Now().Add(10 * time.Second) ctx, cancelFunc := context.WithDeadline(context.Background(), deadline) defer cancelFunc() - cmd := exec.CommandContext(ctx, "sudo", "--non-interactive", "apache2ctl", subcmd) + apache2ctl := getApacheCtrl() + + cmd := exec.CommandContext(ctx, "sudo", "--non-interactive", apache2ctl, subcmd) output, err := cmd.CombinedOutput() return string(output), err }