Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

On Ubuntu 14.04, I have created an unprivileged container that I can manually start and stop.

But I would like this to start and stop along with the system.

I have added the following to the container's configuration: lxc.start.auto = 1 lxc.start.delay = 5

However, the system scripts don't seem to pick unprivileged containers.

There is a thread related to this on linuxcontainers.org, but the solution seems to be restricted to root user.

Is there a clean way to do this for a non-root user (with root user's consent)?

share|improve this question

3 Answers 3

I'd recommend using the handy @reboot alias in Ubuntu's cron to run lxc-autostart.

As the user that owns the unprivileged container, run crontab -e and add the following line:

@reboot lxc-autostart

share|improve this answer
This sounds great. However, there doesn't seem to be a way to run a command on shutdown (via cron). Any ideas? –  HRJ Jan 30 at 1:48
I'm not aware of any simple ways to run a job at shutdown. You'd probably have to, as root, add an upstart job to shutdown containers for each user that owns them. You could look at /etc/init/lxc.conf for pointers. It's the upstart job that starts the privileged containers. It shouldn't be too hard to copy it and modify it to shutdown unprivileged containers as well. –  encoded Jan 30 at 4:29
It occurs to me that, since each process in the container is visible from the host, the container likely doesn't need anything special to shut it down, each process should receive the TERM signal from the host. Chances are you don't need to do anything special on shutdown. If you want to run some scripts or other such things on shutdown, that's different, but most of the processes should have a chance to shutdown normally. –  encoded Jan 30 at 19:30
Does the crontab approach work? On Ubuntu 14.04, I get the "call to cgmanager_move_pid_sync failed: invalid request" error which occurs because PAM, namely libpam-systemd is not involved in the user changing process. You can see in /proc/self/cgroup that it contains sequences like /user/0.user/1.session instead of /user/1000.user/1.session –  Daniel Alder May 23 at 12:20

Assuming (which are the mother of all ways to screw things up), you are logging in as the user which "owns" the unprivileged lxc container, then the following command should address what you are looking for...

$ echo "lxc-start -n LXC-CONTAINER-NAME -d" >> .bashrc

This will simply run the above command when you log in via bash. This is also assuming that bash is the login shell. Please replace the name: LXC-CONTAINER-NAME with the name of your LXC container which you'd like to start.

share|improve this answer

I've written a small script to work around the issue, just follow the commented instructions.

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.