supervisor部署tornado

  • supervisord常見命令
supervisorctl shutdown 關閉命令

supervisord -c /etc/supervisord.conf 啓動supervisord

supervisorctl restart all // 重啓全部

supervisorctl restart program-name // 重啓某一進程,program-name爲[program:xx]中的xx

supervisorctl status //查看supervisord狀態
  • 生成配置文件
echo_supervisord_conf > /etc/supervisord.conf
  • 編輯配置文件
因爲配置文件生成在etc目錄下,咱們要作進一步配置
帶有;的行是被註釋的,並不真正發揮做用 [program:olddream] command
=python3 /dingshub/olddream/server.py --port=8989
; 注意上面一行配置,因爲我在linux爲python創建的軟連接名爲python3,各程序員實踐的時候須要按照狀況做調整 ;process_name
=%(program_name)s ; process_name expr (default %(program_name)s) ;numprocs=1 ; number of processes copies to start (def 1) directory=/dingshub/olddream/ ; 網站文件夾實際路徑,這一路經下放着tornado的起始配置文件server.py ;umask=022 ; umask for process (default None) ;priority=999 ; the relative start priority (default 999) autostart=true ; start at supervisord start (default: true) ;autorestart=unexpected ; whether/when to restart (default: unexpected) ;startsecs=1 ; number of secs prog must stay running (def. 1) ;startretries=3 ; max # of serial start failures (default 3) ;exitcodes=0,2 ; 'expected' exit codes for process (default 0,2) ;stopsignal=QUIT ; signal used to kill process (default TERM) ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) ;stopasgroup=false ; send stop signal to the UNIX process group (default false) ;killasgroup=false ; SIGKILL the UNIX process group (def false) ;user=chrism ; setuid to this UNIX account to run the program redirect_stderr=true ; redirect proc stderr to stdout (default false) stdout_logfile=/dingshub/olddream/dings.log ; 最好設置一個log日誌文件 ;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) ;stdout_logfile_backups=10 ; # of stdout logfile backups (default 10) ;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) ;stdout_events_enabled=false ; emit events on stdout writes (default false) ;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO ;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) ;stderr_logfile_backups=10 ; # of stderr logfile backups (default 10) ;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) ;stderr_events_enabled=false ; emit events on stderr writes (default false) ;environment=A="1",B="2" ; process environment additions (def no adds) ;serverurl=AUTO ; override serverurl computation (childutils) loglevel=info           ; 這是一箇中等級別的日誌
  • nginx配置(一個地址多個站點)
分站點配置---這是tornado網站的配置細節

個人nginx是經過編譯源代碼安裝的,在nginx的安裝目錄下,新建一個vhosts文件夾(若是沒有的話)
在vhosts文件夾下創建以 .conf爲後綴的文件
例如:

  upstream tornados{css

    server 127.0.0.1:8989; #能夠發現這裏8989端口與supervisord中的端口一致
    server 127.0.0.1:8021;
    server 127.0.0.1:8022;
  }
  proxy_next_upstream error;
html


  server {
  listen 8989;
  server_name sniffcpcssocks.com;
  root /dingshub/olddream;
  index server.py;

  # 靜態文件直接由Nginx處理
  location /static/{
  alias /data/web/advance_python/tornado_asyn/img/;
  expires 24h;
  }
  location /{
  proxy_pass_header Server;
  proxy_set_header Host $http_host;
  proxy_redirect off;
  proxy_set_header X-Real-IP $remote_addr;
  # 把請求方向代理傳給tornado服務器,負載均衡
  proxy_pass http://tornados;
  }
 }python

  • nginx conf文件夾下 nginx.conf主文件配置(我也並不瞭解nginx配置要訣---這種配置起碼能夠保證網站跑起來)
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    include /nginx/vhosts/*.conf;   #這一句是一個ip地址,多個站點配置的關鍵
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       8999;
        server_name  localhost;

       
        location / {
            root   html;
            index  index.html index.htm;
        }

       
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
       
    }

}
  • tornado網站主程序文件server.py(注意!這一程序文件裏,不要出現任何註釋符號,還有中文,由於supervisord執行時可能會出現異常)
import tornado.ioloop

import tornado.web

import tornado.httpserver

import os


..........

settings={

    'template_path':os.path.join(os.getcwd(),"templates"),

    'static_path':os.getcwd()+"//templates//static"

}

def App():

    return tornado.web.Application([

        (r'/loadcolspage',loadcolspage),
        .........
        
        (r'/xsfp/list', xsfp_v)],**settings)

if __name__=="__main__":

    app = App()

    print(("current_path:"),os.path.join(os.getcwd()+"//templates",'static'))

    myserver = tornado.httpserver.HTTPServer(app)

    myserver.listen(8989)

    tornado.ioloop.IOLoop.current().start()
相關文章
相關標籤/搜索