Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9cdcc59c28 | |||
| 68b28201ad | |||
| ebfc4d0d72 | |||
| 67b06f3a83 | |||
| f510caa0e7 |
+7
-7
@@ -91,6 +91,7 @@ import re
|
||||
import select
|
||||
import signal
|
||||
from time import sleep
|
||||
from subprocess import check_output
|
||||
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import info, error, debug, output
|
||||
@@ -561,13 +562,12 @@ def init():
|
||||
"Initialize Mininet."
|
||||
if init.inited:
|
||||
return
|
||||
if os.getuid() != 0:
|
||||
# Note: this script must be run as root
|
||||
# Perhaps we should do so automatically!
|
||||
print "*** Mininet must run as root."
|
||||
exit( 1 )
|
||||
# If which produces no output, then mnexec is not in the path.
|
||||
# May want to loosen this to handle mnexec in the current dir.
|
||||
# Make sure we can sudo without a password
|
||||
try:
|
||||
check_output( [ 'sudo', '-n', 'echo' ] )
|
||||
except:
|
||||
raise Exception( "Could not run sudo -n echo - check /etc/sudoers" )
|
||||
# Make sure mnexec is in our path
|
||||
if not quietRun( 'which mnexec' ):
|
||||
raise Exception( "Could not find mnexec - check $PATH" )
|
||||
fixLimits()
|
||||
|
||||
+5
-3
@@ -76,12 +76,12 @@ class Node( object ):
|
||||
opts = '-cdp'
|
||||
if self.inNamespace:
|
||||
opts += 'n'
|
||||
cmd = [ 'mnexec', opts, 'bash', '-m' ]
|
||||
cmd = [ 'sudo', '-E', 'env', 'PATH=%s' % os.environ['PATH'],
|
||||
'mnexec', opts, 'bash', '-m', '-p' ]
|
||||
self.shell = Popen( cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT,
|
||||
close_fds=False )
|
||||
self.stdin = self.shell.stdin
|
||||
self.stdout = self.shell.stdout
|
||||
self.pid = self.shell.pid
|
||||
self.pollOut = select.poll()
|
||||
self.pollOut.register( self.stdout )
|
||||
# Maintain mapping between file descriptors and nodes
|
||||
@@ -102,6 +102,8 @@ class Node( object ):
|
||||
self.waiting = False
|
||||
# Stash additional information as desired
|
||||
self.args = kwargs
|
||||
# Read pid from mnexec
|
||||
self.pid = int( self.readline()[ 1: ] )
|
||||
|
||||
@classmethod
|
||||
def fdToNode( cls, fd ):
|
||||
@@ -149,7 +151,7 @@ class Node( object ):
|
||||
|
||||
def terminate( self ):
|
||||
"Send kill signal to Node and clean up after it."
|
||||
os.kill( self.pid, signal.SIGKILL )
|
||||
quietRun( 'kill ' + str( self.pid ) )
|
||||
self.cleanup()
|
||||
|
||||
def stop( self ):
|
||||
|
||||
+23
-4
@@ -1,11 +1,12 @@
|
||||
"Utility functions for Mininet."
|
||||
|
||||
from time import sleep
|
||||
from resource import setrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
|
||||
from resource import setrlimit, getrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
|
||||
import select
|
||||
from subprocess import call, check_call, Popen, PIPE, STDOUT
|
||||
import os
|
||||
|
||||
from mininet.log import error
|
||||
from mininet.log import error, warn
|
||||
|
||||
# Command execution support
|
||||
|
||||
@@ -29,6 +30,7 @@ def quietRun( *cmd ):
|
||||
cmd = cmd[ 0 ]
|
||||
if isinstance( cmd, str ):
|
||||
cmd = cmd.split( ' ' )
|
||||
cmd = ["sudo", "-E", "env", "PATH=%s" % os.environ["PATH"]] + cmd
|
||||
popen = Popen( cmd, stdout=PIPE, stderr=STDOUT )
|
||||
# We can't use Popen.communicate() because it uses
|
||||
# select(), which can't handle
|
||||
@@ -205,5 +207,22 @@ def makeNumeric( s ):
|
||||
|
||||
def fixLimits():
|
||||
"Fix ridiculously small resource limits."
|
||||
setrlimit( RLIMIT_NPROC, ( 4096, 8192 ) )
|
||||
setrlimit( RLIMIT_NOFILE, ( 16384, 32768 ) )
|
||||
manyprocs = 8192
|
||||
manyfiles = 32768
|
||||
minprocs, maxprocs = getrlimit( RLIMIT_NPROC )
|
||||
minfiles, maxfiles = getrlimit( RLIMIT_NOFILE )
|
||||
# Root can raise limits
|
||||
if os.getuid() == 0:
|
||||
maxprocs = max( maxprocs, manyprocs )
|
||||
maxfiles = max( maxfiles, manyfiles )
|
||||
minprocs = min( manyprocs, maxprocs )
|
||||
minfiles = min( manyfiles, maxfiles )
|
||||
setrlimit( RLIMIT_NPROC, ( minprocs, maxprocs ) )
|
||||
setrlimit( RLIMIT_NOFILE, ( minfiles, maxfiles ) )
|
||||
nprocs = max( getrlimit( RLIMIT_NPROC ) )
|
||||
nfiles = max( getrlimit( RLIMIT_NOFILE ) )
|
||||
# Complain if limits are too low
|
||||
if nprocs < manyprocs:
|
||||
warn( '*** Warning: process limit is low:', nprocs, 'procs\n' )
|
||||
if nfiles < manyfiles:
|
||||
warn( '*** Warning: open file limit is low:', nfiles, 'files \n' )
|
||||
|
||||
Reference in New Issue
Block a user