diff options
| author | Soren Hansen <soren@linux2go.dk> | 2012-02-04 00:02:41 +0100 |
|---|---|---|
| committer | Soren Hansen <soren@linux2go.dk> | 2012-02-04 00:26:26 +0100 |
| commit | e9fd01e58b6a83b400ce9825f2543cb6ef476f00 (patch) | |
| tree | 33da6872d80a694f3796e0528d962835b8d3cf84 | |
| parent | 61c434baa77fa2744cac81f64957da319078614e (diff) | |
Re-run nova-manage under sudo if unable to read conffile
Having to manually sudo to the nova user to make things work is
tedious. Make it so that if we can't read the conffile, we just
re-exec under sudo.
Fixes bug 805695
Change-Id: I322cece80ca757c69147fb3f8474ad137d9bff82
| -rwxr-xr-x | bin/nova-manage | 11 | ||||
| -rw-r--r-- | nova/utils.py | 3 |
2 files changed, 12 insertions, 2 deletions
diff --git a/bin/nova-manage b/bin/nova-manage index e89923d3c..6b15dea63 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -2307,7 +2307,16 @@ def methods_of(obj): def main(): """Parse options and call the appropriate class/method.""" - utils.default_flagfile() + flagfile = utils.default_flagfile() + + if flagfile and not os.access(flagfile, os.R_OK): + st = os.stat(flagfile) + print "Could not read %s. Re-running with sudo" % flagfile + try: + os.execvp('sudo', ['sudo', '-u', '#%s' % st.st_uid] + sys.argv) + except: + print 'sudo failed, continuing as if nothing happened' + argv = FLAGS(sys.argv) logging.setup() diff --git a/nova/utils.py b/nova/utils.py index 72e1cd3e0..c93b48fc6 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -325,7 +325,7 @@ def default_flagfile(filename='nova.conf', args=None): args = sys.argv for arg in args: if arg.find('flagfile') != -1: - break + return arg[arg.index('flagfile') + 1:] else: if not os.path.isabs(filename): # turn relative filename into an absolute path @@ -338,6 +338,7 @@ def default_flagfile(filename='nova.conf', args=None): if os.path.exists(filename): flagfile = '--flagfile=%s' % filename args.insert(1, flagfile) + return filename def debug(arg): |
