Skip to content

Commit

Permalink
[Cont] Support restarting LXD-based LXC containers (github issue #26
Browse files Browse the repository at this point in the history
…by James Johnston @JohnstonJ).
  • Loading branch information
liske committed Dec 10, 2016
1 parent 61592f1 commit e584a67
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ needrestart (2.11) unstable; urgency=medium
* Features:
- [Core] Allow special treatment to restart services (i.e. dbus).
(github issue #44 by @Vladimir-csp)
- [Cont] Support restarting LXD-based LXC containers.
(github issue #26 by James Johnston @JohnstonJ)
* Fixes:
- [Core] Fix default config type for override_* settings.
(github issue #47 by @mphilipps)
Expand Down
19 changes: 13 additions & 6 deletions perl/lib/NeedRestart/CONT/LXC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ sub new {
die "Could not get NS PID of #1!\n" unless(defined($self->{nspid}));

$self->{lxc} = {};
$self->{lxd} = {};

$self->{has_lxd} = -x q(/usr/bin/lxc);

return bless $self, $class;
}

Expand All @@ -68,16 +72,17 @@ sub check {
}

# look for LXC cgroups
return 0 unless($cg =~ /^\d+:[^:]+:\/lxc\/([^\/\n]+)($|\/)/m);
return unless($cg =~ /^\d+:[^:]+:\/lxc\/([^\/\n]+)($|\/)/m);

my $name = $1;
my $type = ($self->{has_lxd} && -d qq(/var/lib/lxd/containers/$name) ? 'LXD' : 'LXC');
unless($norestart) {
print STDERR "$LOGPREF #$pid is part of LXC container '$name' and should be restarted\n" if($self->{debug});
print STDERR "$LOGPREF #$pid is part of $type container '$name' and should be restarted\n" if($self->{debug});

$self->{lxc}->{$name}++;
$self->{lc($type)}->{$name}++;
}
else {
print STDERR "$LOGPREF #$pid is part of LXC container '$name'\n" if($self->{debug});
print STDERR "$LOGPREF #$pid is part of $type container '$name'\n" if($self->{debug});
}

return 1;
Expand All @@ -86,9 +91,11 @@ sub check {
sub get {
my $self = shift;

return map {
return (map {
($_ => [qw(lxc-stop --reboot --name), $_]);
} keys %{ $self->{lxc} };
} keys %{ $self->{lxc} }), (map {
($_ => [qw(lxc restart), $_]);
} keys %{ $self->{lxd} });
}

1;

0 comments on commit e584a67

Please sign in to comment.