diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cf589c1..f7a8e9f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,12 +23,14 @@ and this project adheres to - Go 1.17 support. v0.109.0 will require at least Go 1.18 to build. ### Fixed +- Service not being stopped before running the `uninstall` service action + ([#3868]). - Legacy DNS rewrites responding from upstream when a request other than `A` or `AAAA` is received ([#4008]). - Panic on port availability check during installation ([#3987]). @@ -38,6 +40,7 @@ and this project adheres to - Go 1.16 support. [#3057]: https://github.com/AdguardTeam/AdGuardHome/issues/3057 +[#3868]: https://github.com/AdguardTeam/AdGuardHome/issues/3868 [#3987]: https://github.com/AdguardTeam/AdGuardHome/issues/3987 [#4008]: https://github.com/AdguardTeam/AdGuardHome/issues/4008 diff --git a/internal/home/service.go b/internal/home/service.go index 4d003584..c2073e6c 100644 --- a/internal/home/service.go +++ b/internal/home/service.go @@ -102,9 +102,9 @@ func sendSigReload() { return } - pidfile := fmt.Sprintf("/var/run/%s.pid", serviceName) + pidFile := fmt.Sprintf("/var/run/%s.pid", serviceName) var pid int - data, err := os.ReadFile(pidfile) + data, err := os.ReadFile(pidFile) if errors.Is(err, os.ErrNotExist) { if pid, err = aghos.PIDByCommand(serviceName, os.Getpid()); err != nil { log.Error("service: finding AdGuardHome process: %s", err) @@ -112,19 +112,19 @@ func sendSigReload() { return } } else if err != nil { - log.Error("service: reading pid file %s: %s", pidfile, err) + log.Error("service: reading pid file %s: %s", pidFile, err) return } else { parts := strings.SplitN(string(data), "\n", 2) if len(parts) == 0 { - log.Error("service: parsing pid file %s: bad value", pidfile) + log.Error("service: parsing pid file %s: bad value", pidFile) return } if pid, err = strconv.Atoi(strings.TrimSpace(parts[0])); err != nil { - log.Error("service: parsing pid from file %s: %s", pidfile, err) + log.Error("service: parsing pid from file %s: %s", pidFile, err) return } @@ -243,7 +243,7 @@ func handleServiceInstallCommand(s service.Service) { if aghos.IsOpenWrt() { // On OpenWrt it is important to run enable after the service - // installation Otherwise, the service won't start on the system + // installation. Otherwise, the service won't start on the system // startup. _, err = runInitdCommand("enable") if err != nil { @@ -279,6 +279,10 @@ func handleServiceUninstallCommand(s service.Service) { } } + if err := svcAction(s, "stop"); err != nil { + log.Debug("service: executing action %q: %s", "stop", err) + } + if err := svcAction(s, "uninstall"); err != nil { log.Fatalf("service: executing action %q: %s", "uninstall", err) } @@ -341,7 +345,9 @@ func configureService(c *service.Config) { // returns command code or error if any func runInitdCommand(action string) (int, error) { confPath := "/etc/init.d/" + serviceName + // Pass the script and action as a single string argument. code, _, err := aghos.RunCommand("sh", "-c", confPath+" "+action) + return code, err } @@ -579,9 +585,10 @@ const freeBSDScript = `#!/bin/sh name="{{.Name}}" {{.Name}}_env="IS_DAEMON=1" {{.Name}}_user="root" -pidfile="/var/run/${name}.pid" +pidfile_child="/var/run/${name}.pid" +pidfile="/var/run/${name}_daemon.pid" command="/usr/sbin/daemon" -command_args="-p ${pidfile} -f -r {{.WorkingDirectory}}/{{.Name}}" +command_args="-P ${pidfile} -p ${pidfile_child} -f -r {{.WorkingDirectory}}/{{.Name}}" run_rc_command "$1" ` diff --git a/internal/home/service_openbsd.go b/internal/home/service_openbsd.go index be715edf..521e6287 100644 --- a/internal/home/service_openbsd.go +++ b/internal/home/service_openbsd.go @@ -28,8 +28,7 @@ import ( // // TODO(e.burkov): Perhaps, file a PR to github.com/kardianos/service. -// sysVersion is the version of local service.System interface -// implementation. +// sysVersion is the version of local service.System interface implementation. const sysVersion = "openbsd-runcom" func chooseSystem() { diff --git a/scripts/install.sh b/scripts/install.sh index dd0bcdab..078dc34b 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -481,6 +481,7 @@ handle_existing() { "to reinstall/uninstall the AdGuard Home using this script specify one of the '-r' or '-u' flags" fi + # TODO(e.burkov): Remove the stop once v0.107.1 released. if ( cd "$agh_dir" && ! ./AdGuardHome -s stop || ! ./AdGuardHome -s uninstall ) then # It doesn't terminate the script since it is possible