V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  Pooc  ›  全部回复第 2 页 / 共 2 页
回复总数  29
1  2  
2018-09-21 23:13:37 +08:00
回复了 greyli 创建的主题 Flask 送出几本《Flask Web 开发实战》
分子分子
@defunct9 多谢老哥帮助!!!
其实是跟 @robinlovemaggie 老哥你的想法一致,也跟上面的各位 dalao 想法一致的。
我把 @defunct9 老哥解决方法说一下,以便后面的同学能及时处理这个问题。

@defunct9 原话:
原因是 venv 跟 gunicorn 必须是同一个 shell 引导,否则无法继承环境变量。

解决方法:
```
# cat /etc/supervisord.conf
[supervisord]
http_port=/var/tmp/supervisor.sock ; (default is to run a UNIX domain socket server)
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (logging level;default info; others: debug,warn)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)

[supervisorctl]
serverurl=unix:///var/tmp/supervisor.sock ; use a unix:// URL for a unix socket

[program:microblog]
command=/www/blog/venv/bin/gunicorn_start
directory=/www/blog
user=root
autostart=true
autorestart=true
stopasgroup=true
killasgrouv=true
stdout_logfile=/www/blog/logs/microblog.log
redirect_stderr=true


# cat /www/blog/venv/bin/gunicorn_start
#!/bin/sh

export FLASK_APP=microblog.py

cd /www/blog/
source venv/bin/activate
/www/blog/venv/bin/gunicorn -b localhost:3000 -w 4 microblog:app

```
直接通过一个 sh 脚本处理同一个 shell 引导,
这个时候由 gunicorn 启动的 microblog 应用服务器现在运行在本地端口 3000,
然后我再设置一下 Nginx 就可以将应用程序暴露给外部世界。
@ericls @0xABCD @yylucifer
日志找到了。。。原来我看错了,是在 logfile=/var/log/supervisor/supervisord.log

```
2018-06-29 17:07:08,984 CRIT Running without any HTTP authentication checking
2018-06-29 17:07:08,989 INFO daemonizing the process
2018-06-29 17:07:08,991 INFO supervisord started with pid 5375
2018-06-29 17:07:08,995 INFO spawned: 'microblog' with pid 5376
2018-06-29 17:07:09,866 INFO exited: microblog (exit status 3; not expected)
2018-06-29 17:07:09,867 INFO received SIGCLD indicating a child quit
2018-06-29 17:07:10,870 INFO spawned: 'microblog' with pid 5382
2018-06-29 17:07:11,864 INFO exited: microblog (exit status 3; not expected)
2018-06-29 17:07:11,865 INFO received SIGCLD indicating a child quit
2018-06-29 17:07:13,871 INFO spawned: 'microblog' with pid 5389
2018-06-29 17:07:14,576 INFO exited: microblog (exit status 1; not expected)
2018-06-29 17:07:14,576 INFO received SIGCLD indicating a child quit
2018-06-29 17:07:17,581 INFO spawned: 'microblog' with pid 5396
2018-06-29 17:07:18,413 INFO exited: microblog (exit status 1; not expected)
2018-06-29 17:07:18,413 INFO received SIGCLD indicating a child quit
2018-06-29 17:07:19,414 INFO gave up: microblog entered FATAL state, too many start retries too quickly
2018-06-29 17:33:58,601 CRIT Supervisor running as root (no user in config file)
2018-06-29 17:33:58,635 INFO localhost:0 - - [29/Jun/2018:09:33:58 +0800] "GET / HTTP/1.0" 200 2204
2018-06-29 17:35:16,200 CRIT Supervisor running as root (no user in config file)
2018-06-29 17:35:16,232 INFO localhost:0 - - [29/Jun/2018:09:35:16 +0800] "GET / HTTP/1.0" 200 2204
2018-06-29 17:37:37,650 CRIT received SIGTERM indicating exit request
2018-06-29 17:37:58,299 CRIT Supervisor running as root (no user in config file)
2018-06-29 17:37:58,311 INFO /var/tmp/supervisor.sock:Medusa (V1.1.1.1) started at Fri Jun 29 17:37:58 2018
Hostname: <unix domain socket>
Port:/var/tmp/supervisor.sock
2018-06-29 17:37:58,363 CRIT Running without any HTTP authentication checking
2018-06-29 17:37:58,365 INFO daemonizing the process
2018-06-29 17:37:58,366 INFO supervisord started with pid 5702
2018-06-29 17:37:58,368 INFO spawned: 'microblog' with pid 5703
2018-06-29 17:37:58,851 INFO exited: microblog (exit status 3; not expected)
2018-06-29 17:37:58,852 INFO received SIGCLD indicating a child quit
2018-06-29 17:37:59,855 INFO spawned: 'microblog' with pid 5707
2018-06-29 17:38:00,681 INFO exited: microblog (exit status 3; not expected)
2018-06-29 17:38:00,682 INFO received SIGCLD indicating a child quit
2018-06-29 17:38:02,687 INFO spawned: 'microblog' with pid 5713
2018-06-29 17:38:03,381 INFO exited: microblog (exit status 3; not expected)
2018-06-29 17:38:03,381 INFO received SIGCLD indicating a child quit
2018-06-29 17:38:06,386 INFO spawned: 'microblog' with pid 5720
2018-06-29 17:38:07,114 INFO exited: microblog (exit status 1; not expected)
2018-06-29 17:38:07,114 INFO received SIGCLD indicating a child quit
2018-06-29 17:38:08,115 INFO gave up: microblog entered FATAL state, too many start retries too quickly
2018-06-29 17:38:53,721 INFO localhost:0 - - [29/Jun/2018:09:38:53 +0800] "POST /RPC2 HTTP/1.0" 200 254
2018-06-29 17:38:53,724 INFO localhost:0 - - [29/Jun/2018:09:38:53 +0800] "POST /RPC2 HTTP/1.0" 200 1242
2018-06-29 17:38:56,321 INFO localhost:0 - - [29/Jun/2018:09:38:56 +0800] "POST /RPC2 HTTP/1.0" 200 254
2018-06-29 17:38:56,325 INFO localhost:0 - - [29/Jun/2018:09:38:56 +0800] "POST /RPC2 HTTP/1.0" 200 1242
2018-06-29 17:39:00,612 INFO localhost:0 - - [29/Jun/2018:09:39:00 +0800] "POST /RPC2 HTTP/1.0" 200 254
2018-06-29 17:39:00,614 INFO localhost:0 - - [29/Jun/2018:09:39:00 +0800] "POST /RPC2 HTTP/1.0" 200 1242
2018-06-29 17:45:58,505 INFO localhost:0 - - [29/Jun/2018:09:45:58 +0800] "POST /RPC2 HTTP/1.0" 200 254
2018-06-29 17:45:58,509 INFO localhost:0 - - [29/Jun/2018:09:45:58 +0800] "POST /RPC2 HTTP/1.0" 200 1242

```
@robinlovemaggie 是的,老哥,的确是不要在 root 下跑非系统程序。。。
@ericls @0xABCD @yylucifer /var/tmp 下的日志是空的。。。
@defunct9 小哥,怎么联系。。。
@knktc @tempdban 我也觉得是很 venv 有关系,但是我添加了环境变量了,在 venv 在没有进入 venv 的情况下能正常使用。。。在 venv/bin/activate 跟 /etc/profile 都添加了 export FLASK_APP=microblog.py 会不会是这个有误?
@summerwar @bolide2005 running 几秒钟就重复 start,running,block。。。
2018-05-24 17:16:01 +08:00
回复了 wwwaaa 创建的主题 Python Python selenium 中如何对网站中内嵌的一个视频进行操作呢?
move_by_offset() 就是通过坐标点击
2018-05-22 21:57:48 +08:00
回复了 Pooc 创建的主题 Python 求助: win10 下新建 flask,运行报错 UnicodeDecodeError 的问题
@John60676 !!!的确是计算机名字为中文的问题!修改就好了,多谢,多谢!!!
2018-05-22 12:56:20 +08:00
回复了 Pooc 创建的主题 Python 求助: win10 下新建 flask,运行报错 UnicodeDecodeError 的问题
@John60676 谢谢你的解答,不过还是不行。。。
1  2  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2723 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 15ms · UTC 09:14 · PVG 17:14 · LAX 01:14 · JFK 04:14
Developed with CodeLauncher
♥ Do have faith in what you're doing.