From patchwork Wed Sep 23 00:51:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 521525 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id AEEBC1401AF for ; Wed, 23 Sep 2015 10:52:09 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id CF22510A0F; Tue, 22 Sep 2015 17:51:36 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v1.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 539D7109F8 for ; Tue, 22 Sep 2015 17:51:33 -0700 (PDT) Received: from bar3.cudamail.com (bar1 [192.168.15.1]) by mx3v1.cudamail.com (Postfix) with ESMTP id CF8B2618036 for ; Tue, 22 Sep 2015 18:51:32 -0600 (MDT) X-ASG-Debug-ID: 1442969492-03dd7b044708e40001-byXFYA Received: from mx3-pf3.cudamail.com ([192.168.14.3]) by bar3.cudamail.com with ESMTP id 2xJ6hvGWPAEUP3GD (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 22 Sep 2015 18:51:32 -0600 (MDT) X-Barracuda-Envelope-From: azhou@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.3 Received: from unknown (HELO mail-pa0-f46.google.com) (209.85.220.46) by mx3-pf3.cudamail.com with ESMTPS (RC4-SHA encrypted); 23 Sep 2015 00:51:32 -0000 Received-SPF: unknown (mx3-pf3.cudamail.com: Multiple SPF records returned) X-Barracuda-Apparent-Source-IP: 209.85.220.46 X-Barracuda-RBL-IP: 209.85.220.46 Received: by pacex6 with SMTP id ex6so24072892pac.0 for ; Tue, 22 Sep 2015 17:51:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=g1C+/XwLRYrXwpuK6nRanbEwdHx3cx7sYJwHXPXyh0E=; b=HMB8amVTszV/17cHQHcJt73HQE30T1udtzjyFyi+6iNwBHj5jCQFChtbSJgRZak9bG o5no/FGZ0y/oiFPJW9v70W2z4ZeuySnofuAiJja3jc1vzYUZ5+ZHK1XZmsDvSXmiNPWH BO0HqHVXy/CTnO8efvztyW4zkD0x54RXILZgSCkwMdvmX56AIWXWek33KjkX5jPh8IA5 TP2deZTUysJXnb5BUb8xLdivWdZTu6HMQCNynj3LHWMof2SlSx4ZU9I2akOjJZHdorMz STKm83jiWRKUL2flilPBXxA4mM8NrZT3RCVWtoUtNjAhl1PWvTPkb50xedaoL5fYfqdo u/Ig== X-Gm-Message-State: ALoCoQncqdxrlYI8hnxKVoXYsTwupBOHkayw1aj1gucft4R5k8BPBMn4GiHUR92Gz1q+X86BWspN X-Received: by 10.68.202.9 with SMTP id ke9mr34505410pbc.85.1442969491895; Tue, 22 Sep 2015 17:51:31 -0700 (PDT) Received: from ubuntu.localdomain ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id qn5sm4441160pbc.74.2015.09.22.17.51.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Sep 2015 17:51:31 -0700 (PDT) X-CudaMail-Envelope-Sender: azhou@nicira.com From: Andy Zhou To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V3-921070340 X-CudaMail-DTE: 092215 X-CudaMail-Originating-IP: 209.85.220.46 Date: Tue, 22 Sep 2015 17:51:16 -0700 X-ASG-Orig-Subj: [##CM-V3-921070340##][PATCH 7/8] ovs-dev.py: add --user and -u option Message-Id: <1442969477-11026-7-git-send-email-azhou@nicira.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1442969477-11026-1-git-send-email-azhou@nicira.com> References: <1442969477-11026-1-git-send-email-azhou@nicira.com> X-Barracuda-Connect: UNKNOWN[192.168.14.3] X-Barracuda-Start-Time: 1442969492 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH 7/8] ovs-dev.py: add --user and -u option X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" ovs-dev.py "run" command now accepts the "--user" option for running all ovs daemons as "user". The argument can be specified in "user[:group]" format. '-u' is an short hand option that, if ovs-dev.py is launched as an non-root user, then current user and group will be used as if they are supplied by the --user option. "./ovs-dev.py run -u" can now launch ovsdb-server and ovs-vswitchd as current user and group. Signed-off-by: Andy Zhou --- utilities/ovs-dev.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/utilities/ovs-dev.py b/utilities/ovs-dev.py index 68c9a42..1f9dbd7 100755 --- a/utilities/ovs-dev.py +++ b/utilities/ovs-dev.py @@ -55,9 +55,16 @@ def uname(): return _sh("uname", "-r", capture=True)[0].strip() -def sudo(): +def sudo(run_as_me): if os.geteuid() != 0: - _sh(" ".join(["sudo"] + sys.argv), check=True) + opt = [] + if (run_as_me): + user = subprocess.check_output(["id", "-un"]).strip() + group = subprocess.check_output(["id", "-gn"]).strip() + opt=["--user", user + ":" + group] + sys.argv.remove("-u") + + _sh(" ".join(["sudo"] + sys.argv + opt), check=True) sys.exit(0) def conf(): @@ -191,7 +198,7 @@ commands.append(tag) def kill(): - sudo() + sudo(False) for proc in ["ovs-vswitchd", "ovsdb-server"]: if os.path.exists("%s/run/openvswitch/%s.pid" % (VARDIR, proc)): _sh("ovs-appctl", "-t", proc, "exit", check=False) @@ -201,7 +208,7 @@ commands.append(kill) def reset(): - sudo() + sudo(False) kill() if os.path.exists(VARDIR): shutil.rmtree(VARDIR) @@ -210,7 +217,7 @@ def reset(): commands.append(reset) def run(): - sudo() + sudo(options.as_me) kill() for d in ["log", "run"]: d = "%s/%s" % (VARDIR, d) @@ -231,6 +238,12 @@ def run(): opts = ["--pidfile", "--log-file"] + if (options.user == "") or (options.user == "root:root"): + _sh("chown", "root:root", "-R", RUNDIR) + else: + _sh("chown", options.user, "-R", RUNDIR); + opts = ["--user", options.user] + opts + _sh(*(["ovsdb-server", "--remote=punix:%s/run/db.sock" % VARDIR, "--remote=db:Open_vSwitch,Open_vSwitch,manager_options", @@ -274,7 +287,7 @@ def modinst(): print "Missing modules directory. Is this a Linux system?" sys.exit(1) - sudo() + sudo(False) try: _sh("rmmod", "openvswitch") except subprocess.CalledProcessError, e: @@ -315,7 +328,7 @@ Basic Configuration: # First install the basic requirements needed to build Open vSwitch. sudo apt-get install git build-essential libtool autoconf pkg-config \\ - libssl-dev gdb linux-headers-`uname -r` + libssl-dev gdb libcap-ng linux-headers-`uname -r` # Next clone the Open vSwitch source. git clone https://github.com/openvswitch/ovs.git %(ovs)s @@ -414,6 +427,10 @@ def main(): help="run ovs-vswitchd with dpdk subopts (ended by --)") group.add_option("--clang", dest="clang", action="store_true", help="Use binaries built by clang") + group.add_option("--user", dest="user", action="store", default="", + help="run all daemons as a non root user") + group.add_option("-u", dest="as_me", action="store_true", + help="set --user to the current user") parser.add_option_group(group) @@ -435,6 +452,11 @@ def main(): print "Missing %s." % OVS_SRC doc() + if options.as_me: + if options.user != "": + print "-u and --user can not be specifed at the same time." + sys.exit(1) + for arg in args: for cmd in commands: if arg == cmd.__name__: