satnet-project / server

Repository with the source code for the server of the SATNet network.
Apache License 2.0
2 stars 1 forks source link

server-setup.sh - wsgi.py cannot be loaded as Python module #23

Closed ajvazquez closed 9 years ago

ajvazquez commented 9 years ago

The server seems to be running, but I get an error when trying to access through the web browser. This is the content of website/logs/error.log after the access:

 [Fri Apr 03 22:33:19 2015] [error] >>> Loading local server information...
 [Fri Apr 03 22:33:19 2015] [error] DEBUG (0.001) SELECT "network_server"."id", "network_server"."is_me", "network_server"."is_external", "network_server"."owner_id", "network_server"."identifier", "network_server"."ip_address", "network_server"."latitude", "network_server"."longitude", "network_server"."timestamp" FROM "network_server" WHERE "network_server"."is_me" = true ; args=(True,)
 [Fri Apr 03 22:33:19 2015] [error] [client ::1] mod_wsgi (pid=13745): Target WSGI script '/home/aj/satnet_main/server/WebServices/website/wsgi.py' cannot be loaded as Python module.
 [Fri Apr 03 22:33:19 2015] [error] [client ::1] mod_wsgi (pid=13745): Exception occurred processing WSGI script '/home/aj/satnet_main/server/WebServices/website/wsgi.py'.
 [Fri Apr 03 22:33:19 2015] [error] [client ::1] Traceback (most recent call last):
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/website/wsgi.py", line 47, in <module>
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     server_models.ServerManager().load_local_server()
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/services/network/models/server.py", line 45, in load_local_server
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     s_local = self.get_local()
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/services/network/models/server.py", line 66, in get_local
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     return Server.objects.get(is_me=True)
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/.venv/lib/python2.7/site-packages/django/db/models/manager.py", line 151, in get
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     return self.get_queryset().get(*args, **kwargs)
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/.venv/lib/python2.7/site-packages/django/db/models/query.py", line 304, in get
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     num = len(clone)
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/.venv/lib/python2.7/site-packages/django/db/models/query.py", line 77, in __len__
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     self._fetch_all()
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/.venv/lib/python2.7/site-packages/django/db/models/query.py", line 857, in _fetch_all
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     self._result_cache = list(self.iterator())
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/.venv/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     for row in compiler.results_iter():
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/.venv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 713, in results_iter
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     for rows in self.execute_sql(MULTI):
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/.venv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     cursor.execute(sql, params)
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/.venv/lib/python2.7/site-packages/django/db/backends/util.py", line 69, in execute
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     return super(CursorDebugWrapper, self).execute(sql, params)
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/.venv/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     return self.cursor.execute(sql, params)
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/.venv/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     six.reraise(dj_exc_type, dj_exc_value, traceback)
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]   File "/home/aj/satnet_main/server/WebServices/.venv/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]     return self.cursor.execute(sql, params)
 [Fri Apr 03 22:33:19 2015] [error] [client ::1] ProgrammingError: relation "network_server" does not exist
 [Fri Apr 03 22:33:19 2015] [error] [client ::1] LINE 1: ...r"."longitude", "network_server"."timestamp" FROM "network_s...
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]                                                              ^
 [Fri Apr 03 22:33:19 2015] [error] [client ::1]

After configuring the apache server with the -x option in the script I get:

 [...]
 ERROR: Site satnet_tls does not exist!
 Site satnet_tls.conf already enabled
 [...]

Although this last part may not be a problem.

Any idea? (This is with the master branch). Thank you!

rtubio commented 9 years ago

@ajvazquez , what python version are you using?

ajvazquez commented 9 years ago

From the log it should be the 2.7 version the one which is being used, but I also have python3 installed. After posting I've also tried with the 3k branch, but with similar results...

rtubio commented 9 years ago

You will have to check for the configuration file created automatically for Apache. It now has to use the Python 3 interpreter for the _3k branch.

rtubio commented 9 years ago

http://stackoverflow.com/questions/6454564/target-wsgi-script-cannot-be-loaded-as-python-module

Take a look at this issue on stackoverflow, the answer by "nima" might help...

ajvazquez commented 9 years ago

I think that's one of the sites I checked yesterday, I tried some of those alternatives but no luck. I tried the one you're referencing with the 3k branch now, but I get an error with apache2.

Based on the logs, the server seems to keep using Python 2.7. I've tried to introduce an alias for python to use python3 in .bash_aliases. Should I do anything differently? Shouldn't the server be using python3?

Don't know if it helps, but when trying to reinstall through the server setup I get:

 The following NEW packages will be installed:
   libapache2-mod-wsgi 
 0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
 Need to get 127 kB of archives. After unpacking 349 kB will be used.
 The following packages have unmet dependencies:
  libapache2-mod-wsgi-py3 : Conflicts: libapache2-mod-wsgi but 3.3-4+deb7u1 is to be installed.
 The following actions will resolve these dependencies:

      Remove the following packages:
 1)     libapache2-mod-wsgi-py3
rtubio commented 9 years ago

@ajvazquez , you should change the configuration file for the site within the apache configuration directory. You will find this configuration file within "sites-enabled", under "/etc/apache2/". There, you can find the configuration for the interpreter to be used by the wsgi module.

rtubio commented 9 years ago

@ajvazquez , I am testing it right now within a new virtual machine. I am going to use Debian testing and the "development_3k" branch.

rtubio commented 9 years ago

@ajvazquez : the problem was exactly the one you pointed some posts ago. libapache2-mod-wsgi is not compiled for Python 3 and, once you install libapache2-mod-wsgi-py3 you have to "tweak" a bit the configuration for it to now include the python3 package directory within the virtual environment. The last commit should fix this problem, I got it up and working in a Debian Testing (Jessie) virtual machine, with the branch "development_3k" and everything fully automated from within the installation script.

Please give it another try and let me know how it goes.

ajvazquez commented 9 years ago

Thank you @rtp-calpoly . Much easier now :). I also tried it on a fresh install of Debian Jessie and the server seems to be working. Thanks!

rtubio commented 9 years ago

@ajvazquez , it would be great that you tried the installation in a Ubuntu 14.04.2 LTS since that is the one that I have currently running in a VM hosted on the Internet.

ajvazquez commented 9 years ago

@rtp-calpoly , just tried with Ubuntu Server 14.04.2 LTS. These are the last lines after running the installation script:

 >>>>>>>> Configuring virtualenv...
 Virtual environment activation failed... exiting!

Checking the first lines, the variable "debian_packages_file" seems to be empty:

 * branch_name = development_3k
 * debian_version = LTS
 * debian_packages_file = 

I guess it takes to modify the script to detect the ubuntu version and the file with the list of packages to be installed.

However the installation seems to complete properly with the "debian.8.packages", (from the installation script):

 sudo aptitude install $( cat "debian.8.packages" )

and then rerunning the installation script.

Also, probably the password introduced for the database may be saved into the database.py file, to avoid modifying the file and rerunning the script. Either way other files in that folder have to be modified too... Maybe the fields in these files can be requested during installation? But I guess this would be a different issue...

rtubio commented 9 years ago

@ajvazquez , the latest version should be working fully automatic with the exception of requesting user interaction when it comes to input the passwords for the database, smtp server and Django. The issue that you found with the database authentication (the one that involved running the installation script twice at least) has been solved with this new issue.

Please try it and let me know of any additional improvements that we can make.

rtubio commented 9 years ago

@ajvazquez : could you try this latest version of the software setup script?

rtubio commented 9 years ago

Nobody else has experienced this issue since it happened, so the we will assume that it was a problem with this specific installation process.