lib/dev-lxc/container.rb in dev-lxc-2.3.1 vs lib/dev-lxc/container.rb in dev-lxc-2.3.2

- old
+ new

@@ -36,11 +36,11 @@ super wait(:stopped, 3) end def destroy - shutdown if running? + stop if running? puts "Destroying container '#{self.name}'" super if self.defined? end def sync_mounts(mounts) @@ -83,17 +83,25 @@ authorized_keys_content = String.new authorized_keys_content = authorized_keys.join("\n") + "\n" unless authorized_keys.empty? IO.write("#{config_item('lxc.rootfs')}#{dot_ssh_path}/authorized_keys", authorized_keys_content) end - def run_command(command) + def run_command(command, output_file=nil) unless running? puts "ERROR: Container '#{self.name}' must be running first" exit 1 end attach_opts = { wait: true, env_policy: LXC::LXC_ATTACH_CLEAR_ENV, extra_env_vars: ['HOME=/root'] } - attach(attach_opts) do - LXC.run_command(command) + if output_file + file = File.open(output_file, 'w+') + attach_opts[:stdout] = file + end + begin + attach(attach_opts) do + LXC.run_command(command) + end + ensure + file.close if file end end def install_package(package_path) unless run_command("test -e #{package_path}") == 0