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 - Mod-SVN
The SVNManager needs to be able to gracefully restart Apache after configuration files have been 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: 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 Cmnd_Alias GRACEFUL = /usr/sbin/apache2ctl configtest, /usr/sbin/apache2ctl graceful

View File

@ -4,6 +4,7 @@ package apache
import ( import (
"context" "context"
"os/exec" "os/exec"
"runtime"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -26,12 +27,22 @@ type Restarter interface {
PerformRestart() PerformRestart()
} }
func getApacheCtrl() string {
if runtime.GOOS == "freebsd" {
return "apachectl"
}
return "apache2ctl"
}
func apachectl(subcmd string) (string, error) { func apachectl(subcmd string) (string, error) {
deadline := time.Now().Add(10 * time.Second) deadline := time.Now().Add(10 * time.Second)
ctx, cancelFunc := context.WithDeadline(context.Background(), deadline) ctx, cancelFunc := context.WithDeadline(context.Background(), deadline)
defer cancelFunc() 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() output, err := cmd.CombinedOutput()
return string(output), err return string(output), err
} }