Add support for PRE_SHUTDOWN service control signals

See commit messages for details.
Also you can't assume write access here as a service. You should consider creating a temp file etc.