Improve error messaging if the storage and log directories cannot be created. Fixes #5576
parent
67c978b7a4
commit
a0c19252df
|
@ -9,6 +9,7 @@ This release contains a number of bug fixes and new features since the release o
|
|||
New features
|
||||
************
|
||||
|
||||
| `Issue #5576 <https://redmine.postgresql.org/issues/5576>`_ - Improve error messaging if the storage and log directories cannot be created.
|
||||
|
||||
Housekeeping
|
||||
************
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
##########################################################################
|
||||
|
||||
import os
|
||||
from flask import current_app
|
||||
import pwd
|
||||
|
||||
|
||||
def _create_directory_if_not_exists(_path):
|
||||
|
@ -21,7 +21,22 @@ def create_app_data_directory(config):
|
|||
Create the required directories (if not present).
|
||||
"""
|
||||
# Create the directory containing the configuration file (if not present).
|
||||
_create_directory_if_not_exists(os.path.dirname(config.SQLITE_PATH))
|
||||
try:
|
||||
_create_directory_if_not_exists(os.path.dirname(config.SQLITE_PATH))
|
||||
except PermissionError as e:
|
||||
print("ERROR : Failed to create the directory {}:\n {}".
|
||||
format(os.path.dirname(config.SQLITE_PATH), e))
|
||||
print(
|
||||
"HINT : Create the directory {}, ensure it is writeable by\n"
|
||||
" '{}', and try again, or, create a config_local.py file\n"
|
||||
" and override the SQLITE_PATH setting per\n"
|
||||
" https://www.pgadmin.org/docs/pgadmin4/{}/config_py.html".
|
||||
format(
|
||||
os.path.dirname(config.SQLITE_PATH),
|
||||
pwd.getpwuid(os.getuid()).pw_name,
|
||||
config.APP_VERSION))
|
||||
exit(1)
|
||||
|
||||
# Try to set the permissions on the directory, but don't complain
|
||||
# if we can't. This may be the case on a mounted directory, e.g. in
|
||||
# OpenShift. We'll still secure the config database anyway.
|
||||
|
@ -31,15 +46,62 @@ def create_app_data_directory(config):
|
|||
except Exception as e:
|
||||
# The flask app isn't setup yet, so we can't use the logger
|
||||
print('WARNING: Failed to set ACL on the directory containing the '
|
||||
'configuration database: {}'.format(e))
|
||||
'configuration database:\n {}'.format(e))
|
||||
print("HINT : You may need to manually set the permissions on\n"
|
||||
" {} to allow {} to write to it.".
|
||||
format(os.path.dirname(config.SQLITE_PATH),
|
||||
pwd.getpwuid(os.getuid()).pw_name))
|
||||
|
||||
# Create the directory containing the log file (if not present).
|
||||
_create_directory_if_not_exists(os.path.dirname(config.LOG_FILE))
|
||||
try:
|
||||
_create_directory_if_not_exists(os.path.dirname(config.LOG_FILE))
|
||||
except PermissionError as e:
|
||||
print("ERROR : Failed to create the directory {}:\n {}".
|
||||
format(os.path.dirname(config.LOG_FILE), e))
|
||||
print(
|
||||
"HINT : Create the directory {}, ensure it is writeable by\n"
|
||||
" '{}', and try again, or, create a config_local.py file\n"
|
||||
" and override the LOG_FILE setting per\n"
|
||||
" https://www.pgadmin.org/docs/pgadmin4/{}/config_py.html".
|
||||
format(
|
||||
os.path.dirname(config.LOG_FILE),
|
||||
pwd.getpwuid(os.getuid()).pw_name,
|
||||
config.APP_VERSION))
|
||||
exit(1)
|
||||
|
||||
# Create the session directory (if not present).
|
||||
_create_directory_if_not_exists(config.SESSION_DB_PATH)
|
||||
try:
|
||||
_create_directory_if_not_exists(config.SESSION_DB_PATH)
|
||||
except PermissionError as e:
|
||||
print("ERROR : Failed to create the directory {}:\n {}".
|
||||
format(config.SESSION_DB_PATH, e))
|
||||
print(
|
||||
"HINT : Create the directory {}, ensure it is writeable by\n"
|
||||
" '{}', and try again, or, create a config_local.py file\n"
|
||||
" and override the SESSION_DB_PATH setting per\n"
|
||||
" https://www.pgadmin.org/docs/pgadmin4/{}/config_py.html".
|
||||
format(
|
||||
config.SESSION_DB_PATH,
|
||||
pwd.getpwuid(os.getuid()).pw_name,
|
||||
config.APP_VERSION))
|
||||
exit(1)
|
||||
|
||||
if os.name != 'nt':
|
||||
os.chmod(config.SESSION_DB_PATH, 0o700)
|
||||
|
||||
# Create the storage directory (if not present).
|
||||
_create_directory_if_not_exists(config.STORAGE_DIR)
|
||||
try:
|
||||
_create_directory_if_not_exists(config.STORAGE_DIR)
|
||||
except PermissionError as e:
|
||||
print("ERROR : Failed to create the directory {}\n {}:".
|
||||
format(config.STORAGE_DIR, e))
|
||||
print(
|
||||
"HINT : Create the directory {}, ensure it is writable by\n"
|
||||
" '{}', and try again, or, create a config_local.py file\n"
|
||||
" and override the STORAGE_DIR setting per\n"
|
||||
" https://www.pgadmin.org/docs/pgadmin4/{}/config_py.html".
|
||||
format(
|
||||
config.STORAGE_DIR,
|
||||
pwd.getpwuid(os.getuid()).pw_name,
|
||||
config.APP_VERSION))
|
||||
exit(1)
|
||||
|
|
Loading…
Reference in New Issue