From b95a24fdf1f751c44282f6c38b84b763a85eee19 Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Fri, 20 Apr 2018 11:07:07 +0800 Subject: [PATCH] nixos-container: support restarts --- .../nixos-container/nixos-container.pl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pkgs/tools/virtualization/nixos-container/nixos-container.pl b/pkgs/tools/virtualization/nixos-container/nixos-container.pl index 2cb723a7b71a..a210a65f431c 100755 --- a/pkgs/tools/virtualization/nixos-container/nixos-container.pl +++ b/pkgs/tools/virtualization/nixos-container/nixos-container.pl @@ -242,11 +242,21 @@ sub terminateContainer { 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 { system("systemctl", "stop", "container\@$containerName") == 0 or die "$0: failed to stop container\n"; } +sub restartContainer { + stopContainer; + startContainer; +} + # Run a command in the container. sub runInContainer { my @args = @_; @@ -285,9 +295,12 @@ if ($action eq "destroy") { unlink($confFile) or die; } +elsif ($action eq "restart") { + restartContainer; +} + elsif ($action eq "start") { - system("systemctl", "start", "container\@$containerName") == 0 - or die "$0: failed to start container\n"; + startContainer; } elsif ($action eq "stop") {