Reputation: 4720
I'm using the following script: http://mattupstate.com/python/devops/2012/08/07/flask-wsgi-application-deployment-with-ubuntu-ansible-nginx-supervisor-and-uwsgi.html
I have updated the scripts to the following: setup_server.yml
- name: Install python packages
hosts: webservers
user: ubuntu
sudo: yes
tasks:
- name: add nginx ppa
apt_repository:
repo: "ppa:nginx/stable"
- name: install common packages needed for python application development
apt:
name: "{{ item }}"
with_items:
- libpq-dev
- libmysqlclient-dev
- libxml2-dev
- libjpeg62
- libjpeg62-dev
- libfreetype6
- libfreetype6-dev
- zlib1g-dev
- mysql-client
- python-dev
- python-setuptools
- python-imaging
- python-mysqldb
- python-psycopg2
- git-core
- nginx
- name: install pip
easy_install:
name: pip
- name: install various libraries with pip
pip:
name: "{{ item }}"
with_items:
- virtualenv
- supervisor
- uwsgi
- name: symlink imaging library files
file: src=/usr/lib/x86_64-linux-gnu/libfreetype.so dest=/usr/lib/libfreetype.so state=link
- name: symlink imaging library files
file: src=/usr/lib/x86_64-linux-gnu/libz.so dest=/usr/lib/libz.so state=link
- name: symlink imaging library files
file: src=/usr/lib/x86_64-linux-gnu/libjpeg.so.62 dest=/usr/lib/x86_64-linux-gnu/libjpeg.so state=link
- name: symlink imaging library files
file: src=/usr/lib/x86_64-linux-gnu/libjpeg.so dest=/usr/lib/libjpeg.so state=link
- name: remove default nginx site
file: path=/etc/nginx/sites-enabled/default state=absent
- name: write nginx.conf
template: src=templates/nginx.conf dest=/etc/nginx/nginx.conf
- name: create supervisord config folder
file: dest=/etc/supervisor state=directory owner=root
- name: create supervisord config
template: src=templates/supervisord.conf dest=/etc/supervisor/supervisord.conf
- name: create supervisord init script
template: src=templates/supervisord.sh dest=/etc/init.d/supervisord mode=0755
- name: start supervisord service and have it run during system startup
service: name=supervisord state=started enabled=yes
- name: create webapps directory
file: dest=/srv/webapps state=directory
and: deploy.yml
- name: Setup webser
hosts: webservers
user: ubuntu
sudo: True
vars:
app_name: hello_flask
repo_url: https://github.com/mattupstate/ansible-tutorial.git
repo_remote: origin
repo_version: master
webapps_dir: /srv/webapps
wsgi_file: wsgi.py
wsgi_callable: app
tasks:
- name: ensure log directory
file: path={{ webapps_dir }}/{{ app_name }}/log state=directory mode=0755
- name: deploy code from repository
synchronize: src=/Users/ankitjain/dev/virel/ansible-tutorial/ dest={{ webapps_dir }}/{{ app_name }}/src archive=yes delete=yes rsync_opts="--exclude='tags' --exclude='.git' --exclude='*.swp'" rsync_path='sudo rsync'
- name: install dependencies into virtualenv
pip: requirements={{ webapps_dir }}/{{ app_name }}/src/requirements.txt virtualenv={{ webapps_dir }}/{{ app_name }}/venv state=present
- name: create supervisor program config
template: src=templates/supervisor.ini dest=/etc/supervisor/{{ app_name }}.ini
notify:
- restart app
- name: create nginx site config
template: src=templates/nginx_site.conf dest=/etc/nginx/sites-available/{{ app_name }}.conf
notify:
- restart nginx
- name: link nginx config
file: src=/etc/nginx/sites-available/{{ app_name }}.conf dest=/etc/nginx/sites-enabled/{{ app_name }}.conf state=link
- name: start app
supervisorctl: name={{ app_name }} state=started
handlers:
- name: restart app
supervisorctl: name={{ app_name }} state=restarted
- name: restart nginx
service: name=nginx state=restarted
I have verified that the source is working fine if I run it locally. It is copied correctly with all the variables. Supervisor is running correctly. So nginx config is set correctly, I'm able to start the webserver it directly.
But the supervisor is not able to start the webserver. I get the following error: hello_flask: ERROR (abnormal termination)
I'm not sure how to debug this
Upvotes: 1
Views: 769
Reputation: 83706
Log in to the server over SSH
Use supervisor manually to start the process. Supervisor documentation: http://supervisord.org/
If needed, handedit supervisor configuration files to make supervisor to output the stdout and stderr a file you can ready to see what error message the application is printing out when started through supervisor
Upvotes: 1