Posted on September 20, 2021
| 2 minutes
| 390 words
| appleboy
相信大家都有管理 Linux 主機 Process 的經驗,用的工具也是千奇百種,但是肯定對 Python 版本的 Supervisor 並不陌生,這套工具相當好用,可以監控不同的 Process 狀態,也可以自動重啟。而本篇要介紹用 Go 語言寫出來的開源套件『Supervisord』,作者提到為什麼要用 Go 語言開發此工具,原因很簡單,就是透過 Go 語言的跨平台優勢,寫一套程式,可以直接跑在任何平台,管理者就不需要再為了 Python 環境而煩惱。
ifatomic.LoadInt32(&stopped)==0{log.WithFields(log.Fields{"program":p.GetName()}).Info("force to kill the program")p.Signal(syscall.SIGKILL,killasgroup)killEndTime:=time.Now().Add(killwaitsecs)forkillEndTime.After(time.Now()){//if it exitsifp.state!=Starting&&p.state!=Running&&p.state!=Stopping{atomic.StoreInt32(&stopped,1)break}time.Sleep(10*time.Millisecond)}atomic.StoreInt32(&stopped,1)}
# HELP node_supervisord_exit_status Process Exit Status# TYPE node_supervisord_exit_status gaugenode_supervisord_exit_status{group="tip-agent",name="tip-agent"} 0node_supervisord_exit_status{group="tip-backend",name="tip-backend"} 0# HELP node_supervisord_start_time_seconds Process start time# TYPE node_supervisord_start_time_seconds counternode_supervisord_start_time_seconds{group="tip-agent",name="tip-agent"} 1.632135574e+09
node_supervisord_start_time_seconds{group="tip-backend",name="tip-backend"} 1.632135593e+09
# HELP node_supervisord_state Process State# TYPE node_supervisord_state gaugenode_supervisord_state{group="tip-agent",name="tip-agent"} 20node_supervisord_state{group="tip-backend",name="tip-backend"} 20# HELP node_supervisord_up Process Up# TYPE node_supervisord_up gaugenode_supervisord_up{group="tip-agent",name="tip-agent"} 1node_supervisord_up{group="tip-backend",name="tip-backend"} 1