若是用Python寫過線上的後端服務,相信對Supervisor不會陌生,它包含兩個主要工具:
1)supervisord: 用來實現進程守護
2)supervisorctl: 用來實現supervisord對其守護進程的控制,如reload配置文件、啓/停其守護的子進程,等等html
在使用supervisorctl執行以下命令時,python
## 其中sup.xxx.conf是supervisord的配置文件
$ supervisorctl -c conf/sup.xxx.conf
偶爾會遇到以下報錯:web
error: <class 'socket.gaierror'>, [Errno -2] Name or service not known: file: /home/slvher/python/2.7/lib/python2.7/socket.py line: 553
其中,socket.py第553行代碼片斷以下:後端
551 host, port = address
552 err = None
553 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
554 af, socktype, proto, canonname, sa = res
555 sock = None
556 try:
557 sock = socket(af, socktype, proto)
558 if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
559 sock.settimeout(timeout)
560 if source_address:
561 sock.bind(source_address)
562 sock.connect(sa)
563 return sock
基礎庫報錯?
因而,在第553行前面增長調試代碼,print出host和port的值,發現port竟然是」9212;」(其中9212是配置文件sup.xxx.conf中指定的supervisorctl的listen端口)socket
查看sup.xxx.conf文件,發如今supervisorctl的配置部分,配置serverurl時端口後面直接跟着分號,以下示例:svg
[supervisorctl]
;serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
serverurl=http://127.0.0.1:9723; use an http:// url to specify an inet socket
在端口號和註釋符;之間加個空格就解決了:工具
[supervisorctl]
;serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
serverurl=http://127.0.0.1:9723 ; use an http:// url to specify an inet socket
supervisorctl加載配置文件時,竟然沒有正確解析出註釋符,挖的一手好坑。。。ui