Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
terrible hack: echo "sudo halt" >> .bash_logout – strugee Oct 24 '13 at 2:58
up vote 0 down vote accepted

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
ExecStart=-/sbin/agetty --noclear -a <username> -s console 115200,38400,9600
ExecStop=-/bin/systemctl poweroff
# 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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