mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-25 06:25:44 +03:00
d8d7a5c335
Merge in DNS/adguard-home from 5191-update-flag to master
Updates #5191.
Updates #4223.
Squashed commit of the following:
commit fbace4942844dc67f2467479385e06843c3abb6a
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Mon Jan 9 12:05:16 2023 +0400
all: imp code, docs
commit 8237dceb771ba95f545f79565d76cbb4ebd0d805
Merge: ca9518f2 bbdcc673
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Fri Dec 30 14:45:55 2022 +0400
Merge branch 'master' into 5191-update-flag
commit ca9518f20e5643572adf9734b93a5436ba30c865
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Dec 29 20:36:33 2022 +0400
home: imp code
commit 1dc6c7c3480df3df4a5f3f923f1feab7761a7945
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Dec 29 18:26:08 2022 +0400
all: imp code, docs
commit 7bbe893e98063b956482fd6f1c6be95a4f1956cf
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Dec 29 03:44:48 2022 +0400
home: restart service on update
commit e0d3c287a7e1c05b1e397f4727c447a1fcd9f7f6
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Dec 29 03:22:49 2022 +0400
all: update on first run
commit 0aa4e78f03bf3819425accb468ce59e747506ef3
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Dec 29 02:47:30 2022 +0400
all: move some code to init less
commit 68aebfa050b9965afef26653e9b699ff4aaf5b8b
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Dec 29 00:36:00 2022 +0400
WIP
commit 2c7fb97d701ac158613c5a3a4d4d35c5b79b3d59
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Wed Dec 28 14:15:59 2022 +0400
home: imp logs
commit 4b06d089da835d6d187803bbb5ca1caf9973e2d3
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Dec 27 19:21:17 2022 +0400
all: fix update flag
84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
//go:build linux
|
|
|
|
package home
|
|
|
|
import (
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
|
"github.com/kardianos/service"
|
|
)
|
|
|
|
// chooseSystem checks the current system detected and substitutes it with local
|
|
// implementation if needed.
|
|
func chooseSystem() {
|
|
sys := service.ChosenSystem()
|
|
// By default, package service uses the SysV system if it cannot detect
|
|
// anything other, but the update-rc.d fix should not be applied on OpenWrt,
|
|
// so exclude it explicitly.
|
|
//
|
|
// See https://github.com/AdguardTeam/AdGuardHome/issues/4480 and
|
|
// https://github.com/AdguardTeam/AdGuardHome/issues/4677.
|
|
if sys.String() == "unix-systemv" && !aghos.IsOpenWrt() {
|
|
service.ChooseSystem(sysvSystem{System: sys})
|
|
}
|
|
}
|
|
|
|
// sysvSystem is a wrapper for service.System that wraps the service.Service
|
|
// while creating a new one.
|
|
//
|
|
// TODO(e.burkov): File a PR to github.com/kardianos/service.
|
|
type sysvSystem struct {
|
|
// System is expected to have an unexported type
|
|
// *service.linuxSystemService.
|
|
service.System
|
|
}
|
|
|
|
// New returns a wrapped service.Service.
|
|
func (sys sysvSystem) New(i service.Interface, c *service.Config) (s service.Service, err error) {
|
|
s, err = sys.System.New(i, c)
|
|
if err != nil {
|
|
return s, err
|
|
}
|
|
|
|
return sysvService{
|
|
Service: s,
|
|
name: c.Name,
|
|
}, nil
|
|
}
|
|
|
|
// sysvService is a wrapper for a service.Service that also calls update-rc.d in
|
|
// a proper way on installing and uninstalling.
|
|
type sysvService struct {
|
|
// Service is expected to have an unexported type *service.sysv.
|
|
service.Service
|
|
// name stores the name of the service to call updating script with it.
|
|
name string
|
|
}
|
|
|
|
// Install wraps service.Service.Install call with calling the updating script.
|
|
func (svc sysvService) Install() (err error) {
|
|
err = svc.Service.Install()
|
|
if err != nil {
|
|
// Don't wrap an error since it's informative enough as is.
|
|
return err
|
|
}
|
|
|
|
_, _, err = aghos.RunCommand("update-rc.d", svc.name, "defaults")
|
|
|
|
// Don't wrap an error since it's informative enough as is.
|
|
return err
|
|
}
|
|
|
|
// Uninstall wraps service.Service.Uninstall call with calling the updating
|
|
// script.
|
|
func (svc sysvService) Uninstall() (err error) {
|
|
err = svc.Service.Uninstall()
|
|
if err != nil {
|
|
// Don't wrap an error since it's informative enough as is.
|
|
return err
|
|
}
|
|
|
|
_, _, err = aghos.RunCommand("update-rc.d", svc.name, "remove")
|
|
|
|
// Don't wrap an error since it's informative enough as is.
|
|
return err
|
|
}
|