Moved shutdown handlers definition outside for extensibility.
Pseudo cherry-pick from mrares/python-daemon@07a7f2de3d386b6630ef34a0138cb335cfaf6ed2.