forked from mirrors/nixpkgs
Merge pull request #39717 from peterhoeg/f/container
nixos-container: support restarts
This commit is contained in:
commit
236a9189e3
|
@ -242,11 +242,21 @@ sub terminateContainer {
|
||||||
while ( kill 0, $leader ) { Time::HiRes::sleep(0.1) }
|
while ( kill 0, $leader ) { Time::HiRes::sleep(0.1) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub startContainer {
|
||||||
|
system("systemctl", "start", "container\@$containerName") == 0
|
||||||
|
or die "$0: failed to start container\n";
|
||||||
|
}
|
||||||
|
|
||||||
sub stopContainer {
|
sub stopContainer {
|
||||||
system("systemctl", "stop", "container\@$containerName") == 0
|
system("systemctl", "stop", "container\@$containerName") == 0
|
||||||
or die "$0: failed to stop container\n";
|
or die "$0: failed to stop container\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub restartContainer {
|
||||||
|
stopContainer;
|
||||||
|
startContainer;
|
||||||
|
}
|
||||||
|
|
||||||
# Run a command in the container.
|
# Run a command in the container.
|
||||||
sub runInContainer {
|
sub runInContainer {
|
||||||
my @args = @_;
|
my @args = @_;
|
||||||
|
@ -285,9 +295,12 @@ if ($action eq "destroy") {
|
||||||
unlink($confFile) or die;
|
unlink($confFile) or die;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
elsif ($action eq "restart") {
|
||||||
|
restartContainer;
|
||||||
|
}
|
||||||
|
|
||||||
elsif ($action eq "start") {
|
elsif ($action eq "start") {
|
||||||
system("systemctl", "start", "container\@$containerName") == 0
|
startContainer;
|
||||||
or die "$0: failed to start container\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ($action eq "stop") {
|
elsif ($action eq "stop") {
|
||||||
|
|
Loading…
Reference in a new issue