destroying containers from code doesn't sync with lxc-ls
bararchy opened this issue · 5 comments
I created 10 containers, then, destroyed them all (muahaha).
Looking at lxc-ls and ifconfig I can see that the containers are still "running" but trying to execute lxc-destroy --name *** gives back an error
f87efd19-4594-407d-9b18-712273144675 RUNNING 10.0.3.130 - - NO
root@Sphere:/var/lib/lxc# lxc-destroy --name f87efd19-4594-407d-9b18-712273144675
Container is not defined
looking at /var/lib/lxc shows an empty dir.
So it seems I got "phantom" containers ?
Hi Bar
Can you share the script you ran that resulted in this mess? :)
Em 14 de jan de 2016, às 11:36, Bar Hofesh notifications@github.com escreveu:
I created 10 containers, then, destroyed them all (muahaha).
Looking at lxc-ls and ifconfig I can see that the containers are still "running" but trying to execute lxc-destroy --name *** gives back an errorf87efd19-4594-407d-9b18-712273144675 RUNNING 10.0.3.130 - - NO
root@Sphere:/var/lib/lxc# lxc-destroy --name f87efd19-4594-407d-9b18-712273144675
Container is not defined
looking at /var/lib/lxc shows an empty dir.So it seems I got "phantom" containers ?
—
Reply to this email directly or view it on GitHub.
Sure,
To create I use this:
def create_container
container_name = SecureRandom.uuid
c = LXC::Container.new(container_name)
begin
c.create('ubuntu')
c.start
SYSLOGGER.info("Pool: Starting container: #{c.name}")
rescue => e
SYSLOGGER.error("Pool: Error starting container #{c.name}: #{e}")
end
return c if c
end
To destroy I use this:
def destroy_container(c)
container_name = c.name
try = 0
begin
while c.running?
SYSLOGGER.debug("Container: Shutting down container #{c.name}...")
c.shutdown(-1)
sleep 0.1 while c.running?
SYSLOGGER.debug("Container: Stopping container #{c.name}...")
c.stop
c.wait(:stopped, 5)
SYSLOGGER.debug("Container: Destroying container #{c.name}...")
c.destroy
SYSLOGGER.debug("Container: Clearing config for container #{c.name}...")
c.clear_config
end
SYSLOGGER.info("Container: Container #{container_name} closed")
rescue => e
SYSLOGGER.error("Container: Error stopping Container #{container_name}: #{e}")
sleep 2
try += 1
if try < 3
retry
else
@running = true
end
end
end
So i basically did something like
container_array = []
10.times do
container_array << create_container
end
container_array.each do |c|
destroy_container(c)
end
what distro you are using? Can you run the script and print lxcpath as part of it?
puts LXC.global_config_item('lxc.lxcpath')
fwiw, I tried your script (with unprivileged containers) and it worked fine for me.
Hi @ranjib , I'm running:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu Xenial Xerus (development branch)"
puts LXC.global_config_item('lxc.lxcpath')
=> /var/lib/lxc
I'm running with Privileged containers.
Ruby:
ruby --version
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]