Restarting host from docker container
docker
Solution
I was able to send sysrq commands to the host mounting `/proc/sysrq-trigger` as a volume.
This booted the host.
docker-server# docker run -i -t -v /proc/sysrq-trigger:/sysrq centos bash
docker-container# echo b > /sysrq
You can set a bit-mask permission on `/proc/sys/kernel/sysrq` on the host to only allow eg, sync the disks and boot. More information about this at http://en.wikipedia.org/wiki/Magic_SysRq_key but something like this (untested) should set those permissions:
echo 144 > /proc/sys/kernel/sysrq
Also remember to add `kernel.sysrq = 144` to `/etc/sysctl.conf` to have it saved over reboots.
Problem
As the title indicates, is it possible to restart the host from a container? I have a docker container running with systemd as described here and started as: ``` $ docker run -privileged --net host -ti -d -v /sys/fs/cgroup:/sys/fs/cgroup:ro <image_name> ``` Once I issue the `systemctl reboot` command, I see: ``` # systemctl reboot [root@dhcp-40-115 /]# [3]+ Stopped ``` The host doesn't reboot. However, I see `[1915595.016950] systemd-journald[17]: Received SIGTERM from PID 1 (systemd-shutdow).` on host's kernel buffer. Use case: I am experimenting with running the restraint test harness in a container and some of the tests reboot the host and hence if this is possible to do from a container, the tests can run unchanged. Update As I mention in my answer: There is a detail I missed in my question above which is once I have systemd running in the container itself, the systemctl reboot is (roughly saying) connecting to systemd on the container itself which is not what I want. The accepted answer has the advantage that it is not dependent on the host and the container distro be have compatible `systemd`. However, on a setup where they are, my answer is what I think is a more acceptable one, since you can just use the usual `reboot` command. Other init systems such as `upstart` is untested.