GrahamDumpleton / mod_wsgi

Source code for Apache/mod_wsgi.
Apache License 2.0
1.03k stars 268 forks source link

mod_wsgi is Ok with command “httpd –k start”, but not Ok with “systemctl start httpd.services” #594

Closed James-LP-Wang closed 3 years ago

James-LP-Wang commented 4 years ago

Hi Graham,

Excuse me for the this long posting, but I need help. In a RED HAT 8.0 installation I have created a VENV and installed Django in the VENV, added mod_wsgi to httpd configuration. My problem is the command "sudo systemctl start httpd.services" could not start httpd process. If I run the command “sudo httpd –k start”, eight httpd processes are created, and mod_wsgi works fine, and Django pages are served nicely.

I noticed with "sudo systemctl start httpd.services" the httpd processes are run with the option -DFOREGROUND, and systemctl immediately killed httpd processes. Command “sudo httpd –k start” does not use -DFOREGOURND option for httpd processes. Then I removed -DFOREGROUND from /lib/systemd/system/httpd.service for testing purpose, systemctrl can go further, but it failed with this error "Python error: Py_Initialize: Unable to get the locale encoding".

I confirmed in another test that systemctrl can start and stop httpd beautifully AFTER I removed 10-wsgi-python3.conf from httpd conf.modules.d/ folder.

What could be the cause for systemctl not able to control httpd with mod_wsgi loaded? We are trying to find a solution so that the server can monitor and auto-start Apache server. Your help is much appreciated.

I pasted some info and log at the below for you to see my problem.

(VENV) $ python -V Python 3.6.8

(VENV) $ find ../VENV -name "wsgi" ../VENV/lib/python3.6/site-packages/asgiref/wsgi.py ../VENV/lib/python3.6/site-packages/django/conf/project_template/project_name/wsgi.py-tpl ../VENV/lib/python3.6/site-packages/django/core/handlers/wsgi.py ../VENV/lib/python3.6/site-packages/django/core/wsgi.py ../VENV/lib/python3.6/site-packages/django/contrib/auth/handlers/modwsgi.py

$ rpm -qi python3-mod_wsgi Name : python3-mod_wsgi Version : 4.6.4 Release : 4.el8 Architecture: x86_64 Install Date: Mon 27 Jul 2020 08:12:01 AM EDT Group : System Environment/Libraries Size : 9930670 License : ASL 2.0 Signature : RSA/SHA256, Thu 09 Apr 2020 12:01:58 AM EDT, Key ID 05b555b38483c65d Source RPM : mod_wsgi-4.6.4-4.el8.src.rpm Build Date : Mon 06 Apr 2020 10:41:49 PM EDT Build Host : x86-01.mbox.centos.org Relocations : (not relocatable) Packager : CentOS Buildsys bugs@centos.org Vendor : CentOS URL : https://modwsgi.readthedocs.io/ Summary : A WSGI interface for Python web applications in Apache

$ httpd -V Server version: Apache/2.4.37 (centos) Server built: Jun 8 2020 20:14:33 Server's Module Magic Number: 20120211:83 Server loaded: APR 1.6.3, APR-UTIL 1.6.1 Compiled using: APR 1.6.3, APR-UTIL 1.6.1 Architecture: 64-bit Server MPM: worker threaded: yes (fixed thread count) forked: yes (variable process count) Server compiled with.... -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=256 -D HTTPD_ROOT="/etc/httpd" -D SUEXEC_BIN="/usr/sbin/suexec" -D DEFAULT_PIDLOG="run/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf"

After I ran the command "sudo systemctl start httpd.services", the httpd error_log showed python error:

Current thread 0x00007f3946748940 (most recent call first): [Mon Jul 27 12:31:33.523771 2020] [core:notice] [pid 1293681:tid 139883971905856] AH00052: child pid 1295501 exit signal Aborted (6) [Mon Jul 27 12:31:33.523809 2020] [wsgi:info] [pid 1293681:tid 139883971905856] mod_wsgi (pid=1295501): Process 'my-proc' has died, deregister and restart it. [Mon Jul 27 12:31:33.523812 2020] [wsgi:info] [pid 1293681:tid 139883971905856] mod_wsgi (pid=1295501): Process 'my-proc' terminated by signal 6 [Mon Jul 27 12:31:33.523816 2020] [wsgi:info] [pid 1293681:tid 139883971905856] mod_wsgi (pid=1295501): Process 'my-proc' has been deregistered and will no longer be monitored. [Mon Jul 27 12:31:33.524509 2020] [wsgi:info] [pid 1295511:tid 139883971905856] mod_wsgi (pid=1295511): Starting process 'my-proc' with uid=48, gid=48 and threads=15. [Mon Jul 27 12:31:33.526379 2020] [wsgi:info] [pid 1295511:tid 139883971905856] mod_wsgi (pid=1295511): Python home /var/www/myserver.the-company.com/VENV. [Mon Jul 27 12:31:33.526421 2020] [wsgi:info] [pid 1295511:tid 139883971905856] mod_wsgi (pid=1295511): Initializing Python. Fatal Python error: Py_Initialize: Unable to get the locale encoding ModuleNotFoundError: No module named 'encodings'

After I ran the command “sudo httpd –k start”, the httpd error_log showed everything worked fine, mod_wsgi was Ok.

[Mon Jul 27 12:35:18.812251 2020] [core:notice] [pid 1296008:tid 140120808032576] SELinux policy enabled; httpd running as context unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 [Mon Jul 27 12:35:18.813289 2020] [suexec:notice] [pid 1296008:tid 140120808032576] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Mon Jul 27 12:35:18.813353 2020] [ssl:info] [pid 1296008:tid 140120808032576] AH01887: Init: Initializing (virtual) servers for SSL [Mon Jul 27 12:35:18.813985 2020] [ssl:info] [pid 1296008:tid 140120808032576] AH01876: mod_ssl/2.4.37 compiled against Server: Apache/2.4.37, Library: OpenSSL/1.1.1c [Mon Jul 27 12:35:18.828805 2020] [socache_shmcb:info] [pid 1296009:tid 140120808032576] AH00830: Shared memory socache initialised [Mon Jul 27 12:35:18.828836 2020] [ssl:info] [pid 1296009:tid 140120808032576] AH01887: Init: Initializing (virtual) servers for SSL [Mon Jul 27 12:35:18.829741 2020] [ssl:info] [pid 1296009:tid 140120808032576] AH01876: mod_ssl/2.4.37 compiled against Server: Apache/2.4.37, Library: OpenSSL/1.1.1c [Mon Jul 27 12:35:18.829798 2020] [lbmethod_heartbeat:notice] [pid 1296009:tid 140120808032576] AH02282: No slotmem from mod_heartmonitor [Mon Jul 27 12:35:18.833165 2020] [http2:info] [pid 1296009:tid 140120808032576] AH03090: mod_http2 (v1.11.3-git, feats=CHPRIO+SHA256+INVHD+DWINS, nghttp2 1.33.0), initializing... [Mon Jul 27 12:35:18.833283 2020] [fcgid:info] [pid 1296011:tid 140120808032576] mod_fcgid: Process manager 1296011 started [Mon Jul 27 12:35:18.833315 2020] [proxy_http2:info] [pid 1296009:tid 140120808032576] AH03349: mod_proxy_http2 (v1.11.3-git, nghttp2 1.33.0), initializing... [Mon Jul 27 12:35:18.835160 2020] [wsgi:info] [pid 1296012:tid 140120808032576] mod_wsgi (pid=1296012): Starting process 'my-proc' with uid=48, gid=48 and threads=15. [Mon Jul 27 12:35:18.836065 2020] [wsgi:info] [pid 1296013:tid 140120808032576] mod_wsgi (pid=1296013): Starting process 'testdjango' with uid=48, gid=48 and threads=15. [Mon Jul 27 12:35:18.838305 2020] [wsgi:info] [pid 1296013:tid 140120808032576] mod_wsgi (pid=1296013): Python home /var/www/myserver.the-company.com/testvenv. [Mon Jul 27 12:35:18.838479 2020] [wsgi:info] [pid 1296013:tid 140120808032576] mod_wsgi (pid=1296013): Initializing Python. [Mon Jul 27 12:35:18.838573 2020] [mpm_worker:notice] [pid 1296009:tid 140120808032576] AH00292: Apache/2.4.37 (centos) OpenSSL/1.1.1c mod_fcgid/2.3.9 mod_wsgi/4.6.4 Python/3.6 configured -- resuming normal operations [Mon Jul 27 12:35:18.838589 2020] [mpm_worker:info] [pid 1296009:tid 140120808032576] AH00293: Server built: Jun 8 2020 20:14:33 [Mon Jul 27 12:35:18.838599 2020] [core:notice] [pid 1296009:tid 140120808032576] AH00094: Command line: 'httpd' [Mon Jul 27 12:35:18.840217 2020] [wsgi:info] [pid 1296012:tid 140120808032576] mod_wsgi (pid=1296012): Python home /var/www/myserver.the-company.com/VENV. [Mon Jul 27 12:35:18.840278 2020] [wsgi:info] [pid 1296012:tid 140120808032576] mod_wsgi (pid=1296012): Initializing Python. [Mon Jul 27 12:35:18.844885 2020] [wsgi:info] [pid 1296014:tid 140120808032576] mod_wsgi (pid=1296014): Initializing Python. [Mon Jul 27 12:35:18.846701 2020] [wsgi:info] [pid 1296016:tid 140120808032576] mod_wsgi (pid=1296016): Initializing Python. [Mon Jul 27 12:35:18.855883 2020] [wsgi:info] [pid 1296015:tid 140120808032576] mod_wsgi (pid=1296015): Initializing Python. [Mon Jul 27 12:35:18.871242 2020] [wsgi:info] [pid 1296016:tid 140120808032576] mod_wsgi (pid=1296016): Attach interpreter ''. [Mon Jul 27 12:35:18.875433 2020] [wsgi:info] [pid 1296016:tid 140120808032576] mod_wsgi (pid=1296016): Imported 'mod_wsgi'. [Mon Jul 27 12:35:18.880111 2020] [wsgi:info] [pid 1296014:tid 140120808032576] mod_wsgi (pid=1296014): Attach interpreter ''. [Mon Jul 27 12:35:18.884362 2020] [wsgi:info] [pid 1296014:tid 140120808032576] mod_wsgi (pid=1296014): Imported 'mod_wsgi'. [Mon Jul 27 12:35:18.890554 2020] [wsgi:info] [pid 1296015:tid 140120808032576] mod_wsgi (pid=1296015): Attach interpreter ''. [Mon Jul 27 12:35:18.894503 2020] [wsgi:info] [pid 1296015:tid 140120808032576] mod_wsgi (pid=1296015): Imported 'mod_wsgi'.

Thanks, James

GrahamDumpleton commented 4 years ago

Since you are using Red Hat products and what appears to be a mod_wsgi packaged/supported by Red Hat, in the first instance I suggest that you ask via your Red Hat support channel or the Red Hat bugzilla (https://bugzilla.redhat.com/). I don't know anything about how they package it and don't see an obvious reason based on details you have provided.

All I can do is say whether your mod_wsgi configuration might be okay, but you don't provide that.

GrahamDumpleton commented 3 years ago

Closing as no further response and assumed information provided was sufficient to solve any issue or gave up.