PROCD questions


#1

Hello,

I have a service which needs to be triggered when the wireless channel is changed on the first radio.

cat << 'EOF' > /etc/init.d/test
#!/bin/sh /etc/rc.common
START=99
USE_PROCD=1
PROG=/bin/echo

start_service () {
  wifiChannel="$(uci -q get wireless.@wifi-device[0].channel)"
  logger -t "test" "starting wlan test service ($wifiChannel)"
  procd_open_instance
    procd_set_param command $PROG "starting wlan test service ($wifiChannel)"
    procd_set_param file /etc/config/wireless
    procd_set_param file /var/run/hostapd-phy0.conf
  procd_close_instance
}
stop_service () {
  logger -t "test" "stopping wlan test service"
}
service_triggers () {
  procd_open_trigger
    procd_add_reload_trigger "wireless"
    procd_add_reload_interface_trigger "wlan0"
    procd_add_interface_trigger "interface.*" "wlan0" /etc/init.d/test reload
    procd_add_config_trigger "config.change" "wireless" /etc/init.d/test reload
    procd_add_config_trigger "config.change" "/etc/config/wireless" /etc/init.d/test reload
  procd_close_trigger
}
EOF

chmod +x /etc/init.d/test
/etc/init.d/test enable
/etc/init.d/test start

It doesn't work however, if I change the radio channel from luci (or by editing config file and reloading wifi) the service isn't triggered (nothing in the log). I see wlan0 going down and coming back up with the new configuration, but my server isn't triggered. What do I need to do to have service triggered by the change in wireless configuration?

Second question, while looking up PROCD articles I found a lot of examples where procd_open_trigger/procd_close_trigger are not used. What's the correct use of the procd_open_trigger/procd_close_trigger? Is it only needed for some triggers and not the others?

Thanks!


#2

From my point of view the additional procd_open/close_trigger stuff is not needed. If you check procd.sh you'll see that trigger open/close calls are already part of the procd_close_service function.

_procd_close_service() {
           json_close_object
           _procd_open_trigger
           service_triggers
           _procd_close_trigger
           _procd_open_data
           service_data
           _procd_close_data
           _procd_ubus_call ${1:-set}
   }

I do not fully understand what you're trying to achieve, therefore only some general remarks:

  • your "service" (/bin/echo) isn't running, you can always check that with (verbosity prints the trigger settings, too) ...
    ubus call service list '{"name":"test","verbose": true}'
  • maybe you have a wrong expectation regarding reload trigger (like me in 2016 :wink:), see here Jo's answer on the mailing list

#3

Thank you for your reply!

Yeah, that's why I have procd_add_interface_trigger "interface.*" "wlan0" /etc/init.d/test reload in there, but that doesn't work either. :frowning:

PROG=echo intentionally, it's a stub. When the reload is triggered I'm expecting to see a message in syslog.


#4

You need to procd_set_param stdout 1 to make it relay the echo output to syslog.


#5

@jow I'm using this:

It works (on service start), the problem is that service doesn't get triggered on wifi reload even tho I'm tracking wlan interface.


#6

run "/sbin/reload_config" for reload the config


#7

What the trigger does is registering the uci file as change source for
the service so that an "/etc/init.d/firewall reload" or an
"reload_config" would trigger a firewall restart in case the
/etc/config/firewall got changed since the last reload.
Set PROCD_DEBUG=1 to see debugging information when starting or stopping a procd init script. 

procd_add_interface_trigger "interface.*" "wlan0" /etc/init.d/test reload

“wlan0” ——->. wlan0 ????

As per

https://openwrt.org/docs/guide-developer/procd-init-scripts


#8

No, the ".*" is a wildcard for ".up" or ".down"


#9

Sorry my mistake no dot

“wlan0” —-> wlan0