Skip to content

Commit

Permalink
2128 + service: Detect config file on service run correctly
Browse files Browse the repository at this point in the history
Cose #2128

Squashed commit of the following:

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

    2128 + service: Detect config file on service run correctly
  • Loading branch information
ArtemBaskal committed Sep 28, 2020
1 parent 990f531 commit 8c411c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 12 additions & 7 deletions home/home.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions home/service.go
Expand Up @@ -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)
Expand Down

0 comments on commit 8c411c4

Please sign in to comment.