[PATCH 5/5] procd: add api wrapper

John Crispin john at phrozen.org
Wed Dec 2 13:24:54 EST 2020


can we augment we augment the procd_add_trigger/procd_close_trigger into 
the helper such as reload_trigger() does ?

     John

On 02.12.20 15:52, Florian Eckert wrote:
> This commit add a wrapper for procd services, to add a callback script
> if the "service.restart" trigger event was fired.
>
> Example:
>
> service_trigger() {
> 	procd_add_trigger
> 	procd_add service_trigger "service.restart" "firewall" <script>
> 	procd_close_trigger
> }
>
> If the firewall was restart, then the stored script gets executed.
>
> Signed-off-by: Florian Eckert <fe at dev.tdt.de>
> ---
>   package/system/procd/files/procd.sh | 23 +++++++++++++++++++++++
>   1 file changed, 23 insertions(+)
>
> diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh
> index d86b7219da..9076ddba5d 100644
> --- a/package/system/procd/files/procd.sh
> +++ b/package/system/procd/files/procd.sh
> @@ -329,6 +329,28 @@ _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_raw_trigger() {
>   	json_add_array
>   	_procd_add_array_data "$1"
> @@ -559,6 +581,7 @@ _procd_wrapper \
>   	procd_add_instance \
>   	procd_add_raw_trigger \
>   	procd_add_config_trigger \
> +	procd_add_service_trigger \
>   	procd_add_interface_trigger \
>   	procd_add_reload_trigger \
>   	procd_add_reload_interface_trigger \



More information about the openwrt-devel mailing list