为什么我的gunicorn服务器无法启动?
jeffy@originaldjangster:~$ sudo /home/jeffy/django_files/django_test_venv/bin/gunicorn -c /home/jeffy/django_files/django_test_venv/gunicorn_config.py django_test.wsgi
Connection in use: ('127.0.0.1', 8001)
Retrying in 1 second.
Connection in use: ('127.0.0.1', 8001)
Retrying in 1 second.
Connection in use: ('127.0.0.1', 8001)
Retrying in 1 second.
Connection in use: ('127.0.0.1', 8001)
Retrying in 1 second.
Connection in use: ('127.0.0.1', 8001)
Retrying in 1 second.
Can't connect to ('127.0.0.1', 8001)
jeffy@originaldjangster:~$
nginx侦听http://104.131.200.120/
,并传递给gunicorn,后者监听127.0.0.1。我在Ubuntu 14上。
我列出了所有进程,看看gunicorn是否已经在运行:
jeffy@originaldjangster:~$ ps -a
PID TTY TIME CMD
7653 pts/1 00:00:00 ps
jeffy@originaldjangster:~$ ps
PID TTY TIME CMD
7249 pts/1 00:00:00 bash
7654 pts/1 00:00:00 ps
jeffy@originaldjangster:~$ ps -A
PID TTY TIME CMD
1 ? 00:00:02 init
2 ? 00:00:00 kthreadd
3 ? 00:00:00 ksoftirqd/0
5 ? 00:00:00 kworker/0:0H
6 ? 00:00:00 kworker/u2:0
7 ? 00:00:00 rcu_sched
8 ? 00:00:00 rcu_bh
9 ? 00:00:00 migration/0
10 ? 00:00:00 watchdog/0
11 ? 00:00:00 khelper
12 ? 00:00:00 kdevtmpfs
13 ? 00:00:00 netns
14 ? 00:00:00 writeback
15 ? 00:00:00 kintegrityd
16 ? 00:00:00 bioset
17 ? 00:00:00 kworker/u3:0
18 ? 00:00:00 kblockd
19 ? 00:00:00 ata_sff
20 ? 00:00:00 khubd
21 ? 00:00:00 md
22 ? 00:00:00 devfreq_wq
23 ? 00:00:08 kworker/0:1
24 ? 00:00:00 khungtaskd
25 ? 00:00:00 kswapd0
26 ? 00:00:00 ksmd
27 ? 00:00:00 fsnotify_mark
28 ? 00:00:00 ecryptfs-kthrea
29 ? 00:00:00 crypto
41 ? 00:00:00 kthrotld
44 ? 00:00:00 scsi_eh_0
45 ? 00:00:00 scsi_eh_1
66 ? 00:00:00 deferwq
67 ? 00:00:00 charger_manager
120 ? 00:00:01 jbd2/vda-8
121 ? 00:00:00 ext4-rsv-conver
271 ? 00:00:00 upstart-udev-br
275 ? 00:00:00 systemd-udevd
322 ? 00:00:00 dbus-daemon
349 ? 00:00:00 kpsmoused
351 ? 00:00:00 kworker/0:2
356 ? 00:00:00 systemd-logind
358 ? 00:00:00 rsyslogd
387 ? 00:00:00 kvm-irqfd-clean
624 ? 00:00:00 upstart-file-br
704 ? 00:00:00 upstart-socket-
758 tty4 00:00:00 getty
761 tty5 00:00:00 getty
767 tty2 00:00:00 getty
768 tty3 00:00:00 getty
770 tty6 00:00:00 getty
794 ? 00:00:00 sshd
800 ? 00:00:00 acpid
802 ? 00:00:00 cron
804 ? 00:00:00 atd
853 ? 00:00:01 postgres
855 ? 00:00:00 postgres
856 ? 00:00:01 postgres
857 ? 00:00:01 postgres
858 ? 00:00:02 postgres
859 ? 00:00:02 postgres
903 ? 00:00:17 supervisord
961 tty1 00:00:00 getty
982 ? 00:00:00 kauditd
1266 ? 00:00:07 kworker/u2:1
3027 ? 00:00:00 kworker/u3:1
3230 ? 00:00:00 sudo
3231 ? 00:00:01 gunicorn
7014 ? 00:00:00 gunicorn
7115 ? 00:00:00 sshd
7192 ? 00:00:00 sshd
7193 ? 00:00:00 sftp-server
7200 ? 00:00:00 sshd
7248 ? 00:00:00 sshd
7249 pts/1 00:00:00 bash
7610 ? 00:00:00 nginx
7613 ? 00:00:00 nginx
7614 ? 00:00:00 nginx
7615 ? 00:00:00 nginx
7616 ? 00:00:00 nginx
7649 ? 00:00:00 sshd
7650 ? 00:00:00 sshd
7655 pts/1 00:00:00 ps
这是两条枪手:
3231 ? 00:00:01 gunicorn
7014 ? 00:00:00 gunicorn
我试图杀死这两个进程,但是当用fg 3231
将它们带到前台时,它会说"没有这样的工作"。
有人建议我尝试netstat -aWn --programs | grep 80
。这是结果,我不明白
jeffy@originaldjangster:~$ sudo netstat -aWn --programs | grep 80
tcp 0 0 127.0.0.1:8001 0.0.0.0:* LISTEN 3231/python3.4
unix 2 [ ACC ] STREAM LISTENING 8911 800/acpid /var/run/acpid.socket
unix 2 [ ] DGRAM 8908 800/acpid
任何想法导致这种"使用中的连接"错误?感谢。
答案 0 :(得分:8)
原来我需要sudo kill 3231
和sudo kill 7014
。我错误地认为他们首先需要把它带到前台。在我使用大写A选项(ps -A
)之前无法看到这些过程的事实误导了我,他们在某种程度上是特殊的。
当我在妻子面前睡觉时,服务器 正在运行(在前台)。她在睡觉前关掉电脑。
Ubuntu和gunicorn新手。你能说出来吗?
答案 1 :(得分:5)
在本地开发环境中(重新)启动Gunicorn之前,我已经习惯运行killall gunicorn
。
答案 2 :(得分:3)
对于在端口上没有运行任何东西的任何人来说,如果 app.run()
在文件 gunicorn is running 中,那么它将在端口上运行两次并继续尝试重试连接。
就我而言,我正在运行 $ gunicorn run:app 其中 run.py 有:
from app import app
app.run(debug=True)
在里面。当我注释掉 app.run 时,它起作用了。
答案 3 :(得分:0)
我也遇到过同样的问题...... 不要试图从 su 运行gunicorn。 只需更改用户,然后重试
答案 4 :(得分:0)
重新启动计算机对我有帮助
@XmlRootElement(name = "actionError")
@XmlAccessorType(XmlAccessType.FIELD)
public class ActionError<T> {
private ArrayList<String> actionErrors;
private ArrayList<FieldError> fieldErrors;
private T payload;
/**
* @return the actionErrors
*/
public ArrayList<String> getActionErrors() {
return actionErrors;
}
/**
* @param actionErrors the actionErrors to set
*/
public void setActionErrors(ArrayList<String> actionErrors) {
this.actionErrors = actionErrors;
}
/**
* @return the fieldErrors
*/
public ArrayList<FieldError> getFieldErrors() {
return fieldErrors;
}
/**
* @param fieldErrors the fieldErrors to set
*/
public void setFieldErrors(ArrayList<FieldError> fieldErrors) {
this.fieldErrors = fieldErrors;
}
public void addFieldError(String fieldName,String errorMessage){
if (this.fieldErrors==null)
this.fieldErrors = new ArrayList<>();
this.fieldErrors.add(new FieldError(fieldName, errorMessage));
}
public void addActionError(String errorMessage){
if (this.actionErrors==null)
this.actionErrors = new ArrayList<>();
this.actionErrors.add(errorMessage);
}
public boolean hasErrors(){
return (fieldErrors!=null && !fieldErrors.isEmpty()) || (actionErrors!=null && !actionErrors.isEmpty());
}
/**
* @return the payload
*/
public T getPayload() {
return payload;
}
/**
* @param payload the payload to set
* @return
*/
public ActionError setPayload(T payload) { //Class<T> payloadClass
this.payload = payload;
return this;
}
}
列表中没有金枪鱼,所以我不知道该怎么@XmlRootElement(name = "fieldError")
@XmlAccessorType(XmlAccessType.FIELD)
public class FieldError {
private String fieldName;
private String fieldError;
/**
* @return the fieldName
*/
public String getFieldName() {
return fieldName;
}
/**
* @param fieldName the fieldName to set
*/
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
/**
* @return the fieldError
*/
public String getFieldError() {
return fieldError;
}
/**
* @param fieldError the fieldError to set
*/
public void setFieldError(String fieldError) {
this.fieldError = fieldError;
}
public FieldError(String fieldName, String fieldError) {
this.fieldName = fieldName;
this.fieldError = fieldError;
}
}
@XmlRootElement(name = "employee")
@XmlAccessorType(XmlAccessType.FIELD)
public class Employee {
private String empNo;
private String empName;
private String position;
// This default constructor is required if there are other constructors.
public Employee() {
}
public Employee(String empNo, String empName, String position) {
this.empNo = empNo;
this.empName = empName;
this.position = position;
}
public String getEmpNo() {
return empNo;
}
public void setEmpNo(String empNo) {
this.empNo = empNo;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
}
上我也没有得到任何明显印象答案 5 :(得分:0)
我找到了我的解决方案 here。
ps ax|grep gunicorn
>>> 932 pts/0 S 0:01 /home/someuser/flaskdir/.venv/bin/python3 /home/someuser/flaskdir/.venv/bin/gunicorn -w 3 flaskapp:app
kill -9 932