From 8432593be1fbdb174e7ac5636cb0eee11136cf5f Mon Sep 17 00:00:00 2001 From: Dimitry Kolyshev Date: Fri, 14 Jun 2024 12:32:19 +0300 Subject: [PATCH 1/2] Pull request: AG-33410-aghos-err Merge in DNS/adguard-home from AG-33410-aghos-err to master Squashed commit of the following: commit 6014ea1e919ea685475561e4a46284847f67ac99 Author: Dimitry Kolyshev Date: Fri Jun 14 08:30:30 2024 +0300 all: imp code commit 232b207d8da42dad297f2730c42e5e84f9049ab9 Author: Dimitry Kolyshev Date: Thu Jun 13 12:18:41 2024 +0300 all: rm aghos unsupported err --- internal/aghos/os.go | 20 ++------------------ internal/dnsforward/ipset.go | 3 +-- internal/home/home.go | 2 +- internal/ipset/ipset.go | 4 ++-- 4 files changed, 6 insertions(+), 23 deletions(-) diff --git a/internal/aghos/os.go b/internal/aghos/os.go index e04055e4..f2933a98 100644 --- a/internal/aghos/os.go +++ b/internal/aghos/os.go @@ -19,25 +19,9 @@ import ( "github.com/AdguardTeam/golibs/log" ) -// UnsupportedError is returned by functions and methods when a particular -// operation Op cannot be performed on the current OS. -type UnsupportedError struct { - Op string - OS string -} - -// Error implements the error interface for *UnsupportedError. -func (err *UnsupportedError) Error() (msg string) { - return fmt.Sprintf("%s is unsupported on %s", err.Op, err.OS) -} - -// Unsupported is a helper that returns an *UnsupportedError with the Op field -// set to op and the OS field set to the current OS. +// Unsupported is a helper that returns a wrapped [errors.ErrUnsupported]. func Unsupported(op string) (err error) { - return &UnsupportedError{ - Op: op, - OS: runtime.GOOS, - } + return fmt.Errorf("%s: not supported on %s: %w", op, runtime.GOOS, errors.ErrUnsupported) } // SetRlimit sets user-specified limit of how many fd's we can use. diff --git a/internal/dnsforward/ipset.go b/internal/dnsforward/ipset.go index cb6b1663..cd841c34 100644 --- a/internal/dnsforward/ipset.go +++ b/internal/dnsforward/ipset.go @@ -6,7 +6,6 @@ import ( "os" "strings" - "github.com/AdguardTeam/AdGuardHome/internal/aghos" "github.com/AdguardTeam/AdGuardHome/internal/ipset" "github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/log" @@ -35,7 +34,7 @@ func (c *ipsetCtx) init(ipsetConf []string) (err error) { log.Info("ipset: warning: cannot initialize: %s", err) return nil - } else if unsupErr := (&aghos.UnsupportedError{}); errors.As(err, &unsupErr) { + } else if errors.Is(err, errors.ErrUnsupported) { log.Info("ipset: warning: %s", err) return nil diff --git a/internal/home/home.go b/internal/home/home.go index f7db7da0..93e8e09d 100644 --- a/internal/home/home.go +++ b/internal/home/home.go @@ -178,7 +178,7 @@ func setupContext(opts options) (err error) { // unsupported errors and returns nil. If err is nil, logIfUnsupported returns // nil. Otherwise, it returns err. func logIfUnsupported(msg string, err error) (outErr error) { - if errors.As(err, new(*aghos.UnsupportedError)) { + if errors.Is(err, errors.ErrUnsupported) { log.Debug(msg, err) return nil diff --git a/internal/ipset/ipset.go b/internal/ipset/ipset.go index a81102a1..44f519f1 100644 --- a/internal/ipset/ipset.go +++ b/internal/ipset/ipset.go @@ -22,8 +22,8 @@ type Manager interface { // // DOMAIN[,DOMAIN].../IPSET_NAME[,IPSET_NAME]... // -// If ipsetConf is empty, msg and err are nil. The error is of type -// *aghos.UnsupportedError if the OS is not supported. +// If ipsetConf is empty, msg and err are nil. The error's chain contains +// [errors.ErrUnsupported] if current OS is not supported. func NewManager(ipsetConf []string) (mgr Manager, err error) { if len(ipsetConf) == 0 { return nil, nil From 1c82be29500a5b5482734da6057c3a0aefe5f74e Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Mon, 17 Jun 2024 18:33:16 +0300 Subject: [PATCH 2/2] Pull request 2237: 7053 journald Log Updates #7053. Squashed commit of the following: commit f763a229660c00013fbd51cf7a3deabf00a01787 Merge: 06fc83d08 8432593be Author: Eugene Burkov Date: Mon Jun 17 17:52:11 2024 +0300 Merge branch 'master' into 7053-journald-log commit 06fc83d08e45ebb2a09382f2b6961bb18a98906a Author: Eugene Burkov Date: Thu Jun 13 15:59:35 2024 +0300 all: imp chlog commit 1f57a7e84aee7827f9b25f232ca46152a15da371 Author: Eugene Burkov Date: Tue Jun 11 20:36:55 2024 +0300 all: imp chlog commit 7c9a2547a82b4737e1785bb56ede2bf01bfb8533 Author: Eugene Burkov Date: Tue Jun 11 18:33:26 2024 +0300 home: imp doc commit 63731e7ba5e4085d071092ff4c7d712a30e07f28 Author: Eugene Burkov Date: Tue Jun 11 18:27:31 2024 +0300 home: imp systemd script --- CHANGELOG.md | 18 ++++++++++++++++++ internal/home/service.go | 10 +++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa0f3512..5bbaa65f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,11 +30,29 @@ NOTE: Add new changes BELOW THIS COMMENT. ### Changed - Frontend rewritten in TypeScript. +- The `systemd`-based service now uses `journal` for logging by default. It + also doesn't create the `/var/log/` directory anymore ([#7053]). + + **NOTE:** With an installed service for changes to take effect, you need to + reinstall the service using `-r` flag of the [install script][install-script] + or via the CLI (with root privileges): + + ```sh + ./AdGuardHome -s uninstall + ./AdGuardHome -s install + ``` + + Don't forget to backup your configuration file and other important data before + reinstalling the service. ### Deprecated - Node 18 support, Node 20 will be required in future releases. +[#7053]: https://github.com/AdguardTeam/AdGuardHome/issues/7053 + +[install-script]: https://github.com/AdguardTeam/AdGuardHome/?tab=readme-ov-file#automated-install-linux-and-mac + diff --git a/internal/home/service.go b/internal/home/service.go index 30bef2a7..27d59ad3 100644 --- a/internal/home/service.go +++ b/internal/home/service.go @@ -460,8 +460,9 @@ var launchdConfig = ` // 1. The RestartSec setting is set to a lower value of 10 to make sure we // always restart quickly. // -// 2. The ExecStartPre setting is added to make sure that the log directory is -// always created to prevent the 209/STDOUT errors. +// 2. The StandardOutput and StandardError settings are set to redirect the +// output to the systemd journal, see +// https://man7.org/linux/man-pages/man5/systemd.exec.5.html#LOGGING_AND_STANDARD_INPUT/OUTPUT. const systemdScript = `[Unit] Description={{.Description}} ConditionFileIsExecutable={{.Path|cmdEscape}} @@ -471,7 +472,6 @@ ConditionFileIsExecutable={{.Path|cmdEscape}} [Service] StartLimitInterval=5 StartLimitBurst=10 -ExecStartPre=/bin/mkdir -p /var/log/ ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}} {{if .ChRoot}}RootDirectory={{.ChRoot|cmd}}{{end}} {{if .WorkingDirectory}}WorkingDirectory={{.WorkingDirectory|cmdEscape}}{{end}} @@ -479,8 +479,8 @@ ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}} {{if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{end}} {{if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{end}} {{if and .LogOutput .HasOutputFileSupport -}} -StandardOutput=file:/var/log/{{.Name}}.out -StandardError=file:/var/log/{{.Name}}.err +StandardOutput=journal +StandardError=journal {{- end}} {{if gt .LimitNOFILE -1 }}LimitNOFILE={{.LimitNOFILE}}{{end}} {{if .Restart}}Restart={{.Restart}}{{end}}