diff mbox series

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

Message ID 20201217093537.22653-6-fe@dev.tdt.de
State New
Headers show
Series ubus: extend the service object with a restart method | expand

Commit Message

Florian Eckert Dec. 17, 2020, 9:35 a.m. UTC
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@dev.tdt.de>
---
 package/system/procd/files/procd.sh | 33 +++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
diff mbox series

Patch

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 \