Using LXC running a systemd based container, one automatically gets dropped into a console session on the container. By creating and modifying /etc/systemd/system/console-getty.service to have an ExecStart line such as the following:ExecStart=-/sbin/agetty --noclear -a <username> -s console 115200,38400,9600It's possible to skip the login session and directly drop in to a session running as a particular user.What I would like is for the machine to be automatically halted when this session ends. Is there a way to configure this, either in systemd or agetty? For reference, the host is Ubuntu 12.04 and the container is running a pretty recent Arch basis.
Systemd/agetty: halt machine when session ends
systemd;getty
The answer can be found in console-shell.service:ExecStopPost=-/bin/systemctl poweroffBTW, you don't need to make a copy of console-getty.service in order to make these modifications. Try the following:# rm /etc/systemd/system/console-getty.service# mkdir /etc/systemd/system/console-getty.service.d# cat > /etc/systemd/system/console-getty.service.d/custom.conf << EOF[Service]ExecStart=ExecStart=-/sbin/agetty --noclear -a <username> -s console 115200,38400,9600ExecStop=-/bin/systemctl poweroffEOF# systemctl daemon-reloadThe first, empty, ExecStart= entry clears the value inherited from /lib/systemd/system/console-getty.service. For more information about this method of customizing systemd unit files, see systemd.unit(5):Along with a unit file foo.service a directory foo.service.d/ may exist. All files with the suffix .conf from this directory will be parsed after the file itself is parsed. This is useful to alter or add configuration settings to a unit, without having to modify their unit files. Make sure that the file that is included has the appropriate section headers before any directive.