Rebooting the host from within a User container

I have a test farm set up with a few rancherOS hosts that are destroyed and PXE booted after running tests. It would be nice to be able to reboot the host from a user container. So far I have found multiple posts around the internet that achieve this by mounting systemd as a volume and telling the host’s systemd to kick off the reboot process. I also found someone using magic sysrq to perform the reboot, but I want something that has a smaller risk of being fixed in Docker or RancherOS in the future and breaking my workflow for these disposable hosts. Discussion on magic sysrq -> https://stackoverflow.com/questions/24750137/restarting-host-from-docker-container

What is the preferred way to reboot the host from within a user docker container on a clean RancherOS machine?

I would add a script to the host that

  • (deletes the file from the next step on startup)
  • watches for a certain file in a specific directory to exist
  • maybe does other useful cleanup tasks
  • calls regular reboot

Then bind mount in that directory to your container and touch the file when you want a reboot. (for RancherOS, write_files and start it in rc.local or similar). That way you’re not relying on any particular host distro, kernel params, etc to trigger it.