mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 06:17:36 -02:30
Display error message if awx-manage/tower-manage are run as a user other than root or awx.
This commit is contained in:
@@ -74,8 +74,18 @@ def manage():
|
|||||||
# Prepare the AWX environment.
|
# Prepare the AWX environment.
|
||||||
prepare_env()
|
prepare_env()
|
||||||
# Now run the command (or display the version).
|
# Now run the command (or display the version).
|
||||||
|
from django.conf import settings
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
if len(sys.argv) >= 2 and sys.argv[1] in ('version', '--version'): # pragma: no cover
|
if len(sys.argv) >= 2 and sys.argv[1] in ('version', '--version'): # pragma: no cover
|
||||||
sys.stdout.write('%s\n' % __version__)
|
sys.stdout.write('%s\n' % __version__)
|
||||||
|
# If running as a user without permission to read settings, display an
|
||||||
|
# error message. Allow --help to still work.
|
||||||
|
elif getattr(settings, 'MUST_BE_ROOT_OR_AWX', False):
|
||||||
|
if len(sys.argv) == 1 or len(sys.argv) >= 2 and sys.argv[1] in ('-h', '--help'):
|
||||||
|
execute_from_command_line(sys.argv)
|
||||||
|
sys.stdout.write('\n')
|
||||||
|
prog = os.path.basename(sys.argv[0])
|
||||||
|
sys.stdout.write('%s must be run as root or awx.\n' % prog)
|
||||||
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
execute_from_command_line(sys.argv)
|
execute_from_command_line(sys.argv)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
# Production settings for AWX project.
|
# Production settings for AWX project.
|
||||||
|
|
||||||
# Python
|
# Python
|
||||||
|
import errno
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
@@ -74,13 +75,18 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except IOError:
|
except IOError, e:
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
included_file = locals().get('__included_file__', '')
|
included_file = locals().get('__included_file__', '')
|
||||||
if (not included_file or included_file == settings_file) and not os.path.exists(settings_file):
|
if (not included_file or included_file == settings_file) and not os.path.exists(settings_file):
|
||||||
if 'AWX_SETTINGS_FILE' not in os.environ:
|
if e.errno == errno.EACCES:
|
||||||
|
MUST_BE_ROOT_OR_AWX = True
|
||||||
|
elif 'AWX_SETTINGS_FILE' not in os.environ:
|
||||||
msg = 'No AWX configuration found at %s.' % settings_file
|
msg = 'No AWX configuration found at %s.' % settings_file
|
||||||
msg += '\nDefine the AWX_SETTINGS_FILE environment variable to '
|
msg += '\nDefine the AWX_SETTINGS_FILE environment variable to '
|
||||||
msg += 'specify an alternate path.'
|
msg += 'specify an alternate path.'
|
||||||
raise ImproperlyConfigured(msg)
|
raise ImproperlyConfigured(msg)
|
||||||
raise
|
else:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user