HOWTO - Update AdGuard Home automatically with cron

Started by Vexz, February 16, 2023, 03:53:10 PM

Previous topic - Next topic
This tutorial assumes you have installed AGH through mimugmail's community repo (tutorial link).

The gist of this tutorial is to install updates of AGH and restart its running instance with a cronjob automatically.

ATTENTION: You'll need AdGhuard Home v0.107.22 er newer to make this work. In earlier versions the update parameter didn't exist yet or was buggy.

------------------------------------------------------------------

1. Connect to your OPNsense via SSH

2. To make life easier use # sudo -i

3. In the menu where you have to choose an option use "8" (Shell)

4. Edit the following config (I chose vi to do that):
# vi /usr/local/opnsense/service/conf/actions.d/actions_adguardhome.conf

5. In this config you need to add the [update] part. See below:
[start]
command:/usr/local/etc/rc.d/adguardhome start
parameters:
type:script
message:starting Adguardhome

[stop]
command:/usr/local/etc/rc.d/adguardhome stop
parameters:
type:script
message:stopping Adguardhome

[restart]
command:/usr/local/etc/rc.d/adguardhome restart
parameters:
type:script
message:restarting Adguardhome
description:Restart AdGuardHome service

[status]
command:/usr/local/etc/rc.d/adguardhome status;exit 0
parameters:
type:script_output
Message:request Adguardhome status

[update]
command:/usr/local/AdGuardHome/./AdGuardHome --update
parameters:
type:script
message:updating Adguardhome
description:Update AdGuard Home


6. Restart configd
# service configd restart
This will add a new selectable option in the drop down menu for "Command" in the web UI under System > Settings > Cron. Add a cronjob with this option for when you want AGH to update.


7. Install AGH as a service. You will need this to make AGH automatically restart after a new update was installed. The "--no-check-update" is optional and should hinder AGH from searching for new updates. Somehow this doesn't work in my case.
# /usr/local/AdGuardHome/./AdGuardHome -s install --no-check-update

8. Make the AGH service start at boot. For this we need to create a new file.
# touch /usr/local/etc/rc.syshook.d/start/50-adguardhome
# chmod 755 /usr/local/etc/rc.syshook.d/start/50-adguardhome
# vi /usr/local/etc/rc.syshook.d/start/50-adguardhome

Now paste the following in this file and save:
#!/bin/sh

/usr/local/AdGuardHome/./AdGuardHome -s start


9. In the web UI you need to disable AGH or you'll have two instances of AGH running after a reboot. For this navigate to Services > Adguardhome > General. Uncheck the checkmark for "Enable" and hit "Save".

10. Reboot your OPNsense to confirm the AGH service is starting on boot. After the reboot you should be able to access the web UI of AGH. Give AGH a few seconds to start. The CLI of your OPNsense should output "service: running" when you execute this command:
# /usr/local/AdGuardHome/./AdGuardHome -s status

11. Done!

------------------------------------------------------------------

I couldn't find out which file to edit to make the checkmark in the web UI start the AGH service, not an individual instance. Maybe someone more experienced than me can help me out and I'll add it to the tutorial.

Need is the mother of invention. But the approach IMHO should be _not_ to hack around the plugin.
How can the developer out of his/her free time support installations of the plugin that have subsequently modified?
Or anyone seeking assistance from the community for that matter?. But you will do what you will.

From my part, when I need to update AdGH plugin installation, all I have to do is click on "upgrade" on the AdGH UI page. The only minor issue is that an OPN healthcheck will report a file sig mismatch.
Is that something that doesn't work for you?

Quote from: cookiemonster on February 16, 2023, 04:47:23 PM
Need is the mother of invention. But the approach IMHO should be _not_ to hack around the plugin.
How can the developer out of his/her free time support installations of the plugin that have subsequently modified?
Or anyone seeking assistance from the community for that matter?. But you will do what you will.
Nobody is forced setup auto updates for AGH. I just wanted to make a tutorial in case someone is looking for a solution for that.  Also I asked mimugmail a few weeks ago if he wants to update his repo to add this option but didn't get a answer. So I did it myself.

Quote from: cookiemonster on February 16, 2023, 04:47:23 PM
From my part, when I need to update AdGH plugin installation, all I have to do is click on "upgrade" on the AdGH UI page. The only minor issue is that an OPN healthcheck will report a file sig mismatch.
Is that something that doesn't work for you?
It works for me too but I love automation because I don't wanna think about updating every service I use. Also I like figuring stuff like that out. It's fun to me and I learn more about OPNsense.

But with this you are not automating the updates of the plugin instance but creating a new plumbing for the instance, on the same system and away from the UI. Therefore not a solution to the "problem", which we've estblished doesn't exist.
For your purposes, all good but my critique is about having a suitable large notice that is an unsupportable way to hack at the plugin.
I can already see cases of multiple instances running (someone forgot to go and disabled the actual plugin instance from the UI) and all sorts of strange behaviours coming from that.
BTW, good work for your learning. It isn't intended as criticism despite what it might appear.

You can easily revert the changes or create a ZFS snapshot before making any changes to the system.
Of course it's just "plumbing" because I modify a plugin. But what can I do? It's not like I didn't try to ask the maintainer of the repo to implement this feature. I could have kept this tutorial to myself but maybe someone else was looking for this solution but couldn't figure out how to make it work.

What feature? If the update can be done with literally the click of one button. What was to be made to work?
In any case, I won't comment anymore. I'm not trying to discourage you or critizise your contribution. Clearly I'm not explaining myself well. Thank you for the contribution.

It's literally stated in the second line of the first post.

Anyway, I doubt many people will use this tutorial but I'm glad if this was a help for at least someone.

Thanks for HOWTO, I used Your example for auto-updates. But in my case, I also have command for syncing YAML file between 2 nodes, I simply modified my additional file agh_sync.d and added update there with command:

/usr/local/AdGuardHome/./AdGuardHome --update;(sleep 15 && /usr/local/etc/rc.d/adguardhome stop && sleep 5 && /usr/local/etc/rc.d/adguardhome start)

No need to modify plugin files, not so clean about restart but works :)

Anyone else has the issue that the AdGuardHome service is not restarting properly? I have to start it manually each time after clicking the restart button.

Any logs I can look into to see why it's failing?

Can you just change the line in actions_adguardhome.conf:
command:/usr/local/AdGuardHome/./AdGuardHome --update
to something like
command:/usr/local/AdGuardHome/./AdGuardHome --update && service adguardhome start

is thre meanwhile a better solution for autoupdate adguard?

And the next question is, how can I autoupdate the block lists?

Quote from: bread on October 31, 2024, 11:14:11 PM
And the next question is, how can I autoupdate the block lists?

AdGuard Home does that by default.

Settings > General Settings > Filter Update Interval

Default is 24 hours.
Deciso DEC750
People who think they know everything are a great annoyance to those of us who do. (Isaac Asimov)

Quote from: Patrick M. Hausen on October 31, 2024, 11:19:19 PM
Settings > General Settings > Filter Update Interval

Ah, thanks! Just didn't see it.

Regarding the update possibility of adguard itself, as I understand there is no better solution as above, because its not an official OPNsense app, isn't it?

So if I want something that blocks AND updates itself AND is stable with OPNsense after updates, I must use unbound block lists, isn't it?

but IMHO you trade. I've seen a few reported problems apparently caused by the unbound blocklists. Once the user moves to using them outside Unbound, for instance in AdGH, those go away.
The trade is you have to click one button every X weeks to update AdGH. The last one was 3 months from the previous.

AGH is a pretty reliable and stable piece of software that in my experience does not fail working if not updated for a couple of months.

Also Michael does update the plugin from time to time so you will get AGH updates with your regular OPNsense maintenance. Just not on the day they are published upstream.
Deciso DEC750
People who think they know everything are a great annoyance to those of us who do. (Isaac Asimov)