Search code examples
pythonflaskgunicornsupervisord

Python: supervisor configure file to execute gunicorn


Newbie to python, I use Flask+gunicorn+supervisor+ngnix to run a server. And each is set well, my problem is I can not use supervisor to make gunicorn to run some execution.
Below is hierarchy of file:

.  
├── logs  
│   ├── access.log  
│   └── gunicorn_supervisor.log  
└── tserver  
    ├── bin  
    ├── build  
    ├── flasky   
    │   ├── @   
    │   ├── app  
    │   ├── hello.py  
    │   ├── LICENSE   
    │   └── README.md    
    ├── gunicorn.conf  
    ├── include  
    ├── lib  
    ├── local  
    └── pip-selfcheck.json   

tserver is created by virtualenv.

/etc/supervisor/conf.d/tserver.conf :

[program:tserver]
command=/home/jason/tserver/bin/gunicorn hello:app -c /home/jason/tserver/gunicorn.conf
directory=/home/jason/tserver/
user=jason
autostart=true
autorestart=true
stdout_logfile=/home/jason/logs/gunicorn_supervisor.log

My purpose is to let supervisor to make gunicorn run the hello.py, but it doesn't work. I use sudo supervisor status to see the status and found:

tserver      FATAL      Exited too quickly (process log may have details) 

I got a strong feeling that the problem must comes from the tserver.conf, especially the command.

Look the file, the hello.py is in the file named "flasky", Socommand=/home/jason/tserver/bin/gunicorn hello:app -c /home/jason/tserver/gunicorn.conf I think has some problem for the path. But command=/home/jason/tserver/bin/gunicorn ./hello:app -c /home/jason/tserver/gunicorn.conf still doesn't work.

And I think it's a very stupid question for experienced ones, but as a newbie I am stuck, So please give me a detail solution, since I have read the relevant documents and did not get it. Thanks for your favor.


Solution

  • Finally I find my mistake, I scp my own env to the server, which makes the gunicorn unable to work. I don't know the reason, but when I reinstall the env and the gunicorn, it works.

    What's more, the hello.py is in the flasky, so the directory in tserver.conf should be :

    directory=/home/jason/tserver/flasky/