[PATCH v2 5/5] procd: add api wrapper

Florian Eckert fe at dev.tdt.de
Thu Dec 3 04:53:59 EST 2020


This commit adds the functions `procd_add_service_trigger` and
`procd_add_restart_service_trigger`. In order for the service to be
triggered by another service during a restart, only the function
procd_add_restart_service_trigger is needed.

Example:

service_trigger() {
	procd add_restart_service_trigger 'firewall' <command>
}

If the firewall is restarted, the specified <command> will be executed.

Signed-off-by: Florian Eckert <fe at dev.tdt.de>
---

Changes since v1:

 - Augment procd_add_service_trigger with
   procd_add_restart_service_trigger

 package/system/procd/files/procd.sh | 33 +++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh
index d86b7219da..007c99fca0 100644
--- a/package/system/procd/files/procd.sh
+++ b/package/system/procd/files/procd.sh
@@ -329,6 +329,37 @@ _procd_add_config_trigger() {
 	json_close_array
 }
 
+_procd_add_service_trigger() {
+	json_add_array
+	_procd_add_array_data "$1"
+	shift
+
+	json_add_array
+	_procd_add_array_data "if"
+
+	json_add_array
+	_procd_add_array_data "eq" "service" "$1"
+	shift
+	json_close_array
+
+	json_add_array
+	_procd_add_array_data "run_script" "$@"
+	json_close_array
+
+	json_close_array
+	_procd_add_timeout
+	json_close_array
+}
+
+_procd_add_restart_service_trigger() {
+	local service=$1
+	shift
+
+	_procd_open_trigger
+	_procd_add_service_trigger "service.restart" "$service" "$@"
+	_procd_close_trigger
+}
+
 _procd_add_raw_trigger() {
 	json_add_array
 	_procd_add_array_data "$1"
@@ -559,6 +590,8 @@ _procd_wrapper \
 	procd_add_instance \
 	procd_add_raw_trigger \
 	procd_add_config_trigger \
+	procd_add_service_trigger \
+	procd_add_restart_service_trigger \
 	procd_add_interface_trigger \
 	procd_add_reload_trigger \
 	procd_add_reload_interface_trigger \
-- 
2.20.1




More information about the openwrt-devel mailing list