gunicorn:开始:工作未能开始

时间:2016-05-01 12:33:24

标签: python linux service flask gunicorn

我有关于在我的服务器上启动我的gunicorn-Flask应用程序的问题。

我的服务器是Ubuntu 14.04 64位。

当我从终端启动gunicorn(并且虚拟环境处于活动状态)时:

gunicorn --bind 0.0.0.0:8000 wsgi

它可以工作,我可以连接端口8000。

但是当我想要启动sudo service MyApp时,它会出现以下错误:

start: Job failed to start

我的/etc/init/MyApp.conf是:

description "Gunicorn application server running MyApp"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid juldou
setgid  www-data

env PATH=/home/juldou/MyApp/project_juda/bin
chdir /home/juldou/MyApp
exec gunicorn --workers 3 --bind unix:MyApp.sock -m 007 wsgi

注:

  

我知道我没有创建MyApp.sock,我不知道我是否必须   有或这个脚本创建MyApp.sock

应该在哪里出问题?

更新: 从终端,这个命令正在运行:

(project_juda) juldou@ubuntu-512mb-fra1-01-improveyourself:~/MyApp$ gunicorn --workers 3 --bind unix:MyApp.sock -m 007 wsgi
[2016-05-01 14:06:41 +0000] [8119] [INFO] Starting gunicorn 19.4.5
[2016-05-01 14:06:41 +0000] [8119] [INFO] Listening at: unix:MyApp.sock (8119)
[2016-05-01 14:06:41 +0000] [8119] [INFO] Using worker: sync
[2016-05-01 14:06:41 +0000] [8124] [INFO] Booting worker with pid: 8124
[2016-05-01 14:06:41 +0000] [8127] [INFO] Booting worker with pid: 8127
[2016-05-01 14:06:41 +0000] [8130] [INFO] Booting worker with pid: 8130
[2016-05-01 14:07:28 +0000] [8119] [INFO] Handling signal: int
[2016-05-01 14:07:28 +0000] [8124] [INFO] Worker exiting (pid: 8124)
[2016-05-01 14:07:28 +0000] [8130] [INFO] Worker exiting (pid: 8130)
[2016-05-01 14:07:28 +0000] [8127] [INFO] Worker exiting (pid: 8127)
[2016-05-01 14:07:28 +0000] [8119] [INFO] Shutting down: Master
  

auth.log:

May  2 11:16:20 ubuntu-512mb-fra1-01-improveyourself sshd[13991]: 

pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=212.45.1.10  user=www-data
May  2 11:16:22 ubuntu-512mb-fra1-01-improveyourself sshd[13991]: Failed password for www-data from 212.45.1.10 port 39557 ssh2
May  2 11:16:22 ubuntu-512mb-fra1-01-improveyourself sshd[13991]: Received disconnect from 212.45.1.10: 11: Bye Bye [preauth]
May  2 11:16:44 ubuntu-512mb-fra1-01-improveyourself sshd[13997]: reverse mapping checking getaddrinfo for 50-250-218-65-static.hfc.comcastbusiness.net [50.250.218.65] failed - POSSIBLE BREAK-IN ATTEMPT!
May  2 11:16:44 ubuntu-512mb-fra1-01-improveyourself sshd[13997]: Invalid user squid from 50.250.218.65
May  2 11:16:44 ubuntu-512mb-fra1-01-improveyourself sshd[13997]: input_userauth_request: invalid user squid [preauth]
May  2 11:16:44 ubuntu-512mb-fra1-01-improveyourself sshd[13997]: pam_unix(sshd:auth): check pass; user unknown
May  2 11:16:44 ubuntu-512mb-fra1-01-improveyourself sshd[13997]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=50.250.218.65
May  2 11:16:46 ubuntu-512mb-fra1-01-improveyourself sshd[13997]: Failed password for invalid user squid from 50.250.218.65 port 48021 ssh2
May  2 11:16:46 ubuntu-512mb-fra1-01-improveyourself sshd[13997]: Received disconnect from 50.250.218.65: 11: Bye Bye [preauth]
May  2 11:16:49 ubuntu-512mb-fra1-01-improveyourself sshd[13999]: reverse mapping checking getaddrinfo for 67-219-227-156.mycomspan.com [67.219.227.156] failed - POSSIBLE BREAK-IN ATTEMPT!
May  2 11:16:49 ubuntu-512mb-fra1-01-improveyourself sshd[13999]: Invalid user wordpress from 67.219.227.156
May  2 11:16:49 ubuntu-512mb-fra1-01-improveyourself sshd[13999]: input_userauth_request: invalid user wordpress [preauth]
May  2 11:16:49 ubuntu-512mb-fra1-01-improveyourself sshd[13999]: pam_unix(sshd:auth): check pass; user unknown
May  2 11:16:49 ubuntu-512mb-fra1-01-improveyourself sshd[13999]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=67.219.227.156
May  2 11:16:52 ubuntu-512mb-fra1-01-improveyourself sshd[13999]: Failed password for invalid user wordpress from 67.219.227.156 port 37151 ssh2
May  2 11:16:52 ubuntu-512mb-fra1-01-improveyourself sshd[13999]: Received disconnect from 67.219.227.156: 11: Bye Bye [preauth]
  

系统日志:

May  2 07:17:01 ubuntu-512mb-fra1-01-improveyourself CRON[12670]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
May  2 08:17:01 ubuntu-512mb-fra1-01-improveyourself CRON[12920]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
May  2 09:17:01 ubuntu-512mb-fra1-01-improveyourself CRON[13174]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
May  2 10:17:01 ubuntu-512mb-fra1-01-improveyourself CRON[13473]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
May  2 11:05:55 ubuntu-512mb-fra1-01-improveyourself kernel: [167847.860083] init: Failed to spawn MyApp main process: unable to execute: No such file or directory
May  2 11:07:02 ubuntu-512mb-fra1-01-improveyourself kernel: [167915.147641] init: Failed to spawn MyApp main process: unable to execute: No such file or directory
May  2 11:07:12 ubuntu-512mb-fra1-01-improveyourself kernel: [167925.023643] init: Failed to spawn MyApp main process: unable to execute: No such file or directory
May  2 11:07:50 ubuntu-512mb-fra1-01-improveyourself kernel: [167963.214775] init: Failed to spawn MyApp main process: unable to execute: No such file or directory
May  2 11:15:49 ubuntu-512mb-fra1-01-improveyourself kernel: [168442.437658] init: Failed to spawn MyApp main process: unable to execute: No such file or directory
May  2 11:16:29 ubuntu-512mb-fra1-01-improveyourself kernel: [168481.799393] init: Failed to spawn MyApp main process: unable to execute: No such file or directory
May  2 11:17:01 ubuntu-512mb-fra1-01-improveyourself CRON[14004]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
  

更新:

(project_juda) juldou@ubuntu-512mb-fra1-01-improveyourself:~/MyApp/project_juda/bin$ ls
MyApp.sock   activate      activate.fish     easy_install      markdown_py  pip3    pwiz.py     python         python3    wheel
__pycache__  activate.csh  activate_this.py  easy_install-3.4  pip          pip3.4  pygmentize  python-config  python3.4
(project_juda) juldou@ubuntu-512mb-fra1-01-improveyourself:~/MyApp/project_juda/bin$ deactivate
juldou@ubuntu-512mb-fra1-01-improveyourself:~/MyApp/project_juda/bin$ gun
gunicorn         gunicorn_django  gunicorn_paster  gunzip           
juldou@ubuntu-512mb-fra1-01-improveyourself:~/MyApp/project_juda/bin$ gunicorn --workers 3 --bind unix:MyApp.sock -m 007 wsgi 
[2016-05-02 11:44:31 +0000] [14195] [INFO] Starting gunicorn 19.4.5
[2016-05-02 11:44:31 +0000] [14195] [INFO] Listening at: unix:MyApp.sock (14195)
[2016-05-02 11:44:31 +0000] [14195] [INFO] Using worker: sync
[2016-05-02 11:44:31 +0000] [14200] [INFO] Booting worker with pid: 14200
[2016-05-02 11:44:31 +0000] [14200] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 130, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 357, in import_app
    __import__(module)
ImportError: No module named wsgi
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 130, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 357, in import_app
    __import__(module)
ImportError: No module named wsgi
[2016-05-02 11:44:31 +0000] [14200] [INFO] Worker exiting (pid: 14200)
[2016-05-02 11:44:31 +0000] [14195] [INFO] Shutting down: Master
[2016-05-02 11:44:31 +0000] [14195] [INFO] Reason: Worker failed to boot.

1 个答案:

答案 0 :(得分:0)

我认为该行

chdir /home/juldou/MyApp

不会将目录更改为wsgi所在的位置。

尝试将/home/juldou/MyApp更改为您可以从终端运行它的路径。