2128 + service: Detect config file on service run correctly

Cose #2128

Squashed commit of the following:

commit cb7a58276fa97ac2e22bdbcb6d56c61415482e40
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Thu Sep 24 21:03:43 2020 +0300

    2128 + service: Detect config file on service run correctly
This commit is contained in:
Artem Baskal 2020-09-28 10:57:56 +03:00
parent 990f531f54
commit 8c411c4630
2 changed files with 14 additions and 7 deletions

View File

@ -147,13 +147,8 @@ func version() string {
// run is a blocking method!
// nolint
func run(args options) {
// config file path can be overridden by command-line arguments:
if args.configFilename != "" {
Context.configFilename = args.configFilename
} else {
// Default config file name
Context.configFilename = "AdGuardHome.yaml"
}
// configure config filename
initConfigFilename(args)
// configure working dir and config path
initWorkingDir(args)
@ -411,6 +406,16 @@ func writePIDFile(fn string) bool {
return true
}
func initConfigFilename(args options) {
// config file path can be overridden by command-line arguments:
if args.configFilename != "" {
Context.configFilename = args.configFilename
} else {
// Default config file name
Context.configFilename = "AdGuardHome.yaml"
}
}
// initWorkingDir initializes the workDir
// if no command-line arguments specified, we use the directory where our binary file is located
func initWorkingDir(args options) {

View File

@ -164,6 +164,8 @@ func handleServiceControlAction(opts options) {
log.Fatalf("Failed to run service: %s", err)
}
} else if action == "install" {
initConfigFilename(opts)
initWorkingDir(opts)
handleServiceInstallCommand(s)
} else if action == "uninstall" {
handleServiceUninstallCommand(s)