Call on_shutdown handlers on exit.

Fixes #214.