Skip to content

Commit

Permalink
Unmounting all mountpoints before stopping container.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Martynova committed May 27, 2013
1 parent e585f19 commit 2c483df
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion src/lib/Lxctl/stop.pm
Expand Up @@ -4,8 +4,15 @@ use strict;
use warnings;

use Lxc::object;
use LxctlHelpers::config;
use File::Path;

my $config = new LxctlHelpers::config;

my $yaml_conf_dir;
my $lxc;
my %options = ();
my $root_path;

sub do
{
Expand All @@ -14,6 +21,46 @@ sub do
$options{'contname'} = shift
or die "Name the container please!\n\n";

my $vm_option_ref;
my %vm_options;
$vm_option_ref = $config->load_file("$yaml_conf_dir/$options{'contname'}.yaml");
%vm_options = %$vm_option_ref;

my @mount_points;
my $mount_result = `mount`;

if (defined $vm_options{'mountpoints'}) {
my $mount_ref = $vm_options{'mountpoints'};

@mount_points = @$mount_ref;
if ($#mount_points == -1 ) {
#print "No mount points specified!\n";
last;
}

foreach my $mp_ref (@mount_points) {
my %mp = %$mp_ref;
my $cmd = "umount";
my $to = quotemeta("$root_path/$options{'contname'}/rootfs$mp{'to'}");

if ($mount_result =~ /on $to/) {
$cmd .= " $to";
system("$cmd");
if ( $? != 0 ) {
print "Can't umount $mp{'to'} !";
}
}
}
}

if (defined $vm_options{'rootfs_mp'}{'to'}) {
my $cmd = "umount $vm_options{'rootfs_mp'}{'to'}";
system("$cmd");
if ( $? != 0 ) {
print "Can't umount $vm_options{'rootfs_mp'}{'to'} !";
}
}

eval {
$self->{'lxc'}->stop($options{'contname'});
print "It seems that \"$options{'contname'}\" is stopped now\n";
Expand All @@ -30,8 +77,11 @@ sub new
my $class = shift;
my $self = {};
bless $self, $class;


$lxc = Lxc::object->new;
$self->{'lxc'} = Lxc::object->new;
$yaml_conf_dir = $lxc->get_yaml_config_path();
$root_path = $lxc->get_root_mount_path();

return $self;
}
Expand Down

0 comments on commit 2c483df

Please sign in to comment.