Add with-clean-shutdown macro

Add a macro to simplify the use of the code for utilising a clean shutdown