From 18b6d9fe5415a807352b82b8a00718515b2db317 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sat, 13 May 2023 18:54:44 +0200 Subject: [PATCH] Use apachectl on FreeBSD The native tool is called `apachectl` and not `apache2ctl`. --- README.md | 3 ++- apache/control.go | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) 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 } -- 2.30.2