0

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,9600

It'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.

  • terrible hack: echo "sudo halt" >> .bash_logout – strugee Oct 24 '13 at 2:58
0

The answer can be found in console-shell.service:

ExecStopPost=-/bin/systemctl poweroff

BTW, 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,9600
ExecStop=-/bin/systemctl poweroff
EOF
# systemctl daemon-reload

The 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.