My apologies in advance, I really only know enough to be dangerous, only do this part time, and am only allowed to upgrades maybe once a year, so…
I am finally upgrading from Django 1.11 and python 2.7. I was expecting to need some code tweaks. So far,when I ran “manage.py --version”, it told me I needed to fix some tabs and add on_delete to some models. Nifty - that should mean the upgrade was successful, right?
Nope. Restarted my app, with “sudo service myapp restart”,
`[Unit]
Description=uWSGI Server for myapp website
After=network.target
[Service]
ExecStart=/usr/bin/uwsgi --plugins python -x /var/www/myapp/project/uwsgi.xml
ExecReload=/usr/bin/uwsgi --plugins python -x /var/www/myapp/project/uwsgi.xml
#User=www-data
#Group=www-data
#ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
#RestartPreventExitStatus=255
Type=notify
#RuntimeDirectory=sshd
#RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
I got an internal server error. Syslog shows:
*** Operational MODE: single process ***
Dec 29 04:35:37 localhost uwsgi[12986]: added /var/www/etap/ to pythonpath.
Dec 29 04:35:37 localhost uwsgi[12986]: added /usr/bin/python to pythonpath.
Dec 29 04:35:37 localhost uwsgi[12986]: added /var/www/etap/project/apps/ to pythonpath.
Dec 29 04:35:40 localhost uwsgi[12986]: Traceback (most recent call last):
Dec 29 04:35:40 localhost uwsgi[12986]: File "./wsgi.py", line 7, in <module>
Dec 29 04:35:40 localhost uwsgi[12986]: application = get_wsgi_application()
Dec 29 04:35:40 localhost uwsgi[12986]: File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
Dec 29 04:35:40 localhost uwsgi[12986]: django.setup(set_prefix=False)
Dec 29 04:35:40 localhost uwsgi[12986]: File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 27, in setup
Dec 29 04:35:40 localhost uwsgi[12986]: apps.populate(settings.INSTALLED_APPS)
Dec 29 04:35:40 localhost uwsgi[12986]: File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
Dec 29 04:35:40 localhost uwsgi[12986]: app_config.import_models()
Dec 29 04:35:40 localhost uwsgi[12986]: File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 202, in import_models
Dec 29 04:35:40 localhost uwsgi[12986]: self.models_module = import_module(models_module_name)
Dec 29 04:35:40 localhost uwsgi[12986]: File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
Dec 29 04:35:40 localhost uwsgi[12986]: __import__(name)
Dec 29 04:35:40 localhost uwsgi[12986]: File "/var/www/etap/project/apps/imports/models.py", line 5, in <module>
Dec 29 04:35:40 localhost uwsgi[12986]: from bs4 import BeautifulSoup
Dec 29 04:35:40 localhost uwsgi[12986]: ImportError: No module named bs4
Dec 29 04:35:40 localhost uwsgi[12986]: unable to load app 0 (mountpoint='') (callable not found or import error)
Dec 29 04:35:40 localhost uwsgi[12986]: *** no app loaded. going in full dynamic mode ***
Dec 29 04:35:40 localhost uwsgi[12986]: dropping root privileges after application loading
Dec 29 04:35:40 localhost uwsgi[12986]: uWSGI running as root, you can use --uid/--gid/--chroot options
Dec 29 04:35:40 localhost uwsgi[12986]: *** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Dec 29 04:35:40 localhost uwsgi[12986]: *** uWSGI is running in multiple interpreter mode ***
Dec 29 04:35:40 localhost uwsgi[12986]: gracefully (RE)spawned uWSGI master process (pid: 12986)
Dec 29 04:35:40 localhost uwsgi[12986]: sendmsg(): Transport endpoint is already connected [core/notify.c line 39]
Dec 29 04:35:40 localhost uwsgi[12986]: spawned uWSGI worker 1 (pid: 13196, cores: 1)
So it’s looking for the wrong version of python. python --version give 3.6.9, and manage.py from the command line give:
Traceback (most recent call last):
File "/usr/lib/python3.6/logging/config.py", line 565, in configure
handler = self.configure_handler(handlers[name])
File "/usr/lib/python3.6/logging/config.py", line 738, in configure_handler
result = factory(**kwargs)
File "/usr/lib/python3.6/logging/handlers.py", line 150, in __init__
BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
File "/usr/lib/python3.6/logging/handlers.py", line 57, in __init__
logging.FileHandler.__init__(self, filename, mode, encoding, delay)
File "/usr/lib/python3.6/logging/__init__.py", line 1032, in __init__
StreamHandler.__init__(self, self._open())
File "/usr/lib/python3.6/logging/__init__.py", line 1061, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: '/var/www/django/log/mylog.log'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./manage.py", line 30, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 395, in execute
django.setup()
File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python3.6/dist-packages/django/utils/log.py", line 75, in configure_logging
logging_config_func(logging_settings)
File "/usr/lib/python3.6/logging/config.py", line 802, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python3.6/logging/config.py", line 573, in configure
'%r: %s' % (name, e))
ValueError: Unable to configure handler 'default': [Errno 13] Permission denied: '/var/www/django/log/mylog.log'
So it’s finding python 3.6, and somewhere I’ve got something telling it to use Python 2.7, but I can’t for the life of me figure out where.
Some of the files I have checked:
wsgy.py:
import sys
import os
from django.core.wsgi import get_wsgi_application
sys.path.append('/var/www/myapp/project/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = get_wsgi_application()
uwsgi.xml:
<uwsgi>
<socket>127.0.0.1:3032</socket>
<master/>
<processes>1</processes>
<chdir>/var/www/etap/project</chdir>
<pythonpath>/var/www/etap/</pythonpath>
<pythonpath>/usr/bin/python</pythonpath>
<pythonpath>/var/www/etap/project/apps/</pythonpath>
<module>wsgi</module>
</uwsgi>
uwsgi.conf: (Sort of think I may not need both, but they precede my involvement…)
<uwsgi>
<pythonpath>/usr/bin/python</pythonpath>
<pythonpath>/var/www/etap/</pythonpath>
<pythonpath>/var/www/etap/project/</pythonpath>
<pythonpath>/var/www/etap/project/apps/</pythonpath>
<app mountpoint="/">
<script>project.wsgi</script>
</app>
</uwsgi>
uwsgi.ini
module=myapp.uwsgi:application
logto = /var/log/uwsgi/%n.log
uid = uwsgi
gid = uwsgi
pidfile = /run/uwsgi/uwsgi.pid
socket = :3032
myapp.service:
[Unit]
Description=uWSGI Server for website
After=network.target
[Service]
ExecStart=/usr/bin/uwsgi --plugins python -x /var/www/myapp/project/uwsgi.xml
ExecReload=/usr/bin/uwsgi --plugins python -x /var/www/myapp/project/uwsgi.xml
#User=www-data
#Group=www-data
#ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
#RestartPreventExitStatus=255
Type=notify
#RuntimeDirectory=sshd
#RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
uwsgi_params for nginx:
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
There is nothing in the uwsgi log, or my application log.
I am on a shared server, but not an explicit venv. Nothing I can see says “hey, ignore what the system thinks, use this version!”, so I’m just really stumped now.
Any tips/hints/suggestions or outright solutions are very much appreciated, otherwise, thanks for reading.