openwisp / openwisp-config

OpenWRT configuration agent for OpenWISP Controller
https://openwisp.io/docs/dev/openwrt-config-agent/
GNU General Public License v3.0
374 stars 58 forks source link

[feature] Add folders for multiple hook files #151

Closed pniaps closed 2 years ago

pniaps commented 3 years ago

Currently there are 3 possible hooks, pre-reload-hook, post-reload-hook, post-registration-hook.

Sometimes, you need to add code to execute in a hook from a template, but this is a problem when you need to add code from multiple templates.

A possible solution would be to have a *-hook.d folder where each template can place his custom code.

Something similar to

if [ \! -z "$1" -a -d /etc/openwisp/post-reload-hook.d ]; then
    for script in $(ls /etc/openwisp/post-reload-hook.d/* 2>&-); do (
        [ -f $script ] && . $script
    ); done
fi

extracted from OpwnWRT hotplug-call

Also, this paths are configurable. One solution would be to execute the configured file if exists and also search for scripts in a folder with the same name and .d suffix.

okraits commented 2 years ago

https://github.com/openwisp/openwisp-config/pull/180

@pniaps Does this solve this issue for you?

pniaps commented 2 years ago

I have taken a first look at it and it should be valid.

Basically it is the same to write a file in /etc/openwisp/post-reload-hook.d/do-something as in /etc/hotplug.d/openwisp/do-something.

In fact it is better, because with hotplug you can execute things in different events in the same file, while in this proposal you should create a file for each event.

Thanks.