'This manages the flag file that tells the runner if the server
should be restarted or is shutting down.
Args:
mode (bool or None): Valid modes are True/False and None.
If mode is None, no change will be done to the flag file.'

def set_restart_mode(self, mode=None):

    if (mode is None):
        return
    with open(PORTAL_RESTART, 'w') as f:
        print(('writing    mode=%(mode)s    to    %(portal_restart)s' % {'mode': mode, 'portal_restart': PORTAL_RESTART}))
        f.write(str(mode))
