mimugmail / opn-repo

OPNsense repo by mimugmail
Other
325 stars 24 forks source link

AdguardHome "restart" stops adguard, but does not restart it. #208

Closed backlog-bbq closed 3 months ago

backlog-bbq commented 3 months ago

I have my acme client set to restart the opnsense web ui and adguardhome when a certificate renews. My dns went out randomly this weekend and I determined that adguard stopped running after my cert was renewed.

I discovered that the adguardhome restart command wasn't waiting until the process exited before restarting the process, causing any restart to fail like this:

# /usr/local/etc/rc.d/adguardhome restart
adguardhome already running?  (pid=75630).

This issue was mentioned in this comment in #171

I solved this by updating the rc script to wait for the process to exit and everything is working smoothly now. Here is the patch for the updated script (since adguard is not in this repo): adguardhome.patch

--- adguardhome.old 2024-03-17 15:39:35
+++ adguardhome.new 2024-03-17 15:31:41
@@ -12,7 +12,7 @@
 command=/usr/sbin/daemon
 command_args="-f -P /var/run/adguardhome.pid /usr/local/AdGuardHome/AdGuardHome -s run &"

-stop_cmd="killall AdGuardHome"
+stop_cmd=adguardhome_stop
 status_cmd=adguardhome_status

 load_rc_config adguardhome
@@ -30,5 +30,18 @@
          fi
 }

+adguardhome_stop()
+{
+   # wait for process to exit
+   if [ -n "$rc_pid" ]; then
+       echo "Stopping ${name}."
+       kill $rc_pid
+       echo "Waiting for PIDS: $rc_pid"
+       wait_for_pids $rc_pid
+       echo " done."
+   else
+       echo "${name} is not running."
+   fi
+}

 run_rc_command $1

edit: inlined the patch

mimugmail commented 3 months ago

I updated the rc and version, thx!