This adds auto-restarting capability. (imported from commit 74a01a0272025706f2eb902eeedd9c05ee054272)