Supervisor定期重啟指定進程

來源:互聯網
上載者:User

Supervisor是用Python開發的一個客戶機/伺服器系統,允許使用者監視和控制UNIX類作業系統上的多個進程。功能包括監聽、啟動、停止、重啟一個或多個進程。當Supervisor管理的進程出現意外被Kill後,Supervisor監聽到事件會自動啟動該進程,不需要再寫其他指令碼去進行重啟處理。

關於Supervisor的安裝及設定,可以參考Supervisor官網地址:http://supervisord.org/

Supervisor基本操作命令

1.啟動進程

supervisorctl -c /etc/supervisord.conf start program_name

 
2.停止進程

supervisorctl -c /etc/supervisord.conf stop program_name

 
3.重啟進程

supervisorctl -c /etc/supervisord.conf restart program_name

 
4.啟動所有進程

supervisorctl -c /etc/supervisord.conf start all

 
5.停止所有進程

supervisorctl -c /etc/supervisord.conf stop all


Supervisor自動重啟機制

Supervisor的 autorestart 參數可以設定進程自動重啟的事件,一般設定為:

autorestart=unexpected

當進程意外被kill或出現異常時,Supervisor會自動重啟該進程。

但如果Supervisor監控的進程出現記憶體流失或串連不自動釋放的情況,Supervisor並不會執行重啟,且Supervisor不支援定期自動重啟的方法。

因此當出現這種情況時,我們需要對某些進程進行定期自動重啟。
 
  Supervisor定期重啟指定進程方法

我們可以利用crontab來實現定期任務,設定如下:

例: 每小時重啟進程abc

0 * * * * supervisorctl -c /etc/supervisord.conf restart abc

當對於某些會出現記憶體流失或串連不自動釋放的進程時,我們可以使用以上方法進行定期重啟,解決記憶體流失及釋放串連數。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.