|
7 | 7 | import scripts.lib.setup_path_on_import
|
8 | 8 |
|
9 | 9 | if __name__ == "__main__":
|
| 10 | + if 'posix' in os.name and os.geteuid() == 0: |
| 11 | + print("manage.py should not be run as root. Use `su zulip` to drop root.") |
| 12 | + sys.exit(1) |
| 13 | + if (os.access('/etc/zulip/zulip.conf', os.R_OK) and not |
| 14 | + os.access('/etc/zulip/zulip-secrets.conf', os.R_OK)): |
| 15 | + # The best way to detect running manage.py as another user in |
| 16 | + # production before importing anything that would require that |
| 17 | + # access is to check for access to /etc/zulip/zulip.conf (in |
| 18 | + # which case it's a production server, not a dev environment) |
| 19 | + # and lack of access for /etc/zulip/zulip-secrets.conf (which |
| 20 | + # should be only readable by root and zulip) |
| 21 | + print("Error accessing Zulip secrets; manage.py in production must be run as the zulip user.") |
| 22 | + sys.exit(1) |
| 23 | + |
10 | 24 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "zproject.settings")
|
11 | 25 | from django.conf import settings
|
12 | 26 | from django.core.management import execute_from_command_line
|
13 | 27 | from django.core.management.base import CommandError
|
14 | 28 | from scripts.lib.zulip_tools import log_management_command
|
15 | 29 |
|
16 |
| - if 'posix' in os.name and os.geteuid() == 0: |
17 |
| - raise CommandError("manage.py should not be run as root. Use `su zulip` to drop root.") |
18 |
| - |
19 | 30 | log_management_command(" ".join(sys.argv), settings.MANAGEMENT_LOG_PATH)
|
20 | 31 |
|
21 | 32 | os.environ.setdefault("PYTHONSTARTUP", os.path.join(BASE_DIR, "scripts/lib/pythonrc.py"))
|
|
0 commit comments