# Procd shutdown issues/questions

**URL:** <https://forum.openwrt.org/t/procd-shutdown-issues-questions/33759>\
**Category:** For Developers\
**Created:** [March 21, 2019, 6:46am UTC](https://forum.openwrt.org/t/procd-shutdown-issues-questions/33759 "2019-03-21T06:46:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SharkAttack99](https://forum.openwrt.org/user_avatar/forum.openwrt.org/sharkattack99/32/14178_2.png) [@SharkAttack99](https://forum.openwrt.org/u/SharkAttack99)\
**Post date:** [March 21, 2019, 6:46am UTC](https://forum.openwrt.org/t/procd-shutdown-issues-questions/33759/1 "2019-03-21T06:46:10Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![jow](https://forum.openwrt.org/user_avatar/forum.openwrt.org/jow/32/13_2.png) [@jow](https://forum.openwrt.org/u/jow)\
**Post date:** [March 21, 2019, 11:07am UTC](https://forum.openwrt.org/t/procd-shutdown-issues-questions/33759/2 "2019-03-21T11:07:27Z")

</div>

> [@SharkAttack99](#):
>
> 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.

Correct. Procd waits `term_timeouts` seconds for the process to exit before delivering a `KILL` signal.

> [@SharkAttack99](#):
>
> However, that interpretation is apparently wrong because `/etc/init.d/myservice stop` returns immediately even if the process has not terminated yet.

`/etc/init.d/x stop` is asynchronous and merely submits the service termination request to procd, it does not block until the process is stopped.

> [@SharkAttack99](#):
>
> I don't know what termination signal is being sent, but my service is not catching it.

By default, `SIGTERM` is sent. If you service is not receiving it, make sure it is properly supervised by procd. A common mistake is to fork away upon service start, which will cause procd to lose track of the process.

> [@SharkAttack99](#):
>
> The documentation states that stop\_service is called after procd terminates the service.

`stop_service()` is called before the termination request is sent to procd, its purpose is to allow for custom preparatory work before initiating the kill.

---

<div class="post-metadata">

**Author:** ![SharkAttack99](https://forum.openwrt.org/user_avatar/forum.openwrt.org/sharkattack99/32/14178_2.png) [@SharkAttack99](https://forum.openwrt.org/u/SharkAttack99)\
**Post date:** [March 21, 2019, 2:42pm UTC](https://forum.openwrt.org/t/procd-shutdown-issues-questions/33759/3 "2019-03-21T14:42:25Z")

</div>

Thank you! This is very helpful. I will update the docs.

So then upon device shutdown, the shutdown process will not wait for service shutdown to complete. Is that correct? Or is it simply that `/etc/init.d/x stop` does not block?

---

<div class="post-metadata">

**Author:** ![jow](https://forum.openwrt.org/user_avatar/forum.openwrt.org/jow/32/13_2.png) [@jow](https://forum.openwrt.org/u/jow)\
**Post date:** [March 21, 2019, 2:53pm UTC](https://forum.openwrt.org/t/procd-shutdown-issues-questions/33759/4 "2019-03-21T14:53:38Z")

</div>

Correct, `/etc/init.d/x stop` does not block.

---

<div class="post-metadata">

**Author:** ![system](https://forum.openwrt.org/uploads/default/original/3X/7/4/740520c71f00039bbf001045c682f0ecb25e905a.png) [@system](https://forum.openwrt.org/u/system)\
**Post date:** [March 31, 2019, 2:53pm UTC](https://forum.openwrt.org/t/procd-shutdown-issues-questions/33759/5 "2019-03-31T14:53:40Z")

</div>

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