Fail to install "cannot install AdGuardHome as a service"
Prerequisites
-
[x] I have checked the Wiki and Discussions and found no answer
-
[x] I have searched other issues and found no duplicates
-
[x] I want to report a bug and not ask a question or ask for help
-
[x] I have set up AdGuard Home correctly and configured clients to use it. (Use the Discussions for help with installing and configuring clients.)
Platform (OS and CPU architecture)
Linux, ARMv7
Installation
GitHub releases or script from README
Setup
On one machine
AdGuard Home version
Edge
Action
Trying to install Adgyrardhome on a fresh Raspbian on a Raspberry Pi 4B
curl -s -S -L https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh -s -- -c edge starting AdGuard Home installation script [sudo] adgangskode for guld: starting AdGuard Home installation script 2026/11/12 23:00:19.272274 [info] starting adguard home version="AdGuard Home, version v1.0.0-a.116+df45d7c0" 2026/11/12 23:00:19.272935 [info] service: AdGuard Home, version v1.0.0-a.116+df45d7c0 2026/11/12 23:00:19.272976 [info] service: control action=install 2026/11/12 23:00:19.273751 [info] service_manager: installing service name=AdGuardHome 2026/11/12 23:00:19.274345 [error] service: action failed err="action "install": installing service: installing service: Init already exists: /etc/systemd/system/AdGuardHome.service" cannot install AdGuardHome as a service
Expected result
A fresh install og adguardhome edge
Actual result
cannot install AdGuardHome as a service
Additional information and/or screenshots
No response
I can reproduce this. I’ll forward it to the dev team.
I traced this one down to its root cause and opened a fix: #8721.
Problem
There are three layers. The first is the actual bug, and the other two turn it into the confusing "Init already exists" message.
- The systemd unit template no longer renders.
go.modis onkardianos/servicev1.3.0, whose built-in template engine no longer supports Gotext/templatesyntax.internal/ossvc/config_linux.gostill uses that syntax ({{.Description}},{{if and …}},{{if gt …}}). Rendering it fails withservice: unknown template key ".Description". The TODO ingo.modand the v1.3 upgrade notes both say the custom templates still needed rewriting, and that wasn't done yet. So on current edge (v1.0.0-a.116), every systemd install fails on its first attempt. - The library leaves a partial unit behind. In
kardianos/serviceservice_systemd_linux.go,Installcreates/etc/systemd/system/AdGuardHome.servicewithos.OpenFile(line 157) before it parses and renders the template (line 203). When rendering fails, it returns with the file already on disk and doesn't roll back. Any laterInstallhits the existence check at lines 152-154 and returnsInit already exists: /etc/systemd/system/AdGuardHome.service. install.shretries without cleaning up. Inscripts/install.sh,install_service()treats a failed-s installas fatal and runsrm -r "$agh_dir"without uninstalling the service. Onarmv7it then setsreinstall=1and reruns itself witharmv5(the #2542 fallback). In that rerun,handle_existing()returns early because the directory is gone, so-s uninstallnever runs, and the retry hits the leftover unit. Wrapped byhandleServiceInstallCmd→manager.install, that's exactly the message in this report:action "install": installing service: installing service: Init already exists: ….
Confirmed vs. inferred: layers 1-3 are confirmed by reading the code and by unit tests. I haven't re-run it on a real Pi 4B. The log pasted above shows only the final error. It matches either the armv7 → armv5 retry or a second manual attempt after the first one left the unit behind. Both lead to the same leftover file. On other CPUs the script stops after the first failure, so users there would see the template error instead, and the stale unit would still be left behind.
Reproduce
On a systemd Linux host with current edge:
curl -s -S -L https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh -s -- -c edge -v- The first
AdGuardHome -s installfails while rendering the unit (on armv7 the script then retries with armv5 and fails withInit already exists). ls -l /etc/systemd/system/AdGuardHome.serviceshows a leftover (empty or partial) unit.- Every later install attempt fails with
Init already existsuntil that file is removed by hand.
Workaround for affected users until a fix ships: sudo rm /etc/systemd/system/AdGuardHome.service && sudo systemctl daemon-reload. A plain re-run will still fail on step 1 until the template is fixed.
Fix
PR: #8721 (branch cursor/fix-install-service-exists-8714, commit 521e979)
internal/ossvc/config_linux.go:43-67: the systemd unit template is rewritten for the kardianos/service v1.3 engine. The output is the same unit as before (RestartSec=10, stdout/stderr to the journal).internal/ossvc/defaultmanager.go:153-210: ifInstallfails, AdGuard Home uninstalls to remove any partial unit. If the error isInit already exists, it uninstalls and installs once more, so a stale unit from an earlier failed attempt is replaced.internal/home/service.go:337-373: if the unit installs but the service fails to start, the unit is uninstalled again, so nothing half-installed is left behind.scripts/install.sh:547-553: beforerm -r "$agh_dir", the script now runs a best-effort./AdGuardHome -s uninstall(through the existingmaybe_sudo), so the armv7 → armv5 fallback starts clean.CHANGELOG.md: Unreleased → Fixed entry for #8714.
Tests added:
TestSystemdScript_syntax: the new unit template renders with the v1.3 engine and produces a valid unit.TestManager_Install,TestManager_Install_alreadyExists: the first call returnsInit already exists, uninstall runs, and the second install succeeds.TestHandleServiceInstallCmd_rollback: an install error doesn't start the service, and a start error uninstalls the unit.
go test -race -count=1 passes for ./internal/ossvc/ and ./internal/home/. go vet, staticcheck, gosec, gocyclo/gocognit, shadow, nilness, ineffassign, unparam, fieldalignment and misspell pass on the touched packages. shellcheck and shfmt pass for scripts/install.sh.
Caveats
- Other init systems: the SysV, OpenWrt, FreeBSD, macOS (launchd) and OpenBSD custom templates still use the old
text/templatesyntax, so installs there probably fail the same way on edge. This PR only covers systemd, which is what this report is about. I can extend it to the other templates if you'd like that in the same PR. - On
Init already exists, the existingAdGuardHomeunit is replaced, including one that was edited by hand. If you'd rather keep an existing unit and only remove empty or partial ones, I can narrow that. - If
systemctl disableitself fails before the library deletes the file, the retry can still see the old unit.