Problem with stopping service

Hi people.
I've written a service file:

#!/bin/sh /etc/rc.common

START=50
STOP=50

USE_PROCD=1
NAME=nfqws
PROG=/root/zapret/nfqws
LIST=/root/zapret/domains

start_service_nfqws_537() {
        procd_open_instance 537
        procd_set_param command "$PROG" --qnum=537 --daemon --user=network --hostlist="${LIST}" --dpi-desync=syndata,disorder2 --dpi-desync-repeats=6 --dpi-desync-split-pos=1 --dpi-desync-ttl=1 --dpi-desync-fooling=md5sig --dpi-desync-any-protocol=1 --dpi-desync-cutoff=d4
        procd_set_param nice -20
        procd_set_param stdout 1
        procd_set_param stderr 1
        procd_close_instance
}

start_service_nfqws_538() {
        procd_open_instance 538
        procd_set_param command "$PROG" --qnum=538 --daemon --user=network --hostlist="${LIST}" --dpi-desync=fake --dpi-desync-repeats=6
        procd_set_param nice -20
        procd_set_param stdout 1
        procd_set_param stderr 1
        procd_close_instance
}

start_service() {
        if [ -x "$PROG" ] && [ -r "$LIST" ]; then
                start_service_nfqws_537
                start_service_nfqws_538
        fi
}

stop_service() {
        killall -q nfqws
}

It starts fine, but when I stop it I get error message:

Failed to execute "/etc/init.d/nfqws stop" action: Command failed

Though a nfqws service does stop, but I got confused with the message. I tracked the shell functions and found out that the service is not listed in "ubus list" output.
Could you please help me to fix this error?
Regards.

run sh -x rc.conf /etc/init.d/script stop
...

1 Like

Running this way shows no errors:

...
+ readlink /etc/init.d/nfqws
+ basescript=
+ ALL_COMMANDS='boot shutdown depends start stop restart reload enable disable enabled running status trace info '
+ ALL_HELP='\tstart           Start the service\n\tstop            Stop the service\n\trestart         Restart the service\n\treload          Reload configuration files (or restart if service does
not implement reload)\n\tenable          Enable service autostart\n\tdisable         Disable service autostart\n\tenabled         Check if service is started on boot\n\trunning         Check if service is running\n\tstatus          Service status\n\ttrace           Start with syscall trace\n\tinfo            Dump procd service info\n'
+ list_contains ALL_COMMANDS stop
+ local 'var=ALL_COMMANDS'
+ local 'str=stop'
+ local val
+ eval 'val=" ${ALL_COMMANDS} "'
+ val=' boot shutdown depends start stop restart reload enable disable enabled running status trace info  '
+ '[' ' boot shutdown depends start' '!=' ' boot shutdown depends start stop restart reload enable disable enabled running status trace info  ' ]
+ stop
+ procd_lock
+ readlink /etc/init.d/nfqws
+ local 'basescript='
+ basename /etc/init.d/nfqws
+ local 'service_name=nfqws'
+ flock -n 1000
+ '[' 0 '!=' 0 ]
+ stop_service
+ killall -q nfqws
+ basename /etc/init.d/nfqws
+ procd_kill nfqws
+ _procd_call _procd_kill nfqws
+ local old_cb
+ json_set_namespace procd old_cb
+ local '_new=procd'
+ local '_old=old_cb'
+ '[' -n old_cb ]
+ _set_var old_cb
+ local '__val='
+ eval 'old_cb="$__val"'
+ old_cb=
+ JSON_PREFIX=procd
+ _procd_kill nfqws
+ local 'service=nfqws'
+ local 'instance='
+ json_init
+ json_cleanup
+ local unset tmp
+ _json_get_var unset JSON_UNSET
+ eval 'unset="$procdJSON_UNSET"'
+ unset=
+ unset procdU_J_V procdK_J_V procdS_J_V procdT_J_V procdN_J_V procdJ_V
+ unset procdJSON_SEQ procdJSON_CUR procdJSON_UNSET
+ export -n 'procdJSON_SEQ=0'
+ export -- 'procdJSON_CUR=J_V' 'procdK_J_V='
+ '[' -n nfqws ]
+ json_add_string name nfqws
+ local cur
+ _json_get_var cur JSON_CUR
+ eval 'cur="$procdJSON_CUR"'
+ cur=J_V
+ _json_add_generic string name nfqws J_V
+ local var
+ '[' J_V '=' J_A ]
+ var=name
+ '[[' name '==' name ]]
+ export -- 'procdJ_V_name=nfqws' 'procdT_J_V_name=string'
+ _jshn_append JSON_UNSET J_V_name
+ local '_a_value=J_V_name'
+ eval 'procdJSON_UNSET="${procdJSON_UNSET} $_a_value"'
+ procdJSON_UNSET=' J_V_name'
+ _jshn_append K_J_V name
+ local '_a_value=name'
+ eval 'procdK_J_V="${procdK_J_V} $_a_value"'
+ procdK_J_V=' name'
+ '[' -n  ]
+ _procd_ubus_call delete
+ local 'cmd=delete'
+ '[' -n  ]
+ json_dump
+ jshn -p procd -w
+ ubus call service delete '{ "name": "nfqws" }'
+ json_cleanup
+ local unset tmp
+ _json_get_var unset JSON_UNSET
+ eval 'unset="$procdJSON_UNSET"'
+ unset=' J_V_name'
+ unset procdU_J_V_name procdK_J_V_name procdS_J_V_name procdT_J_V_name procdN_J_V_name procdJ_V_n
+ unset procdU_J_V procdK_J_V procdS_J_V procdT_J_V procdN_J_V procdJ_V
+ unset procdJSON_SEQ procdJSON_CUR procdJSON_UNSET
+ json_set_namespace
+ local '_new='
+ local '_old='
+ '[' -n  ]
+ JSON_PREFIX=
+ eval 'type service_stopped'

But running from luci shows following:

Procd keeps track of the pids of services it starts so does its own "stop".
This section is designed to allow pre service shutdown cleanups etc.
So, you can leave this section out entirely.

The error is probably because you need to specify the path to killall.
ie /usr/bin/killall

For reference see:
https://openwrt.org/docs/guide-developer/procd-init-scripts#stopping_services

The problem is that when I remove killall -q nfqws, Procd doesn't stop processes. As for killall itself it actually does it's job, it kills processes, but error appears in lucy.
I decided to get rid of procd and wrote the script the old way like this:

#!/bin/sh /etc/rc.common

START=25
STOP=05

PROG=/usr/bin/nfqws
LIST=/etc/config/nfqws

start() {
        "$PROG" --qnum=537 --daemon --user=network --hostlist="${LIST}" --dpi-desync=syndata,disorder2 --dpi-desync-repeats=6 --dpi-desync-split-pos=1 --dpi-desync-ttl=1 --dpi-desync-fooling=md5sig --dpi-desync-any-protocol=1 --dpi-desync-cutoff=d4
        "$PROG" --qnum=538 --daemon --user=network --hostlist="${LIST}" --dpi-desync=fake --dpi-desync-repeats=6
}

stop() {
        killall -q "$PROG"
}

Now it works fine.