[ovs-dev] [PATCH 7/8] ovs-dev.py: add --user and -u option

Joe Stringer joestringer at nicira.com
Thu Oct 1 00:25:04 UTC 2015


On 22 September 2015 at 17:51, Andy Zhou <azhou at nicira.com> wrote:
> 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 <azhou at nicira.com>

I would have expected "-u" to be short-form for "--user", but they're
subtly different. I'd prefer to see this represented one way, either
the most common or the most flexible. If you really want to save
characters, you could always alias it :-)

I think this should also simplify the user handling inside, and make
it more self-consistent.

> ---
>  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)

So, if you're running as yourself, you sudo to yourself; if you're
running as a different user, you sudo to root, and if you're running
as root you also sudo to root?

<snip>

> @@ -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
> +

So.. if you're running "as_me", then everything will be chowned root:root?



More information about the dev mailing list