mainloop: make periodic events restartable
When we shut down tor, we disable periodic events, but leave their enabled flag set to 1.
See this PR for details: https://github.com/torproject/tor/pull/1397
I'm not sure if this is the best solution, or how far we should backport.