Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

destroying containers from code doesn't sync with lxc-ls #38

Open
bararchy opened this issue Jan 14, 2016 · 5 comments
Open

destroying containers from code doesn't sync with lxc-ls #38

bararchy opened this issue Jan 14, 2016 · 5 comments

Comments

@bararchy
Copy link

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 ?

@andrenth
Copy link
Contributor

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 [email protected] 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 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 ?


Reply to this email directly or view it on GitHub.

@bararchy
Copy link
Author

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

@bararchy
Copy link
Author

@andrenth , did you had time to check this issue ? Can I help somehow ?

@ranjib
Copy link
Contributor

ranjib commented Jan 24, 2016

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.

@bararchy
Copy link
Author

bararchy commented Feb 7, 2016

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants