mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-10-25 12:53:34 +00:00
Baked acme.sh into binary and use it when required, removed docker healthcheck
This commit is contained in:
63
backend/internal/acme/acmesh.go
Normal file
63
backend/internal/acme/acmesh.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package acme
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"npm/embed"
|
||||
"npm/internal/config"
|
||||
"npm/internal/logger"
|
||||
)
|
||||
|
||||
var acmeShFile string
|
||||
|
||||
// GetAcmeShVersion will return the acme.sh script version
|
||||
func GetAcmeShVersion() string {
|
||||
if r, err := acmeShExec("--version"); err == nil {
|
||||
// modify the output
|
||||
r = strings.Trim(r, "\n")
|
||||
v := strings.Split(r, "\n")
|
||||
return v[len(v)-1]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func acmeShExec(args ...string) (string, error) {
|
||||
if _, err := os.Stat(acmeShFile); os.IsNotExist(err) {
|
||||
e := fmt.Errorf("%s does not exist", acmeShFile)
|
||||
logger.Error("AcmeShError", e)
|
||||
return "", e
|
||||
}
|
||||
|
||||
// nolint: gosec
|
||||
c := exec.Command(acmeShFile, args...)
|
||||
b, e := c.Output()
|
||||
|
||||
if e != nil {
|
||||
logger.Error("AcmeShError", fmt.Errorf("Command error: %s -- %v\n%+v", acmeShFile, args, e))
|
||||
logger.Warn(string(b))
|
||||
}
|
||||
|
||||
return string(b), e
|
||||
}
|
||||
|
||||
// WriteAcmeSh this will write our embedded acme.sh script to the data directory
|
||||
// and give it write permissions
|
||||
func WriteAcmeSh() {
|
||||
if config.Configuration.DataFolder == "" {
|
||||
logger.Error("AcmeShWriteError", fmt.Errorf("Configuration folder location is not set"))
|
||||
return
|
||||
}
|
||||
|
||||
acmeShFile = filepath.Clean(fmt.Sprintf("%s/acme.sh", config.Configuration.DataFolder))
|
||||
// nolint: gosec
|
||||
if err := ioutil.WriteFile(acmeShFile, []byte(embed.AcmeSh), 0755); err != nil {
|
||||
logger.Error("AcmeShWriteError", err)
|
||||
} else {
|
||||
logger.Info("Wrote %s", acmeShFile)
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"npm/internal/acme"
|
||||
h "npm/internal/api/http"
|
||||
"npm/internal/config"
|
||||
)
|
||||
@@ -9,6 +10,7 @@ import (
|
||||
type healthCheckResponse struct {
|
||||
Version string `json:"version"`
|
||||
Commit string `json:"commit"`
|
||||
AcmeShVersion string `json:"acme.sh"`
|
||||
Healthy bool `json:"healthy"`
|
||||
IsSetup bool `json:"setup"`
|
||||
ErrorReporting bool `json:"error_reporting"`
|
||||
@@ -23,6 +25,7 @@ func Health() func(http.ResponseWriter, *http.Request) {
|
||||
Commit: config.Commit,
|
||||
Healthy: true,
|
||||
IsSetup: config.IsSetup,
|
||||
AcmeShVersion: acme.GetAcmeShVersion(),
|
||||
ErrorReporting: config.ErrorReporting,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user