Skip to content

Commit ca1a362

Browse files
committed
try with gunicorn
1 parent f9ac9b8 commit ca1a362

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ readme = "README.md"
1414
license = { file = "LICENSE.md" }
1515
requires-python = ">=3.8"
1616
dependencies = [
17-
"jupyter-server-proxy>=3.2.2",
17+
"jupyter-server-proxy>=3.2.2,<4.0.0",
1818
"pgadmin4",
1919
"simple-websocket",
2020
"psycopg",
21-
"uwsgi"
21+
"gunicorn",
2222
]
2323
classifiers = [
2424
"Framework :: Jupyter",

setup/config_system.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424

2525
# from pgadmin.utils import env
2626

27+
28+
TRUTHY = ("true", "1", "yes", "on", "y")
29+
30+
31+
def truthy(val):
32+
return str(val).strip('"').strip("'").lower() in TRUTHY
33+
34+
2735
##########################################################################
2836
# Application settings
2937
##########################################################################
@@ -115,11 +123,11 @@
115123
# SESSION_DB_PATH, STORAGE_DIR, KERBEROS_CCACHE_DIR, and
116124
# AZURE_CREDENTIAL_CACHE_DIR
117125

118-
if (not hasattr(builtins, 'SERVER_MODE')) or builtins.SERVER_MODE is None:
119-
SERVER_MODE = True
120-
else:
121-
SERVER_MODE = builtins.SERVER_MODE
122-
# SERVER_MODE = False
126+
# if (not hasattr(builtins, 'SERVER_MODE')) or builtins.SERVER_MODE is None:
127+
# SERVER_MODE = True
128+
# else:
129+
# SERVER_MODE = builtins.SERVER_MODE
130+
SERVER_MODE = truthy(os.getenv('PGADMIN_SERVER_MODE'))
123131

124132
# HTTP headers to search for CSRF token when it is not provided in the form.
125133
# Default is ['X-CSRFToken', 'X-CSRF-Token']
@@ -334,7 +342,7 @@
334342
# Using PGPASS file
335343
# postgresql://username@host:port?options=-csearch_path=pgadmin
336344
##########################################################################
337-
CONFIG_DATABASE_URI = ''
345+
CONFIG_DATABASE_URI = ""
338346

339347
##########################################################################
340348
# User account and settings storage
@@ -584,7 +592,7 @@
584592
# Master password is used to encrypt/decrypt saved server passwords
585593
# Applicable for desktop mode only
586594
##########################################################################
587-
MASTER_PASSWORD_REQUIRED = True
595+
MASTER_PASSWORD_REQUIRED = truthy(os.getenv("MASTER_PASSWORD_REQUIRED"))
588596

589597
##########################################################################
590598

src/jupyter_pgadmin_proxy/__init__.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import site
77

88
logging.basicConfig(level="INFO")
9-
logger = logging.getLogger("pgadmin")
9+
logger = logging.getLogger("pgAdmin4")
1010
logger.setLevel("INFO")
1111

1212

@@ -24,16 +24,21 @@ def _get_env(port, base_url):
2424
logger.info(f"pgAdmin ENV: {base_url}pgadmin4/")
2525

2626
default_email = os.getenv("PGADMIN_DEFAULT_EMAIL", "[email protected]")
27-
setup_email = os.getenv("PGADMIN_SETUP_EMAIL", "[email protected]")
27+
# setup_email = os.getenv("PGADMIN_SETUP_EMAIL", "[email protected]")
2828
return {
29-
"PGADMIN_SERVER_MODE": 'True',
29+
# "PGADMIN_SERVER_MODE": "True",
30+
# "PGADMIN_SETUP_EMAIL": setup_email,
31+
# "PGADMIN_SETUP_PASSWORD": ".",
3032
"PGADMIN_DEFAULT_EMAIL": default_email,
31-
"PGADMIN_SETUP_EMAIL": setup_email,
32-
"PGADMIN_SETUP_PASSWORD": "",
3333
"PGADMIN_LISTEN_PORT": str(port),
3434
"APPLICATION_ROOT": f"{base_url}pgadmin4/",
3535
"SCRIPT_NAME": f"{base_url}pgadmin4/",
3636
"REMOTE_USER": os.getenv("USER", os.getenv("NB_USER", "nobody")),
37+
"PGHOST": os.getenv("PGHOST"),
38+
"PGPORT": os.getenv("PGPORT"),
39+
"PGDATABASE": os.getenv("PGDATABASE"),
40+
"PGUSER": os.getenv("PGUSER"),
41+
"PGPASSWORD": os.getenv("PGPASSWORD"),
3742
}
3843

3944

@@ -43,7 +48,6 @@ def get_icon_path():
4348
)
4449

4550

46-
4751
def get_system_user():
4852
try:
4953
user = pwd.getpwuid(os.getuid())[0]
@@ -62,36 +66,32 @@ def run_app():
6266

6367
icon_path = get_icon_path()
6468
try:
65-
executable_name = shutil.which("pgadmin4")
69+
executable_name = shutil.which("gunicorn")
6670
except Exception:
67-
executable_name = "pgadmin4"
68-
host = "127.0.0.1"
71+
executable_name = "gunicorn"
6972
user = get_system_user()
7073
try:
7174
chdir_path = f"{site.getsitepackages()[0]}/pgadmin4"
7275
if not os.path.exists(chdir_path):
7376
chdir_path = os.path.dirname(os.path.abspath(__file__))
7477
except Exception:
7578
chdir_path = "/"
76-
logger.debug(f"[{user}] Icon_path: {icon_path}")
79+
logger.debug(f"[{user}] Icon path: {icon_path}")
7780
logger.debug(f"[{user}] Launch Command: {executable_name}")
81+
logger.debug(f"[{user}] pgAdmin path: {chdir_path}")
7882
return {
7983
"command": [
80-
# executable_name,
81-
"uwsgi",
82-
"--http-socket", "127.0.0.1:{port}",
83-
"--mount", "{base_url}pgadmin4/=pgAdmin4:app",
84-
"--chdir", chdir_path,
85-
"--manage-script-name",
86-
"--processes", "1",
87-
"--threads", "25",
88-
"--need-app",
84+
executable_name,
85+
'-b', '127.0.0.1:{port}',
86+
'-e', 'SCRIPT_NAME={base_url}pgadmin',
87+
'--chdir', chdir_path,
88+
'pgAdmin4:app',
8989
],
9090
"timeout": 300,
9191
"environment": _get_env,
9292
"absolute_url": True,
9393
# "rewrite_response": rewrite_netloc,
94-
# "request_headers_override": {"X-Script-Name": "{base_url}pgadmin4/"},
94+
# "request_headers_override": {"X-Script-Name": "{base_url}pgadmin"},
9595
"launcher_entry": {
9696
"title": "pgAdmin4",
9797
"icon_path": icon_path

0 commit comments

Comments
 (0)