Procd init script starting multiple processes

Trying to create an init.d script to auto start a service, but for some reason it's starting multiple instances.

root@ajas1885b1fc837:/etc/init.d# ps | grep hostapd                              
 2308 root      4636 S    /usr/sbin/hostapd -s -g /var/run/hostapd/global        
 8645 root       960 S    /usr/sbin/hostapd_cli -a /usr/bin/wireless_event.sh -B 
 8908 root       960 S    /usr/sbin/hostapd_cli -a /usr/bin/wireless_event.sh -B 
12341 root      1256 S    grep hostapd                                           

I'd like for it to just startup one time. I could put some logic in the init.d script to check for an existing pid and not start if it exists, but figured there might be something built in with init.d to prevent this.

My init.d script:

#!/bin/sh /etc/rc.common                                                                      
                                                                                              
START=31                                                                                      
                                                                                              
USE_PROCD=1                                                                                   
PIDCOUNT=0                                                                                    
                                                                                              
                                                                                              
start_service()                                                                               
{                                                                                             
        if [ -x "/usr/sbin/hostapd_cli" ]; then                                               
                procd_open_instance hostapd_cli                                               
                procd_set_param command /usr/sbin/hostapd_cli -a /usr/bin/wireless_event.sh -B
                procd_set_param respawn 3600 5 1                                              
                procd_close_instance                                                          
        fi                                                                                    
}                                                                                             
                                                                                              
                                                                                              
service_triggers()                                                                            
{                                                                                             
        procd_add_reload_trigger "hostapd_cli"                                                
}                                                                                             
                                                                                              
reload_service()                                                                              
{                                                                                             
        stop                                                                                  
        start                                                                                 
}                                                                                             
                                                                                              
shutdown()                                                                                    
{                                                                                             
        stop                                                                                  
}                                                                                             

I might have solved it. Think it was due to that -B (run in background) So procd was treating it like it needs to be restarted.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.