From 80aaef13b8b241b575999ffbc49d1ca5bee32f49 Mon Sep 17 00:00:00 2001 From: Martyn Smith Date: Tue, 3 Apr 2007 22:51:00 +1200 Subject: [PATCH] Allow context numbers for vservers to be customised This patch adds a subroutine that returns a unique context number for a new vserver to use, so now more than one vserver can be created with this script. Conflicts: vserverctl --- vserverctl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/vserverctl b/vserverctl index e7371b3..7386c12 100755 --- a/vserverctl +++ b/vserverctl @@ -102,6 +102,7 @@ if ( $action eq 'add' ) { close $scriptFH; write_file('/etc/vservers/' . $vsname . "/profile", $profile . "\n"); + write_file('/etc/vservers/' . $vsname . '/context', getFreeContext() . "\n"); system('vserver', $vsname, 'start'); @@ -262,5 +263,19 @@ sub getFreeIPAddress { # {{{ return undef; } # }}} +sub getFreeContext { # {{{ + my $existingContext = { 1 => 1 }; + foreach my $contextFile ( glob '/etc/vservers/*/context' ) { + my $context = slurp($contextFile); + next unless $context =~ m{ \A \s* (\d+) \s* \z }xms; + $existingContext->{$1} = 1; + } + + # Note: probably should allow more than 255 vservers here + for ( my $i = 101; $i < 255 ; $i++ ) { + return "$i" unless $existingContext->{$i}; + } + return undef; +} # }}} -- 2.39.5