Gunicorn 㨠uWSGI ãç¨ãã Web ã¢ããªã±ã¼ã·ã§ã³ã®ãããã¤
Gunicorn ã uWSGI (ã¾ãã¯ããã«é¡ãããã®) ã使ã£ã¦ Web ã¢ããªã±ã¼ã·ã§ã³ããããã¤ããå ´åãã¯ã©ã¤ã¢ã³ãã®ãªã¯ã¨ã¹ããå¦çããããã«è¤æ°ã®ã¯ã¼ã«ã¼ããã»ã¹ãä½ããã¾ãããã®ãããªç°å¢ã§ã¯ã web ã¢ããªã±ã¼ã·ã§ã³ã«ç´æ¥ãã¡ã¤ã«ãã¼ã¹ã®ãã³ãã©ãä½ããã¨ã¯é¿ãã¦ãã ããã 代ããã«ã SocketHandler ã使ã£ã¦å¥ã®ããã»ã¹ã¨ãã¦åä½ãããªã¹ãã¼ã« web ã¢ããªã±ã¼ã·ã§ã³ãããã°ãéä¿¡ããããã«ãã¦ãã ããããã㯠Supervisor ã®ãããªããã»ã¹ç®¡çãã¼ã«ã使ããã¨ã§è¨å®ã§ãã¾ãã
ãã®ã³ã°ã½ã±ããã®ãªã¹ãã¼ãå®è¡ãã
ä½æä¸ã®ãã®ã³ã°ãªã¹ãã¼ãå®è¡ããããã«ã¯ã Supervisor ã®ãããªããã»ã¹ç®¡çãã¼ã«ã使ãå¿ è¦ãããããããã¾ããã [ãã¡ãã® Gist] (https://gist.github.com/vsajip/4b227eeec43817465ca835ca66f75e2b)㯠Supervisor ã使ã£ã¦ä¸è¨ã®æ©è½ãå®è¡ããããã®å¿ è¦æä½éã®ãã¡ã¤ã«ãæä¾ãã¦ãã¾ãã以ä¸ã®ãã¡ã¤ã«ãå¿ è¦ã«ãªãã¾ã:
ãã¡ã¤ã« | ç®ç |
---|---|
prepare.sh | 試é¨ç¨ã®ç°å¢ãæºåãã Bash ã¹ã¯ãªãã |
supervisor.conf | ãªã¹ãã¼ã¨ãã«ãããã»ã¹ã® web ã¢ããªã±ã¼ã·ã§ã³ã®ããã®è¨å®ãå«ã Supervisor ã®è¨å®ãã¡ã¤ã« |
ensure_app.sh | Supervisor ãä¸è¨ã®è¨å®ã§å®è¡ããã¦ãããã¨ãä¿è¨¼ããããã® Bash ã¹ã¯ãªãã |
log_listener.py | ãã°ã¤ãã³ããåä¿¡ãã¦ãã¡ã¤ã«ã«è¨é²ããã½ã±ãããªã¹ãã¼ããã°ã©ã |
main.py | ãªã¹ãã¼ã«æ¥ç¶ãããã½ã±ãããéãã¦ãã®ã³ã°ãå®è¡ããç°¡å㪠web ã¢ããªã±ã¼ã·ã§ã³ |
webapp.json | web ã¢ããªã±ã¼ã·ã§ã³ã®ããã® JSON è¨å®ãã¡ã¤ã« |
client.py | web ã¢ããªã±ã¼ã·ã§ã³ãèµ·åããããã® Python ã¹ã¯ãªãã |
ãã® web ã¢ããªã±ã¼ã·ã§ã³ã¯ããªã¯ã¨ã¹ããå¦çããè¤æ°ã®ã¯ã¼ã«ã¼ããã»ã¹ãèµ·åãã web ã¢ããªã±ã¼ã·ã§ã³ãµã¼ãã¼ã§ãã Gunicorn ã使ã£ã¦ãã¾ããããã«ä¾ã¨ãã¦æããè¨å®ã¯ãè¤æ°ã®ã¯ã¼ã«ã¼ãããã«ãã¦äºãã«è¡çªãããã¨ãªãåããã°ãã¡ã¤ã«ã«æ¸ãè¾¼ã¿ãè¡ããã¨ãã§ãããã示ãã¦ãã¾ã --- ã¯ã¼ã«ã¼ã¯å ¨ã¦ã½ã±ãããªã¹ãã¼ãéãã¦ãã°ãæ¸ãè¾¼ãã®ã§ãã
ãããã®ãã¡ã¤ã«ã試ãããã«ã¯ã POSIX ç°å¢ã«ããã¦ä»¥ä¸ãè¡ãªã£ã¦ãã ãã:
Download ZIP ãã¿ã³ãæ¼ã㦠Gist ã ZIP ã¢ã¼ã«ã¤ãã¨ãã¦ãã¦ã³ãã¼ããã¦ãã ããã
ã¢ã¼ã«ã¤ããã¡ã¤ã«ãã¹ã¯ã©ãããã£ã¬ã¯ããªã«å±éãã¦ãã ããã
æºåã®ããã«ãã¹ã¯ã©ãããã£ã¬ã¯ããªã«ããã¦
bash prepare.sh
ãå®è¡ãã¦ãã ãããããã«ãã Supervisor é¢é£ã®ãã¡ã¤ã«ããã³ãã°ãã¡ã¤ã«ã®ããã® run ãµããã£ã¬ã¯ããªãããã³ bottle, gunicorn ãã㦠supervisor ãã¤ã³ã¹ãã¼ã«ãããä»®æ³ç°å¢ãå«ã venv ãµããã£ã¬ã¯ããªãçæããã¾ããbash ensure_app.sh
ãå®è¡ã㦠Supervisor ãä¸è¨ã®è¨å®ã§å®è¡ããã¦ãããã¨ã確èªãã¦ãã ãããvenv/bin/python client.py
ãå®è¡ã㦠web ã¢ããªã±ã¼ã·ã§ã³ãèµ·åãã¦ãã ãããããã«ãããã°ã«ã¬ã³ã¼ããæ¸ãè¾¼ã¾ããã¯ãã§ããrun ãµããã£ã¬ã¯ããªã«ãããã°ãã¡ã¤ã«ã調ã¹ã¦ãã ãããææ°ã®ãã°ã¯ããã¿ã¼ã³ app.log* ã«ä¸è´ããååã®ãã¡ã¤ã«ã«ããã¯ãã§ãããã°ã¯ç°ãªãã¯ã¼ã«ã¼ããã»ã¹ã«ãã£ã¦é決å®è«çãªå½¢ã§ä¸¦è¡ã«å¦çããããããç¹å®ã®æ±ºã¾ã£ãé çªã«ã¯ãªãã¾ããã
ãªã¹ãã¼ã¨ web ã¢ããªã±ã¼ã·ã§ã³ã¯
venv/bin/supervisorctl -c supervisor.conf shutdown
ãå®è¡ãããã¨ã§ã·ã£ãããã¦ã³ã§ãã¾ãã
ããããããªããã¨ã§ããããã¹ãç°å¢ã§è¨å®ãããã¼ããå¥ã®è¨å®ã¨è¡çªãã¦ãã¾ã£ãå ´åãè¨å®ãã¡ã¤ã«ãä¿®æ£ããå¿ è¦ãããããããã¾ããã