base-files: add service_stopped as a post stop hook
authorArthur Skowronek <ags@digineo.de>
Wed, 30 Jan 2019 13:58:47 +0000 (14:58 +0100)
committerPetr Štetiar <ynezz@true.cz>
Sun, 5 May 2019 19:11:01 +0000 (21:11 +0200)
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

index d9773a0c5aaec092feb5cdae9decc798b5a6b714..75dbeedf34d45937e1fd6acec1fb9c034ec65f8d 100755 (executable)
@@ -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() {