From fc23bcdaa2f011ef47e2f6c6c1babad6fbdc3e7d Mon Sep 17 00:00:00 2001
From: Arthur Skowronek <ags@digineo.de>
Date: Wed, 30 Jan 2019 14:58:47 +0100
Subject: [PATCH] base-files: add service_stopped as a post stop hook
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

Purpose of these changes is to introduce a hook for post service
shutdown in a similar fashion to the existing hook service_started. I
found it to be useful to specify a hook that is called once the service
has been stopped and not before the service is stopped like the
stop_service hook does.

The concrete use case I have for this is that I'm running a binary that
takes over the hardware watchdog timer. Said binary unfortunately can
not use ubus directly to tell procd to hand over the watchdog timer so
this has to be done in the service file for the binary in question. In
order to support a clean handover of the watchdog timer back to procd,
the service init script has to dispatch the ubus invocation once the
binary in question has been stopped.

Signed-off-by: Arthur Skowronek <ags@digineo.de>
Signed-off-by: Petr Å tetiar <ynezz@true.cz>
[added commit message, use the same form as other hooks]
---
 package/base-files/files/etc/rc.common | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/package/base-files/files/etc/rc.common b/package/base-files/files/etc/rc.common
index d9773a0c5a..75dbeedf34 100755
--- a/package/base-files/files/etc/rc.common
+++ b/package/base-files/files/etc/rc.common
@@ -131,6 +131,9 @@ ${INIT_TRACE:+set -x}
 		procd_lock
 		stop_service "$@"
 		procd_kill "$(basename ${basescript:-$initscript})" "$1"
+		if eval "type service_stopped" 2>/dev/null >/dev/null; then
+			service_stopped
+		fi
 	}
 
 	reload() {
-- 
2.30.2