gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 17:30:13 24 4
gpt4 key购买 nike

我正在使用以下脚本: 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com