examples/jail.rb
author Mahlon E. Smith <mahlon@martini.nu>
Tue, 03 Mar 2009 22:23:45 +0000
changeset 7 4460fc10c6a3
permissions -rwxr-xr-x
* Now with 87% more hot jail action! * Predeclared all C methods in jail.h, so they could be arranged in logical order in jail.c * Fixed the extconf namespace. * Added rdoc. * Added usage examples, demonstrating jls, jexec, and jail ruby equivalents. * Re-added the "attach and execute within a block" code. * Added Enumerable and Comparable support. * Return 'path' as a Pathname object. TODO: * Create the actual 'jParallel' shell binary, now that we have a good backend framework. * Tests? How? * Add support for recently committed (will be part of 7.2-RELEASE) multiple IPs per jail, and jail labels.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     1
#!/usr/bin/env ruby
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     2
#
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     3
# An example 'jail' utility in ruby.
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     4
#
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     5
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     6
BEGIN {
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     7
        require 'pathname'
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     8
        basedir = Pathname.new( __FILE__ ).dirname.parent
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     9
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    10
        $LOAD_PATH.unshift basedir + "ext" unless 
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    11
                $LOAD_PATH.include? basedir + "ext"
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    12
}
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    13
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    14
require 'jail'
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    15
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    16
jid = BSD::Jail.create( '127.0.0.1', '/tmp', 'testjail' )
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    17
puts "New jail created with id: %d" % [ jid ]
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    18
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    19
# We're in the jail, now.
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    20
Dir.foreach('.') { |i| puts i }
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    21