mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-18 10:06:26 +00:00
Add nginx exec
This commit is contained in:
13
backend/internal/nginx/control.go
Normal file
13
backend/internal/nginx/control.go
Normal file
@ -0,0 +1,13 @@
|
||||
package nginx
|
||||
|
||||
import "npm/internal/entity/host"
|
||||
|
||||
// ConfigureHost will attempt to write nginx conf and reload nginx
|
||||
func ConfigureHost(h host.Model) error {
|
||||
// nolint: errcheck, gosec
|
||||
h.Expand([]string{"certificate"})
|
||||
|
||||
// nolint: errcheck, gosec
|
||||
reloadNginx()
|
||||
return nil
|
||||
}
|
43
backend/internal/nginx/exec.go
Normal file
43
backend/internal/nginx/exec.go
Normal file
@ -0,0 +1,43 @@
|
||||
package nginx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
|
||||
"npm/internal/logger"
|
||||
)
|
||||
|
||||
func reloadNginx() error {
|
||||
_, err := shExec([]string{"-s", "reload"})
|
||||
return err
|
||||
}
|
||||
|
||||
func getNginxFilePath() (string, error) {
|
||||
path, err := exec.LookPath("nginx")
|
||||
if err != nil {
|
||||
return path, fmt.Errorf("Cannot find nginx execuatable script in PATH")
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
||||
// shExec executes nginx with arguments
|
||||
func shExec(args []string) (string, error) {
|
||||
ng, err := getNginxFilePath()
|
||||
if err != nil {
|
||||
logger.Error("NginxError", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
logger.Debug("CMD: %s %v", ng, args)
|
||||
// nolint: gosec
|
||||
c := exec.Command(ng, args...)
|
||||
|
||||
b, e := c.Output()
|
||||
|
||||
if e != nil {
|
||||
logger.Error("NginxError", fmt.Errorf("Command error: %s -- %v\n%+v", ng, args, e))
|
||||
logger.Warn(string(b))
|
||||
}
|
||||
|
||||
return string(b), e
|
||||
}
|
Reference in New Issue
Block a user