0

When trying to get a shell into a container vm, I get the following error message:

$ doas machinectl shell user@machine
Failed to get shell PTY: Unit container-shell@1.service already exists.

But this unit does not exists:

$ doas systemctl list-units 'container-shell*'
  UNIT LOAD ACTIVE SUB DESCRIPTION
0 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

And I cannot kill it:

$ doas systemctl kill container-shell@1.service
Failed to kill unit container-shell@1.service: Unit container-shell@1.service not loaded.

1 Answers1

0

This is because your last shell didn't terminate correctly. It was most likely killed by another process. (by systemd-oomd?)

The unit container-shell@1.service in question, is inside the machine itself. You can use systemctl -M <machine_name> … to invoke commands inside the machine, and fix it:

$ doas systemctl -M machine list-units 'container-shell*'
  UNIT                      LOAD   ACTIVE SUB    DESCRIPTION
● container-shell@1.service loaded failed failed Shell for User user

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
1 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

You should be able to also clean it by just starting the failed unit again, thus forcing it to clean after itself:

$ doas systemctl -M machine start container-shell@1.service
$ doas systemctl -M machine list-units 'container-shell*'
  UNIT LOAD ACTIVE SUB DESCRIPTION
0 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
$ doas machinectl shell root@machine
Connected to machine machine. Press ^] three times within 1s to exit session.
root@machine:~# profit!!!