[HowTo] Running Adguard Home on OpenWrt

Thanks Lee. I'll consider the full odhcpd option as dnsmasq does seem to be the culprit.

I'm running a standard configuration. Perhaps you've modified yours but standard OpenWrt runs a few processes after rc.local. See the processes that are run in /etc/rc.d/ after S95done.

https://openwrt.org/docs/techref/process.boot

Hi @brokenpipe. I'm not sure this is the best or appropriate way but I use the 'ps' command to list processes and identify the process I need to kill to stop it. I then use the 'kill' command to stop AGH, e.g. kill 2784 if 'ps' listed AGH under process number 2784. To start AGH after killing it I just run /etc/rc.local. Seems to work OK for me but there may be other preferred ways of getting it done.

1 Like

There are still some service related issues with AGH and OpenWrt. These is a recent commit that allows AGH to successfully be installed as a service on OpenWrt that is on master and compiled into the latest AGH beta release, but has not made it to stable release yet.

However, the latest beta that includes that commit does successfully install AGH as a service, but fails to enable/disable the service for boot time startup. I can manually start/stop the AGH service though. So for the time being, I still have to start the AGH service in rc.local with /etc/init.d/AdGuardHome start as a temporary workaround.

If anyone here has good knowledge and understanding of OpenWrt and services, I have started an issue report on AGH Github page: https://github.com/AdguardTeam/AdGuardHome/issues/1386

The developers are asking for additional help on that because they don't have extensive experience with OpenWrt and it differs somewhat from their Linux service code.

That is one of the few remaining issues holding up their next stable release: https://github.com/AdguardTeam/AdGuardHome/milestone/17

Therefore, once sorted out, the next stable release of AGH should be a much better candidate for us OpenWrt users. It includes some other OpenWrt related fixes as well.

1 Like

Currently, this is my init script. It works (improvements are welcome :wink: )

#!/bin/sh /etc/rc.common
 
START=95
STOP=5
 
start() {        
        # (opkg install coreutils-nohup)
        nohup /mnt/usb/AdGuardHome/AdGuardHome > /dev/null 2>&1&
}                 
 
stop() {
        kill -15 $(pgrep -f AdGuardHome)
}

i think it simply lacks a good init script. the standard adguardhome package is based on systemd. i can't find any other disadvantages compared to adguard home on x86 or armv7h.

@brokenpipe Indeed, lacking a good init script is the issue.

In the last few days, I found a couple of init scripts specifically related to AdGuardHome:


But the problem is, those init scripts are quite "busy" with a lot going on. I would much rather trust an init script from the developers of AGH or one like yours which is much simpler that I quite like. I will give yours a try today.

@brokenpipe Would the following code changes work for my setup?

From nohup /mnt/usb/AdGuardHome/AdGuardHome > /dev/null 2>&1&

To nohup /usr/bin/AdGuardHome/AdGuardHome -s run > /dev/null 2>&1&

/usr/bin/AdGuardHome/AdGuardHome is where my binary is located and -s run is the special AGH command that runs it as a service daemon. I don't know if I would need to add quotes or anything to include the command arguments. I'm just not that familiar with Linux.

My biggest problem is that I cannot get AGH to start at boot time as a service without requiring adding it to rc.local as of yet.

apparently the operator doesn't make much difference. but i now start adguard manually. so i can be sure that all openwrt own processes start correctly.

nohup /usr/bin/AdGuardHome/AdGuardHome "-s" "run" > /dev/null 2>&1&

Good news! The AdGuardHome dev team has fixed much of the remaining OpenWrt-related issues and all of those fixes are available now in the latest beta version compiled today. I would recommend this latest beta for OpenWrt users now in comparison to the most recent stable build of AGH. Otherwise, I believe the next stable build for AGH is likely just a few days away anyway.

They are using a much less complex script now along with procd.

Commit: https://github.com/AdguardTeam/AdGuardHome/commit/fc88f59f6160c7d3520f22081cf569025b5fd5c8#diff-e06079fe3b21218b7ea531caffc32b39R411

EDIT: This has also resolved my issue with system time which I believe that NTP issue was related to the boot order and how I was having to use rc.local to start AGH. That is not necessary anymore and this resolved several issues on my end.

2 Likes

Thanks for the GitHub issue. That was a fast fix! They are doing a really good job on AdGuard Home. Looking forward to install the new release :slight_smile: ... are you already on the new beta release?

You're welcome. I am quite pleased with their dev teams pace of development and responsiveness to the community.

Yes, I am using the latest beta right now and it's the best release so far. I would not normally run the beta versions on my network but this beta in particular had so many important fixes for OpenWrt that it was worth switching to beta at least until next stable release.

May I ask how the final solution of you guys is looking to automatically start the service at boot?
Plus: Would it be possible to add it to "luci --> system --> startup"?

use
./AdGuardHome -s install

It will add it automatically,

1 Like

Has anyone seen this error in their logs?

Sun Feb 16 19:44:17 2020 daemon.err AdGuardHome[4886]: 2020/02/17 01:44:17 [info] SafeBrowsing: failed: got an unexpected HTTP status code 400 from 'https://dns-family.adguard.com:443/dns-query'

It's not constant, but wondering how to resolve it.

Thanks for pointing me towards this, a lot nicer and more intuitive to look at than Adblock's LuCi package. Also, I've got no clue why, but the way it deals with RAM is a lot better than Adblock. For example, I've got a custom curated list that I parse through PiHole (PiHole pulls all the lists, parses them, sorts them and removes duplicates) into a singular gravity.list with close to 7 million domains. Adblock seems to get stuck in a loop of chewing through all my Pi's 1GB of RAM, crashing the process, restarting the process and repeating. Adguard just takes a few minutes to get going, but works perfectly well - and I'll still have at least 40Mb of RAM free after the fact.

Check that you were using the null blocking variant. If using a nxdomain variant it applies a filter per domain. Pihole and hosts files include a massive amount of subdomains as the filtering is done at subdomain level. Using those lists with nxdomain filtering grinds your machine to a halt. In the words of the adblock developer

One major drawback of the 'null' blocking method is, that it only works per single host entry ... you can't block a whole domain (e.g. including all subdomains) with one single entry. That's may one reason why these pihole guys working with such big blocking lists.

https://forum.openwrt.org/t/adblock-support-thread/507/931

Yeah, I was using null-blocking because I was trying to use it with Unbound. Tried with both /tmp and a non-volatile folder set as backup. Same end, crash-loop because of RAM. AdGuard Home unequivocally works better with a ton of RAM, not sure how they do it but it works.

Latest stable release (v0.101.0) of AdGuard Home has much better OpenWrt support now, including service installation and various bug fixes as well.

Download: https://github.com/AdguardTeam/AdGuardHome/releases/tag/v0.101.0

"Compatibility with OpenWRT

AdGuard Home is now compatible with OpenWRT. Not that it was completely incompatible before, you could always run a binary, or you could build it manually for (almost) any CPU.

The problem was that you could not install AdGuard Home as a service as per the Getting Started manual, and doing it manually requires some advanced technical knowledge :mortar_board:

Anyways, this is not a problem anymore! AdGuard Home can be installed on an OpenWRT device and registered as a service: #1348, #1386 #1239.

And if you want better integration with OpenWRT, there is an awesome luci application by @rufengsuixing:
https://github.com/rufengsuixing/luci-app-adguardhome/ "

There's lots of interesting new things in this release. One thing in particular:

This can parse existing Hosts files and automatically convert them into proper format for AdGuardHome. Also, there's a new feature where you can load custom filters from your own hard drive which may be beneficial along with this Hostlist Compiler.

1 Like

i'm curious what the HostlistCompiler can do. i built a bash script by myself, which queries all usable and good blocklists, filters out comments, incorrect and duplicate entries.