unbit/uwsgi — pull request #297 by prymitive (2013-05-24 08:25:29+00:00)
Title: fixed dump daemon process termination

I've noticed that graceful process termination in daemons I've added for legion daemons patch doesn't work properly for my dump daemons, example:

```
uwsgi --http :8080 --wsgi-file tests/staticfile.py -M --logdate --attach-daemon="memcached -p 11311 -vv"
```

Issue is that memcached is spawned using subshell, uWSGI only knows subshell pid and it sends SIGTERM to subshells process group. Memcached terminates properly, but subshell is left running as defunct process (I'm not sure why), checks in uWSGI continue to find ud->pid (subshell) alive and we need to wait until --reload-mercy timeout is reached.

This patch will fix it rather brutally, for dumb processes we send SIGTERM, sleep for 3 seconds and retry with SIGKILL if needed. With smart daemons it is not needed.
I'm not sure if this is the best we could do, maybe some simple fix would prevent those defunct shells (but would it work in all cases?).