Pull request: 3868 imp service uninstall

Merge in DNS/adguard-home from 3868-imp-uninstall to master

Closes #3868.
Updates #3457.

Squashed commit of the following:

commit 6f50713407980c27e5b14bef4dc8839e134ec5c8
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Dec 27 19:06:13 2021 +0300

    all: imp openwrt

commit 59f058f8ec7f5ac8cb795bf837c396601652a6ff
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Dec 27 17:26:32 2021 +0300

    all: imp code && docs

commit bab95366b0ffa40d96de5bb8116ec14606e310ed
Merge: 92ebc210 52f36f20
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Dec 27 17:06:25 2021 +0300

    Merge branch 'master' into 3868-imp-uninstall

commit 92ebc210f04d5e02c3eef726017a0d5687f4bc4c
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Dec 27 13:18:58 2021 +0300

    home: imp freebsd script & log changes

commit 583ffc256e9f87cf19da2eca8bbefc9e00ea86cc
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Dec 16 14:08:46 2021 +0300

    all: imp service uninstall
This commit is contained in:
Eugene Burkov 2021-12-27 19:12:40 +03:00
parent 52f36f201e
commit 661f4ece48
4 changed files with 21 additions and 11 deletions

View File

@ -23,12 +23,14 @@ and this project adheres to
<!-- <!--
TODO(a.garipov): Remove this deprecation, if v0.108.0 is released before TODO(a.garipov): Remove this deprecation, if v0.108.0 is released before
that. the Go 1.18 release.
--> -->
- Go 1.17 support. v0.109.0 will require at least Go 1.18 to build. - Go 1.17 support. v0.109.0 will require at least Go 1.18 to build.
### Fixed ### 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 - Legacy DNS rewrites responding from upstream when a request other than `A` or
`AAAA` is received ([#4008]). `AAAA` is received ([#4008]).
- Panic on port availability check during installation ([#3987]). - Panic on port availability check during installation ([#3987]).
@ -38,6 +40,7 @@ and this project adheres to
- Go 1.16 support. - Go 1.16 support.
[#3057]: https://github.com/AdguardTeam/AdGuardHome/issues/3057 [#3057]: https://github.com/AdguardTeam/AdGuardHome/issues/3057
[#3868]: https://github.com/AdguardTeam/AdGuardHome/issues/3868
[#3987]: https://github.com/AdguardTeam/AdGuardHome/issues/3987 [#3987]: https://github.com/AdguardTeam/AdGuardHome/issues/3987
[#4008]: https://github.com/AdguardTeam/AdGuardHome/issues/4008 [#4008]: https://github.com/AdguardTeam/AdGuardHome/issues/4008

View File

@ -102,9 +102,9 @@ func sendSigReload() {
return return
} }
pidfile := fmt.Sprintf("/var/run/%s.pid", serviceName) pidFile := fmt.Sprintf("/var/run/%s.pid", serviceName)
var pid int var pid int
data, err := os.ReadFile(pidfile) data, err := os.ReadFile(pidFile)
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
if pid, err = aghos.PIDByCommand(serviceName, os.Getpid()); err != nil { if pid, err = aghos.PIDByCommand(serviceName, os.Getpid()); err != nil {
log.Error("service: finding AdGuardHome process: %s", err) log.Error("service: finding AdGuardHome process: %s", err)
@ -112,19 +112,19 @@ func sendSigReload() {
return return
} }
} else if err != nil { } 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 return
} else { } else {
parts := strings.SplitN(string(data), "\n", 2) parts := strings.SplitN(string(data), "\n", 2)
if len(parts) == 0 { 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 return
} }
if pid, err = strconv.Atoi(strings.TrimSpace(parts[0])); err != nil { 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 return
} }
@ -243,7 +243,7 @@ func handleServiceInstallCommand(s service.Service) {
if aghos.IsOpenWrt() { if aghos.IsOpenWrt() {
// On OpenWrt it is important to run enable after the service // 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. // startup.
_, err = runInitdCommand("enable") _, err = runInitdCommand("enable")
if err != nil { 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 { if err := svcAction(s, "uninstall"); err != nil {
log.Fatalf("service: executing action %q: %s", "uninstall", err) 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 // returns command code or error if any
func runInitdCommand(action string) (int, error) { func runInitdCommand(action string) (int, error) {
confPath := "/etc/init.d/" + serviceName confPath := "/etc/init.d/" + serviceName
// Pass the script and action as a single string argument.
code, _, err := aghos.RunCommand("sh", "-c", confPath+" "+action) code, _, err := aghos.RunCommand("sh", "-c", confPath+" "+action)
return code, err return code, err
} }
@ -579,9 +585,10 @@ const freeBSDScript = `#!/bin/sh
name="{{.Name}}" name="{{.Name}}"
{{.Name}}_env="IS_DAEMON=1" {{.Name}}_env="IS_DAEMON=1"
{{.Name}}_user="root" {{.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="/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" run_rc_command "$1"
` `

View File

@ -28,8 +28,7 @@ import (
// //
// TODO(e.burkov): Perhaps, file a PR to github.com/kardianos/service. // TODO(e.burkov): Perhaps, file a PR to github.com/kardianos/service.
// sysVersion is the version of local service.System interface // sysVersion is the version of local service.System interface implementation.
// implementation.
const sysVersion = "openbsd-runcom" const sysVersion = "openbsd-runcom"
func chooseSystem() { func chooseSystem() {

View File

@ -481,6 +481,7 @@ handle_existing() {
"to reinstall/uninstall the AdGuard Home using this script specify one of the '-r' or '-u' flags" "to reinstall/uninstall the AdGuard Home using this script specify one of the '-r' or '-u' flags"
fi fi
# TODO(e.burkov): Remove the stop once v0.107.1 released.
if ( cd "$agh_dir" && ! ./AdGuardHome -s stop || ! ./AdGuardHome -s uninstall ) if ( cd "$agh_dir" && ! ./AdGuardHome -s stop || ! ./AdGuardHome -s uninstall )
then then
# It doesn't terminate the script since it is possible # It doesn't terminate the script since it is possible