feat: if running as a service set workdir to /var/lib/AdGuardHome
Fixes issue where the service would write the data dir into /usr/bin if the binary was within /usr/bin
This commit is contained in:
parent
c0a5e389d9
commit
60177cebf2
|
@ -748,7 +748,6 @@ func writePIDFile(fn string) bool {
|
|||
// initConfigFilename sets up context config file path. This file path can be
|
||||
// overridden by command-line arguments, or is set to default.
|
||||
func initConfigFilename(opts options) {
|
||||
// TODO: if running as service the config location should be /etc/AdGuardHome/AdGuardHome.yaml
|
||||
Context.configFilename = stringutil.Coalesce(opts.confFilename, "AdGuardHome.yaml")
|
||||
}
|
||||
|
||||
|
@ -761,11 +760,18 @@ func initWorkingDir(opts options) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
// TODO: if running as a service use /var/lib/AdGuardHome
|
||||
|
||||
if opts.workDir != "" {
|
||||
// If there is a custom config file, use it's directory as our working dir
|
||||
Context.workDir = opts.workDir
|
||||
} else if !execDirAvaliable() {
|
||||
// If running as a service and from /usr/bin/ use /var/lib for working dir instead of
|
||||
// /usr/bin/data
|
||||
Context.workDir = "/var/lib/AdGuardHome"
|
||||
|
||||
// Create dir if it does not already exist
|
||||
if err := os.MkdirAll(Context.workDir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
Context.workDir = filepath.Dir(execPath)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -729,3 +730,12 @@ func secureBinaryUnix() error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// execDirAvaliable returns true if the executable's current folder is avaliable to be
|
||||
// used as a workDir.
|
||||
// If AdGuardHome is running as a service, it should not use the binary's location as a
|
||||
// workDir, thus this function will return false.
|
||||
func execDirAvaliable() bool {
|
||||
// If installed in /usr/bin do not use /usr/bin/data to store files
|
||||
return filepath.Dir(os.Args[0]) != "/usr/bin"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue