I have a simple procd service that needs to cleanly close on shutdown. Currently the service intercepts a number of kill signals (SIGHUP, SIGQUIT, SIGSTOP, SIGTERM, SIGINT). When one of these signals is sent to the process, it cleans up and exits properly. For testing purposes, the service waits 10 seconds and then exits.
There is documentation on this, but it does not seem correct to my interpretations: (https://openwrt.org/docs/guide-developer/procd-init-scripts)
The term_timeout parameter seems to indicate that a SIGTERM signal is sent and procd waits for the process to terminate up to the timeout value. However, that interpretation is apparently wrong because /etc/init.d/myservice stop returns immediately even if the process has not terminated yet. I don't know what termination signal is being sent, but my service is not catching it.
My next thought was to simply block in service_stop() until the process terminates. The documentation states that stop_service is called after procd terminates the service. However, that is not what I am seeing. If I put a 20 second sleep in stop_service and then call /etc/init.d/myservice stop I can see the process remains during the 20 second sleep and then is killed after stop_service returns.
Am I misinterpreting things? What signal is procd using to terminate a service? Is there an easy way to block for a process to cleanly terminate? I suppose I could create a dummy service that shuts down after the real service and inside that service_stop block for the real service to terminate, but that is a total hack.
Thanks for any insights.