-
-
Save nowherekai/d3628aebab586d131e7c to your computer and use it in GitHub Desktop.
god
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
god使用ruby写的监控框架,优点是配置文件也是用ruby代码。 | |
[官网](http://godrb.com/) | |
简单使用: | |
simple.rb | |
```ruby | |
loop do | |
puts "hello" | |
sleep 5 | |
end | |
``` | |
然后写一个简单的god配置文件, 位置是在同一个目录下。simple.god.rb | |
```ruby | |
God.watch do |w| | |
w.name = 'simple' | |
w.start = 'ruby /path/to/simpel.rb' | |
w.keepalive | |
end | |
这是一个最简单的配置。在god中,一个watch表示我们需要监控和控制的进程。每个watch必须(最少)有一个唯一的名字,和一个开始命令(w.start)。keepalive表示god需要保持这个程序为启动状态,god启动时若程序未程序则启动它, 如果程序挂了需要拉起来。上面的配置没有讲到pid, 下面会讲到。 | |
启动god: | |
```ruby | |
god -c simple.god.rb -D | |
``` | |
-D选项表示在stdout输出log。输出如下, | |
``` | |
I [2014-08-29 14:05:01] INFO: Loading simple.god | |
I [2014-08-29 14:05:01] INFO: Syslog enabled. | |
I [2014-08-29 14:05:01] INFO: Using pid file directory: /home/klc/.god/pids | |
I [2014-08-29 14:05:01] INFO: Started on drbunix:///tmp/god.17165.sock | |
I [2014-08-29 14:05:01] INFO: simple move 'unmonitored' to 'up' | |
I [2014-08-29 14:05:01] INFO: simple moved 'unmonitored' to 'up' | |
``` | |
可以通过kill -9 $simpe_process_no 杀掉simple程序测试god是否重启了simple.rb | |
使用`god stop simple` 杀掉simple程序, `god start simple`重新启动simple程序。 | |
以上是god的简单使用, 通过配置文件可以设置很多其他高级功能,比如占用了内存和CPU超过指定的百分比后会重启程序等等。 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment