From 8c411c463030e0188a27c85db5ad545ab442cce8 Mon Sep 17 00:00:00 2001 From: Artem Baskal Date: Mon, 28 Sep 2020 10:57:56 +0300 Subject: [PATCH] 2128 + service: Detect config file on service run correctly Cose #2128 Squashed commit of the following: commit cb7a58276fa97ac2e22bdbcb6d56c61415482e40 Author: ArtemBaskal Date: Thu Sep 24 21:03:43 2020 +0300 2128 + service: Detect config file on service run correctly --- home/home.go | 19 ++++++++++++------- home/service.go | 2 ++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/home/home.go b/home/home.go index 3c2dce58..10235664 100644 --- a/home/home.go +++ b/home/home.go @@ -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) { diff --git a/home/service.go b/home/service.go index b48c743b..fbe612cf 100644 --- a/home/service.go +++ b/home/service.go @@ -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)