strace便å©ã§ããããæè¿ãnginxãã©ã®ãã¡ã¤ã«éãã¦ãã®ã調ã¹ãã®ã«ä½¿ãã¾ããããã ãOSXã ã¨ããã«æºããã³ãã³ãã£ã¦ãªãã®ããªã¼ã¨åæã«è«¦ãã¦ããã®ã§ãããããã¾ãããã
dtruss
straceã¨åãããã« sudo dtruss -p ããã»ã¹ID
ã§ã·ã¹ãã ã³ã¼ã«ã確èªã§ããã
ä¾ãã°ãnginxã§ç¢ºèªãã¦ã¿ããã
$ ps -ef | grep nginx 501 31223 1 0 6:22PM ?? 0:00.00 nginx: master process nginx 501 31224 31223 0 6:22PM ?? 0:00.00 nginx: worker process 501 31935 31725 0 8:07PM ttys005 0:00.00 grep nginx
ã¯ã¼ã«ã¼ãè¦ãã°è¯ãã®ã§ã 31224
ã«ã¢ã¿ãããã¦ã¿ããã
$ sudo dtruss -p 31224
ããããã«Webãã¼ã¸ã«ã¢ã¯ã»ã¹ãã¦ã¿ãã
SYSCALL(args) = return kevent(0x8, 0x7F91DD005C00, 0x1) = 1 0 recvfrom(0x3, 0x7F91DD005400, 0x400) = 469 0 stat64("/usr/local/Cellar/nginx/1.6.2/html/index.html\0", 0x7FFF5DEEF148, 0x400) = 0 0 open("/usr/local/Cellar/nginx/1.6.2/html/index.html\0", 0x4, 0x0) = 10 0 fstat64(0xA, 0x7FFF5DEEEF08, 0x0) = 0 0 writev(0x3, 0x7FFF5DEEE9D0, 0x1) = 179 0 write(0x4, "127.0.0.1 - - [31/Dec/2014:20:08:35 +0900] \"GET / HTTP/1.1\" 304 0 \"-\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36\"\n\0", 0xC1) = 193 0 close(0xA) = 0 0 access("/etc/localtime\0", 0x4, 0x0) = 0 0 open_nocancel("/etc/localtime\0", 0x0, 0x0) = 9 0 fstat64(0x9, 0x7FFF5DEEBFC0, 0x0) = 0 0 read_nocancel(0x9, "TZif\0", 0x2A64) = 126 0 close_nocancel(0x9) = 0 0 accept(0x6, 0x7FFF5DEEF430, 0x7FFF5DEEF42C) = 9 0
æ¨æºã¨ã©ã¼ãæ¨æºåºåã«ãªãã¤ã¬ã¯ãããã°grepãã§ããã®ã§ããããã¸ããstraceã¨åãã§ããã
$ sudo dtruss -p 31224 2>&1 | grep open open_nocancel("/etc/localtime\0", 0x0, 0x0) = 10 0 open("/usr/local/Cellar/nginx/1.6.2/html/index.html\0", 0x4, 0x0) = 10 0
ã¡ãªã¿ã«ãHomebrewã§ã¤ã³ã¹ãã¼ã«ããnginxã®ä½ãä½ã ãåãããªãåé¡
ãã®æ¤è¨¼ã«ããããé©å½ãªããã»ã¹ã¨ãã¦nginxåãããã¨æãã¾ãããã§ãHomebrewã§ã¤ã³ã¹ãã¼ã«ãã¦ã¿ãã®ã§ãããã©ã®ãã¼ãã§åãã¦ããã¨ãããããããããããªãã£ãã®ã§èª¿ã¹ã¦ã¿ã¾ããã®ã¡ã¢ï¼lsofã®ä½¿ãæ¹ãã¤ãå¿ããã®ã ã£ãï¼ã
ã¡ãªã¿ã«ãèµ·åã¯åã« nginx
ã¨æã¤ã ãã§è¯ãã
lsofã¯ããã»ã¹åã§æ¤ç´¢ãããã¨ãã§ããã®ã§ãä»åã¯nginxãæå®ãã¦èª¿ã¹ãããã®å ´åã-c
ãªãã·ã§ã³ã使ç¨ãããããã«ã-P
ãªãã·ã§ã³ã使ç¨ãããã¨ã§ãã¼ãçªå·ãçã®ã¾ã¾ï¼æ°å¤ã§ï¼è¡¨ç¤ºãããªãã·ã§ã³ã追å ãã¦ããã
$ lsof -c nginx -P | grep LISTEN nginx 32055 sugamasao 6u IPv4 0xed732b31079edf33 0t0 TCP *:8080 (LISTEN) nginx 32056 sugamasao 6u IPv4 0xed732b31079edf33 0t0 TCP *:8080 (LISTEN)
ããããã¨ãã©ãããLISTENãã¦ããã®ã¯8080ãã¼ããããã¨ãããã¨ããããã
-P
ãæå®ããªãå ´åããããªæãã«ãªã£ã¦Service Nameã¨ããã®å¤ã«å¤æããããã«ãªã£ã¦ããï¼çãã¼ã¿ãããã©ã«ãã«ãã¦ã»ãããªãï¼ã
$ lsof -c nginx | grep LISTEN nginx 32055 sugamasao 6u IPv4 0xed732b31079edf33 0t0 TCP *:http-alt (LISTEN) nginx 32056 sugamasao 6u IPv4 0xed732b31079edf33 0t0 TCP *:http-alt (LISTEN)
ã£ã¦ããããã¾ã¨ãã«lsof
ã®çµæè¦ãã¨ãªã¼ãã³ãã¦ããã¡ã¤ã«ã¨ããããããçµæ§è¯ãã§ãããããã
ãªãã±
Homebrewã§ã¤ã³ã¹ãã¼ã«ãããnginxã使ãconfã®å ´æãããã¨ããããªãã¦ãããªæãã§ç¢ºèªãã¾ããï¼ãããã使ãæ¹ãã§ããããã¨ãããã¨ã§ä¸ã¤ï¼ã
masterããã»ã¹ããããã¯ããã»ã¹åèªä½ã§dtrussã§ã¢ã¿ãããã¦ãnginx -s reload
ã§è¨å®ãã¡ã¤ã«ãèªã¿ç´ããã¨ã§ãã©ãã®ãã¡ã¤ã«ãåç
§ãã¦ãããã確èªã§ããã
$ sudo dtruss -n nginx 2>&1 | grep conf
ãããã¦ããå¥ã¿ã¼ããã«ã§ nginx -s reload
ããã¨ãããªæãã®ãã°ã表示ããã¦ããã
32880/0x641a4: stat64("/usr/lib/system/libsystem_configuration.dylib\0", 0x7FFF54E3E9F8, 0x2) = 0 0 32055/0x6168e: open("/usr/local/etc/nginx/nginx.conf\0", 0x0, 0x0) = 4 0 32880/0x641a4: read_nocancel(0x4, "#\n# OpenSSL example configuration file.\n# This is mostly being used for generation of certificate requests.\n#\n\n# This definition stops the following lines choking if HOME isn't\n# defined.\nHOME\t\t\t= .\nRANDFILE\t\t= $ENV::HOME/.rnd\n\n# Extra OBJECT IDENTIFIER in", 0x1000) = 4096 0 32880/0x641a4: open("/usr/local/etc/nginx/nginx.conf\0", 0x0, 0x0) = 4 0
å
容ã確èªãã¦ã¿ãã¨ãã©ããã /usr/local/etc/nginx/nginx.conf
ã£ã½ããªã£ã¦ã®ãããã£ãã便å©ãã