From c0ac82be6a91cd4f5e43e7de6281d2854bbf63c2 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Tue, 24 May 2022 14:43:54 +0300 Subject: [PATCH] Pull request: 4480 fix sysv service script Merge in DNS/adguard-home from 4480-sysv-boot to master Updates #4480. Squashed commit of the following: commit c9645b1f3bd22a249c666e4485818bab6769f32d Author: Eugene Burkov Date: Tue May 24 14:25:09 2022 +0300 home: imp sysv script commit cc323364ba6cce0284cbc6be9133a50a51b71f56 Author: Eugene Burkov Date: Mon May 23 21:13:06 2022 +0300 home: fix sysv service script --- CHANGELOG.md | 2 ++ internal/home/service.go | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aca8f15..9d837c95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -128,6 +128,7 @@ In this release, the schema version has changed from 12 to 14. ### Fixed +- Service startup on boot on systems using SysV-init ([#4480]). - Detection of the stopped service status on macOS and Linux ([#4273]). - Case-sensitive ClientID ([#4542]). - Slow version update queries making other HTTP APIs unresponsible ([#4499]). @@ -150,6 +151,7 @@ In this release, the schema version has changed from 12 to 14. [#4238]: https://github.com/AdguardTeam/AdGuardHome/issues/4238 [#4273]: https://github.com/AdguardTeam/AdGuardHome/issues/4273 [#4276]: https://github.com/AdguardTeam/AdGuardHome/issues/4276 +[#4480]: https://github.com/AdguardTeam/AdGuardHome/issues/4480 [#4499]: https://github.com/AdguardTeam/AdGuardHome/issues/4499 [#4503]: https://github.com/AdguardTeam/AdGuardHome/issues/4503 [#4533]: https://github.com/AdguardTeam/AdGuardHome/issues/4533 diff --git a/internal/home/service.go b/internal/home/service.go index 70ab3c78..831a80d0 100644 --- a/internal/home/service.go +++ b/internal/home/service.go @@ -433,8 +433,11 @@ EnvironmentFile=-/etc/sysconfig/{{.Name}} WantedBy=multi-user.target ` -// Note: we should keep it in sync with the template from service_sysv_linux.go file -// Use "ps | grep -v grep | grep $(get_pid)" because "ps PID" may not work on OpenWrt +// sysvScript is the source of the daemon script for SysV-based Linux systems. +// Keep as close as possible to the https://github.com/kardianos/service/blob/29f8c79c511bc18422bb99992779f96e6bc33921/service_sysv_linux.go#L187. +// +// Use ps command instead of reading the procfs since it's a more +// implementation-independent approach. const sysvScript = `#!/bin/sh # For RedHat and cousins: # chkconfig: - 99 01 @@ -465,7 +468,7 @@ get_pid() { } is_running() { - [ -f "$pid_file" ] && ps | grep -v grep | grep $(get_pid) > /dev/null 2>&1 + [ -f "$pid_file" ] && ps -p "$(get_pid)" > /dev/null 2>&1 } case "$1" in