2013-03-08 45 views
6

我想從Ubuntu 12.04系統的Supervisor中運行Gunicorn。 Gunicorn運行一個Flask應用程序(用Flask的嵌入式服務器測試簡單的REST Web服務)。我通過克隆GIT repo來安裝Gunicorn,試圖避免'apt-get install',因爲它在安裝時運行Gunicorn服務器。我不希望它運行,它只會由Supervisor運行。主管沒有和Gunicorn + Flask一起工作

所以以後安裝它,如果我嘗試:

cd /usr/local/bin 
gunicorn my_app:app -c /path/to/gu_config_file 

Gunicorn工作。然後我殺了它。注意沒有擴展名的配置文件,因爲'.py'擴展名對我不起作用。 所以我喜歡編輯監事的配置文件:在超級

[program:gunicorn] 
command=/usr/local/bin/gunicorn my_app:app -c /path/to/.gu_setup 
directory=/usr/local/bin/ 
autostart=true 
autorestart=true 
redirect_stderr=True 

和更新變化:

supervisorctl reread 
# gunicorn: changed 
supervisorctl update 
# gunicorn: stopped 
# gunicorn: updated process group 

檢測到更改文件和工程Gunicorn程序。好了,但後來我嘗試啓動它:

supervisorctl start gunicorn 

獲取一個惱人的:

gunicorn: ERROR (abnormal termination) 

檢查監督員日誌:

2013-03-08 13:07:22,378 INFO spawned: 'gunicorn' with pid 3355 
2013-03-08 13:07:22,916 INFO exited: gunicorn (exit status 3; not expected) 
2013-03-08 13:07:23,918 INFO spawned: 'gunicorn' with pid 3361 
2013-03-08 13:07:24,492 INFO exited: gunicorn (exit status 3; not expected) 
2013-03-08 13:07:26,496 INFO spawned: 'gunicorn' with pid 3367 
2013-03-08 13:07:27,078 INFO exited: gunicorn (exit status 3; not expected) 
2013-03-08 13:07:30,085 INFO spawned: 'gunicorn' with pid 3373 
2013-03-08 13:07:30,628 INFO exited: gunicorn (exit status 3; not expected) 
2013-03-08 13:07:31,630 INFO gave up: gunicorn entered FATAL state, too many start retries too quickly 

我不知道現在該怎麼辦.. 。 你可以幫我嗎? Thx很多!

編輯:對不起,我忘了說我已出口PYTHONPATH變量:

export PYTHONPATH=/usr/local/bin:/usr/local/lib/project 

'my_app應用' 是在/ usr/local/bin目錄。其他模塊需要lib路徑。 我也編輯主管的配置文件,以表明環境變量,如:

environment=PYTHONPATH=/usr/local/bin:/usr/local/lib/project/ 

但沒有奏效。

編輯2:如@robertklep在他的評論暗示,這是日誌的輸出:

Traceback (most recent call last): 
    File "/tmp/gunicorn/gunicorn/arbiter.py", line 485, in spawn_worker 
    worker.init_process() 
    File "/tmp/gunicorn/gunicorn/workers/base.py", line 100, in init_process 
    self.wsgi = self.app.wsgi() 
    File "/tmp/gunicorn/gunicorn/app/base.py", line 103, in wsgi 
    self.callable = self.load() 
    File "/tmp/gunicorn/gunicorn/app/wsgiapp.py", line 25, in load 
    return util.import_app(self.app_uri) 
    File "/tmp/gunicorn/gunicorn/util.py", line 369, in import_app 
    __import__(module) 
    File "/usr/local/bin/my_app.py", line 4, in <module> 
    import const 
ImportError: No module named const 
2013-03-08 13:29:35 [3670] [INFO] Worker exiting (pid: 3670) 
2013-03-08 13:29:36 [3665] [INFO] Shutting down: Master 
2013-03-08 13:29:36 [3665] [INFO] Reason: Worker failed to boot. 

'常量' 模塊是在/ usr/local/lib目錄/項目...

回答

8

我不看不到你,在你的上司的配置文件設置環境:

[program:gunicorn] 
environment=PYTHONPATH=/usr/local/bin:/usr/local/lib/project 
command=/usr/local/bin/gunicorn my_app:app -c /path/to/.gu_setup 
... 

如果還是不行,請嘗試啓動調試模式gunicorn:

command=/usr/local/bin/gunicorn --debug --log-level debug my_app:app -c /path/to/.gu_setup 

或者傳遞路徑直接gunicorn:

command=/usr/local/bin/gunicorn --pythonpath /usr/local/bin,/usr/local/lib/project my_app:app -c /path/to/.gu_setup 

編輯: gunicorn的--pythonpath壞了,你只能通過一個目錄:

command=/usr/local/bin/gunicorn --pythonpath /usr/local/lib/project my_app:app -c /path/to/.gu_setup 
+0

是的,我這樣做,並在您迴應我的同時編輯我的問題......對不起!我正在做你說的,等待它! :) – 2013-03-08 12:30:24

+0

所以告訴我它找不到'const'模塊,但是它在/ usr/local/lib/project中,添加到Supervisor配置文件中的環境中... – 2013-03-08 12:38:41

+0

請參閱我的關於將路徑直接傳遞給gunicorn的編輯。 – robertklep 2013-03-08 12:45:50

3

這是沒有必要通--pythonpath 。如果你工作virtuanenv你把增加在哪裏是gunicorn。例如:

command=/home/virtualenv/bin/gunicorn application:app -c /home/virtualenv/deploy/gunicorn.conf.py 

和目錄是當瓶代碼,例如:

directory=/home/virtualenv/myapp 

記住用戶是根!

user=root