From 1f0b5c88d326caf06551748db33ed664dbc4a46e Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Sat, 4 Feb 2012 00:02:41 +0100 Subject: [PATCH] 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 --- bin/nova-manage | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/nova-manage b/bin/nova-manage index e89923d3..6b15dea6 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()