-
Notifications
You must be signed in to change notification settings - Fork 8
Developer Guide
See the Installation section to quickly setup the Django Application in your local system.
The project uses django-haystack which supports Elastic Search 1.x and Elastic Search 2.x. Elastic Search 5.x is not supported yet. You can use either of them to get the App Store running.
Elastic Search can be installed by following the official installation instructions in the official website. To quickly setup Elastic Search, follow these steps :
-
Install the latest OpenJDK. In CentOS, the following command can be used :
$ sudo yum install java-1.8.0-openjdk.x86_64 -
Get the
rpm/debpackage corresponding to the Elastic Search version that you choose usingwget. -
Install Elastic Search using
dpkg/rpmdepending on the Linux Distribution used. For example :
$ sudo dpkg -i elasticsearch-2.3.1.deb(Ubuntu)
$ sudo rpm -ivh elasticsearch-2.3.1.rpm(CentOS) -
Once installation is complete, setup Elastic Search as a service :
$ sudo systemctl daemon-reload
$ sudo systemctl enable elasticsearch.service -
To modify Elastic Search clusters to suite your needs, you can edit the
/etc/elasticsearch/elasticsearch.ymlfile. By default, this file comes with the default settings to run the search engine. If you are an advanced user, you can edit the details to suit your requirements. -
Start the Elastic Search service.
$ sudo systemctl start elasticsearch
- Modify the
settings/base.pyfile to add theHAYSTACK_CONNECTIONSto connectdjango-haystackwith Elastic Search. The settings are already included in the file, uncomment it depending on the verion of Elastic Search being used.
For Elastic Search 1.x :
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
},
}For Elastic Search 2.x :
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch2_backend.Elasticsearch2SearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
},
}-
Make sure
elasticsearchpython package is installed in your virtual environment. You can check this by using the command :
$ pip freeze
The package will be installed if you have followed the installation instructions correctly. -
Build your search index using the command :
$ python manage.py rebuild_index
This should be executed inside thesrc/directory. -
To update the search index periodically, a cron job should be created which is executed at regular intervals.
update_indexcommand ofdjango-haystackcan be used to update the search index.
The website can be deployed using any standard webserver, Apache2, Nginx, etc. Here, we will explain how to deploy the website using gunicorn and nginx.
Here, we will demonstrate how to setup gunicorn on a CentOS 7 system. Setup with other linux distributions might vary slightly.
- Install
gunicornusing the following command :
pip install gunicorn - To setup
gunicornas a service, edit the following file :/etc/systemd/system/gunicorn.service - Sample setup :
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=username
Group=nginx
WorkingDirectory=/<path-to-appstore>/ns-3-AppStore/src
ExecStart=/<path-to-appstore>/ns-3-AppStore/venv/bin/gunicorn --workers 3 --bind unix:/<path-to-appstore>/ns-3-AppStore/src/appstore.sock appstore.wsgi:application
[Install]
WantedBy=multi-user.target
- Now start
gunicornservice and enable it :
sudo systemctl start gunicorn
sudo systemctl enable gunicorn
Here, we will demonstrate how to setup gunicorn on a CentOS 7 system. Setup with other linux distributions might vary slightly.
- Install
nginxusing the following command :
sudo yum install nginx - To setup
nginxas a service, edit the following file :/etc/nginx/nginx.conf - Sample
nginx.conffile :
http {
. . .
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name server_domain_or_IP;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /<path-to-appstore>/ns-3-AppStore/site;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/<path-to-appstore>/ns-3-AppStore/src/appstore.sock;
}
}
. . .
- Now manage user permissions and test
nginxconfiguration :
sudo usermod -a -G user nginx
chmod 710 /home/user
sudo nginx -t
- Now start
nginxservice and enable it :
sudo systemctl start nginx
sudo systemctl enable nginx
By default, the Django Project setup is suitable for development. For production deployment, several changes need to be made. The project uses Edge which provides a separate production settings file. That file is used by the wsgi application.
- Make sure that
settings.productionis being used inside thewsgifile. - To render the static files properly, it needs to be collected in place. This can be done by the following command :
$ python manage.py collectstatic
NOTE : If you receive errors regarding static root, edit themanage.pyfile to usesettings.productionrather thatsettings.development. - In the production settings,
ALLOWED_HOSTSvariable needs to be modified to allow the server_name/IP. Modify the variable insettings/production.py. For example :
ALLOWED_HOSTS = ['ns-apps.ee.washington.edu']
By following the above instructions, a production deployment of the App Store can be created. If you have any issues during setup, please raise an issue or contact the contributors.