python - Flask Ansible 通过主管启动时出错

标签 python nginx supervisord

我正在使用以下脚本: http://mattupstate.com/python/devops/2012/08/07/flask-wsgi-application-deployment-with-ubuntu-ansible-nginx-supervisor-and-uwsgi.html

我已将脚本更新为以下内容: 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

以及: 部署.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

我已经验证,如果我在本地运行源代码,它可以正常工作。它与所有变量一起正确复制。 Supervisor 运行正常。所以 nginx 配置设置正确,我可以直接启动网络服务器。

但是主管无法启动网络服务器。我收到以下错误: hello_flask:错误(异常终止)

我不知道如何调试这个

最佳答案

  • 通过 SSH 登录服务器

  • 手动使用supervisor来启动进程。主管文档:http://supervisord.org/

  • 如果需要,手动编辑supervisor配置文件以使supervisor输出stdout和stderr文件,您可以随时查看应用程序在通过supervisor启动时打印出什么错误消息

关于python - Flask Ansible 通过主管启动时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31954429/

相关文章:

docker - 如果一个退出,退出所有supervisord进程

Django celery daemon 给出 'supervisor FATAL can' t find command',但路径是正确的

python - 类可以继承namedtuple的属性吗?

python - 如何使用 GitPython 计算未发布的提交数?

regex - 尝试优化掉 Nginx 正则表达式是否值得?

Django Supervisord fastcgi 配置(supervisord.conf)——立即退出

python - 如何方便地从 Python ubuntu native 更改为 Python Anaconda,反之亦然?

python - Matplotlib 文本不采用数组值

php - 找不到PHP Docker供应商Autoload.php

php - Nginx - 未从反向代理调用 PHP 脚本