]> git.mjollnir.org Git - vserverctl.git/commitdiff
Allow context numbers for vservers to be customised
authorMartyn Smith <martyn@catalyst.net.nz>
Tue, 3 Apr 2007 10:51:00 +0000 (22:51 +1200)
committerMartyn Smith <martyn@sear.home>
Tue, 3 Apr 2007 10:51:00 +0000 (22:51 +1200)
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

index e7371b333647cbfb9eafdfc449de13ebf9e40e47..7386c123cb0b225b3456b37a553f6b99bc7e3a8c 100755 (executable)
@@ -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;
+} # }}}