How to disable Autostart of Lxc containers

How to disable Autostart of Lxc containers

 

I’ve stopped the lxc containers but the Autostart option shows enabled.
 

root@server:/# lxc-ls –fancy
NAME STATE IPV4 IPV6 AUTOSTART
———————————————————
server-qa STOPPED – – YES
server2 STOPPED – – YES

 
You can see Autostart shows YES for the above containers. Please follow the below steps to disable Autostart of Lxc containers.

1. Open a new Terminal

2. Log into your Lxc server via SSH as ‘root’ user

3. Go to /var/lib/lxc directory
 

root@server:/var/lib/lxc# cd /var/lib/lxc

root@server:/var/lib/lxc# ls -l

 
4. Type ‘ls -l’ to list all containers in your server

5. Change to container directory using cd command

6. Edit the config file in this directory using vi command
 

root@server:/var/lib/lxc/mysql# ls -l
total 8
-rw-r–r– 1 root root 1279 Jun 8 17:09 config
drwxr-xr-x 22 root root 4096 Jun 8 16:59 rootfs
-rw——- 1 root root 0 Aug 19 2014 rootfs.hold

root@server:/var/lib/lxc/mysql# vi config

 

7. Change “lxc.start.auto = 1” to “lxc.start.auto = 0”

This will disable the container autostart.

8. Now run the command ‘lxc-ls –fancy’ to confirm
 
 

How to enable autostart of Lxc containers

 
1. Log into Lxc server

2. Edit the config file under the container using vi editor
 

vi /var/lib/lxc/[container_name]/config

 
3. You should change “lxc.start.auto = 0” to “lxc.start.auto = 1”

4. Execute the command ‘lxc-ls –fancy’ to make sure Autostart is disabled
 

root@server:/# lxc-ls –fancy
NAME STATE IPV4 IPV6 AUTOSTART
———————————————————
server-qa STOPPED – – NO
server2 STOPPED – – NO