Desperate to make service reload on config change

Hello!

The procd file that I've written for my service is working fine in all aspects except for reloading when config file was changed... It start, stops and reload the service, it correctly gets the parameters from the config.

What I've already tried to trigger reloading:

First:

procd_set_param file /etc/config/mysrv

Then:

service_triggers()                                                       
{                                       
    procd_add_reload_trigger "/etc/config/mysrv"
}

The init file (with exact command/param names removed) is:

#!/bin/sh /etc/rc.common                                                 
USE_PROCD=1                                                              
START=95                                
STOP=01                                            
                                                                         
service_triggers()                                                       
{                                       
    procd_add_reload_trigger "/etc/config/mysrv"
}                                                                        
                                                                                                     
                                       
start_service() {                               
    config_load mysrv               
 
   <getting params from config>

    # Run service                       
    procd_open_instance                                                         
    procd_set_param <exact command with params>
    # Respawn if killed                                                         
    procd_set_param respawn                                                     
    # Redirect stdout and stderr to syslog                                 
    procd_set_param stdout 1                                               
    procd_set_param stderr 1                                                    
    # Restart if config was changed                                             
    procd_set_param file /etc/config/mysrv                              
    procd_close_instance                                                   
}

I totally don't understand what am I doing wrong.

Please advise!

Thank you!

Based on the code from some other packages I've arrived at: https://github.com/stangri/source.openwrt.melmac.net/blob/ed4d51a671f0a91b392eb27a9c006227bd6ec893/pbr/files/etc/init.d/pbr#L2625-L2631

You'll probably just need:

	procd_open_trigger
		procd_add_config_trigger "config.change" "mysrv" /etc/init.d mysrv reload
	procd_close_trigger

within your service_triggers().

I also remember I've struggled with new code from service_triggers not being picked up on manual service start/restart, so make sure to run service myserv info to verify what triggers are registered.

3 Likes