Linux Process management Tools--god-Detailed (1)-Getting Started

Source: Internet
Author: User

God is a monitoring architecture written by Ruby that can protect your processes from running, and can restart processes for special situations. Expansion can be done through Frigga to manage the global God.


The best way to install (via ruby-gems):

Gem Install God

Quick Start

Note: The Quick Launch requires more than 0.12 versions, and you can use the following command to view the version:

God--version

A simple example: Use God to keep a simple process.

Here is a simple script with the name hello.py

#!/usr/bin/env python#import timewhile true:print "Hello" time.sleep (1)

Now write a god config file to manage the hello.py process above,Simple.god:

God.watch do |w| W.name = "Hello" W.start = "python/root/god/hello.py" W.keepalive End

This is a simple God configuration, we first declare a god.watch module, which can monitor and control the process above. Each watch must have a unique name and command to start the process. keepalive tells god to ensure that the process survives, and if the process dies,God initiates the process through start defined above.

In This simple example, we run God to the front end to ensure that we can do the relevant viewing.

To run God, we need to specify the configuration file (-c) and ask him to run on the front (-D)

God-c simple.god-d

There are 2 ways thatGod 's monitoring process is in evidence. 1, the best way (based on the event), not every system supports it, but support will automatically use it. When a related event (exit) is generated,God immediately knows. 2.God uses a polling mechanism for systems that do not support events. PS: I am here based on the event mechanism, because of my limitations here, there is no poll based, if want to see: http://godrb.com/

#EventsI  [2014-08-11 11:10:10]  INFO: Loading simple.godI [2014-08-11  11:10:10]  info: syslog enabled. I [2014-08-11 11:10:10]  info: using pid file directory: /var/run /godi [2014-08-11 11:10:10]  info: socket already in usei [ 2014-08-11 11:10:10]  info: socket is stale, reopeningi [2014-08-11  11:10:10]  info: started on drbunix:///tmp/god.17165.socki [2014-08-11  11:10:10]  INFO: hello move  ' unmonitored '  to  ' init ' i [2014-08-11  11:10:10]  INFO: hello moved  ' unmonitored '  to  ' init ' i [ 2014-08-11 11:10:10]  info: hello [trigger] process is not  running  (processrunning) i [2014-08-11 11:10:10]  info: hello move  ' init '  to  ' Start ' I [2014-08-11 11:10:10]  info: hello start:  python /root/god/hello.pyi [2014-08-11 11:10:10]  info: hello moved   ' init '  to  ' start ' i [2014-08-11 11:10:10]  info: hello [trigger]  process is running  (processrunning) I [2014-08-11 11:10:10]  info:  hello move  ' start '  to  ' up ' i [2014-08-11 11:10:10]  info:  hello registered  ' Proc_exit '  event for pid 25779i [2014-08-11 11:10:10 ]  info: hello moved  ' start '  to  ' up '

From the debug message, you can see that theHello process was not started at first, and then God started it. PS: If it is started based on the polling mode, you observe that he will check the process for 5 seconds.

To reflect event-based, I've added one more step here (Kill hello.pyat another endpoint to verify the event-based form):

[[email protected] ~]# ps-ef|grep hello.pyroot 25779 1 0 11:10?  00:00:00 python/root/god/hello.pyroot 25803 25782 0 11:10 pts/1 00:00:00 grep hello.py[[email protected] ~]# kill -9 25779
#Event   Status:i [2014-08-11 11:11:02]  info: hello [trigger] process  25779 exited {:thread_group_id=>25779, :p Id=>25779, :exit_code=>9, :exit_ signal=>17}  (processexits) i [2014-08-11 11:11:02]  info: hello move   ' Up '  to  ' start ' i [2014-08-11 11:11:02]  info: hello deregistered   ' Proc_exit '  event for pid 25779i [2014-08-11 11:11:02]  info:  hello start: python /root/god/hello.pyi [2014-08-11 11:11:02]  info:  hello moved  ' Up '  to  ' start ' i [2014-08-11 11:11:02]  info:  hello [trigger] process is running  (processrunning) i [2014-08-11 11:11:02]   INFO: hello move  ' start '  to  ' up ' i [2014-08-11 11:11:02]   info: hello registered  ' Proc_exit '  event for pid 25807I [2014-08-11 11:11:02]   INFO: hello moved  ' start '  to  ' up '

PS: If it is polling (polls) mode, it is not started immediately, but waits until the check cycle arrives.


Here, you already know how God is going to ensure the process, there are some more empty management methods, such as how much CPU to restart the process,memory to how many restart process, and so on, here is a configuration example:

God.watch do |w| W.name = "Hello" W.start = "python/root/god/hello.py" w.keepalive (: Memory_max = 150.megabytes,: cpu_ma x = 50.percent) End

Explanation:: Memory_max option belongs to keepalive Sub-command: Cpu_max is also. In the configuration above, if the memory reaches 150M, or the CPU reaches 50%,god will restart the process. By default, these processes are checked 1 times in 30 seconds and are restarted (5 over 3 times) to avoid occasional overloads.


  Here is not the case of simulated memory leakage, the following post a restart of the CPU log, the official document:http://godrb.com/  search memory leak

I [2014-08-11 13:35:46] info:hello [trigger] CPU out of bounds [5.3571428566083%, *90.3052064640262%%, *94.706994329297 7%%, *96.3414634148933%%] (cpuusage) I [2014-08-11 13:35:46] info:hello move ' up ' to ' restart ' I [2014-08-11 13:35:46] In Fo:hello deregistered ' Proc_exit ' event for PID 26355I [2014-08-11 13:35:46] Info:hello stop:default Lambda Killeri [2  014-08-11 13:35:46] Info:hello sent Sigtermi [2014-08-11 13:35:47] Info:hello process Stoppedi [2014-08-11 13:35:47] Info:hello start:python/root/god/hello.py

In addition, you can use God to manipulate some processes:

God start Hello #hello为进程名. w.namegod stop hellogod Restart hello ... in the corresponding Simple.god file

So, when you use God's management process, you can write some specific configuration files to manage the related processes. For example: HTTP error, large disk IO, and so on, can help you do something.


This article is from the "Tofu Blog" blog, make sure to keep this source http://407711169.blog.51cto.com/6616996/1538541

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.