Use apachectl on FreeBSD #3

Merged
Francesco Siddi merged 1 commits from Sergey/svn-manager:freebsd_apachectl into main 2023-05-13 19:29:25 +02:00
2 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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
}