用newlisp管理windows下的nginx

來源:互聯網
上載者:User

我寫了一個nginx.lsp檔案,可以通過傳遞參數來進行Nginx進程管理。

使用方法

1. 從nginx網站下載windows版本的程式,加壓後,將newlisp.lsp檔案複製到該目錄。

2. 確保windows的system32目錄下有newlisp.exe程式。

3. 運行程式, 目前支援5個參數

 

newlisp nginx.lsp start|stop|monitor|reload|view

 

比如下面用view來觀察進程:

 

c:\newlisp nginx.lsp viewImage Name                     PID Session Name        Session#    Mem Usage========================= ======== ================ =========== ============nginx.exe                     8048 Console                    1      6,716 Knginx.exe                     4512 Console                    1      6,988 Knginx.exe                     1684 Console                    1      6,836 Knginx.exe                     4652 Console                    1      7,132 Knginx.exe                     6512 Console                    1      6,816 Knginx.exe                     6868 Console                    1      7,152 K

可以用stop參數關閉所有nginx進程。

 

具體實現代碼如下:

 

;; parse argument as one of the following;; start|stop|reload|monitor|view(define (start)  (process "start.bat")  )(define (kill-process e)  (if (regex "^nginx.exe" e)      (begin(set 'pid ((regex "^nginx.exe[ ]+([0123456789]+)" e) 3))(exec (append "Taskkill /PID " pid " /F")))))(define (handle-element e)  (if (regex "^nginx.exe" e)      (set 'h true)))(define (check-nginx-process)  (set 'cmd "tasklist /fi \"imagename eq nginx.exe\"")  (set 'result (exec cmd))  (set 'h nil)  (dolist (str result)  (handle-element str))  )(define (kill-nginx-processes)  (set 'cmd "tasklist /fi \"imagename eq nginx.exe\"")  (set 'result (exec cmd))  (set 'h nil)  (dolist (str result)  (kill-process str))  )(define (view)  (set 'cmd "tasklist /fi \"imagename eq nginx.exe\"")  (set 'result (exec cmd))  (dolist (str result)  (println str))  )(define (stop)  (set 'cmd "tasklist /fi \"imagename eq nginx.exe\"")  (set 'result (exec cmd))    (check-nginx-process)  (if h      (begin(println "stoping nginx now ...")(exec "nginx -s stop")(check-nginx-process)(if h    (begin      (println "kill nginx processes ...")      (kill-nginx-processes)      )))      (println "do nothing because nginx is stopped"))  )(define (reload)  (exec "nginx -s reload")  )(define (monitor)  (while true (begin   (sleep 10000)   (println "check nginx process at 10 seconds")   (check-nginx-process)   (unless h   (begin     (println "nginx is stopped, start it now ...")     (start))   (println "nginx process is alive")   )   ) )  )(define (main-fun)  (set 'action ((main-args) 2))  (unless action  (begin    (println "please pass one of the arguments: start|stop|reload|monitor|view")    (exit)))  (if (= "start" action)     (start))  (if (= "stop" action)     (stop))  (if (= "reload" action)     (reload))  (if (= "monitor" action)     (monitor))  (if (= "view" action)      (view))  )(main-fun)(exit)

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.