rt_watchdog 1.0.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/rt_watchdog ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rt_watchdog'
4
+ require 'rt_watchdog/daemon'
5
+
6
+ RTwatchdog::Daemon.new.run
7
+
@@ -0,0 +1,51 @@
1
+ module RTwatchdog
2
+
3
+ class Daemon
4
+
5
+ def run
6
+
7
+ trap('TERM') do
8
+ stop
9
+ exit
10
+ end
11
+
12
+ loop do
13
+ start unless running?
14
+ restart if ram_too_big?
15
+ sleep 2
16
+ end
17
+ end
18
+
19
+ def start
20
+ `#{RTwatchdog::START}`
21
+ end
22
+
23
+ def stop
24
+ begin
25
+ Timeout::timeout RTwatchdog::TIMEOUT do
26
+ `#{RTwatchdog::STOP}`
27
+ end
28
+ rescue Timeout::Error
29
+ `#{RTwatchdog::REALLY_STOP}`
30
+ end
31
+ end
32
+
33
+ def restart
34
+ stop
35
+ start
36
+ end
37
+
38
+ def ram
39
+ `#{RTwatchdog::RAM}`.to_i
40
+ end
41
+
42
+ def running?
43
+ `#{RTwatchdog::RUNNING}`.length > 0
44
+ end
45
+
46
+ def ram_too_big?
47
+ ram > RTwatchdog::MAX_RAM
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,43 @@
1
+ module RTwatchdog
2
+
3
+ # RT binary name without path
4
+ #
5
+ BIN = 'rt-server.fcgi'
6
+
7
+ # RT sbin directory
8
+ #
9
+ RT_SBIN = '/opt/rt4/sbin'
10
+
11
+ # command to get PID of RT
12
+ #
13
+ PID = "ps -e awk '$4 ~ /^#{BIN}$/ {print $1}'"
14
+
15
+ # command to start RT
16
+ #
17
+ START = "spawn-fcgi -u www-data -g www-data -a 127.0.0.1 -p 9000 #{RT_SBIN}/#{BIN}"
18
+
19
+ # command to stop RT
20
+ #
21
+ STOP = "kill `#{PID}`"
22
+
23
+ # command to stop RT even if it refuses to stop
24
+ #
25
+ REALLY_STOP = "kill -9 `#{PID}`"
26
+
27
+ # command to check whether RT is running
28
+ #
29
+ RUNNING = "ps -e | awk '$4 ~ /^#{BIN}$/"
30
+
31
+ # command to obtain RT's current RAM usage in bytes
32
+ #
33
+ RAM = "ps -e -o rss,comm | awk '/$2 ~ /^#{BIN}$/ {print $1}'"
34
+
35
+ # the maximum allowed rss size for RT
36
+ #
37
+ MAX_RAM = 128 * 1024 * 1024 # 128MB
38
+
39
+ # number of seconds before timeout
40
+ #
41
+ TIMEOUT = 10
42
+ end
43
+
@@ -0,0 +1,12 @@
1
+ # rt-watchdog - Keep RT running
2
+ start on runlevel [12345]
3
+ stop on runlevel [0]
4
+
5
+ respawn
6
+
7
+ pre-start script
8
+ rm -rf /opt/rt4/var/mason_data/obj
9
+ end script
10
+
11
+ exec rt_watchdog
12
+
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rt_watchdog
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Justin Force
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-19 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! "\n Request Tracker's rt-server.fcgi seems to have a memory leak
15
+ and will\n continue to consume memory indefinitely. The rt_watchdog daemon will\n
16
+ \ monitor the process's memory consumption and whether the process is running\n
17
+ \ and restart or start it if it has hung or crashed.\n "
18
+ email: justin.force@gmail.com
19
+ executables:
20
+ - rt_watchdog
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - lib/rt_watchdog.rb
25
+ - lib/rt_watchdog/daemon.rb
26
+ - lib/upstart/rt_watchdog.conf
27
+ - bin/rt_watchdog
28
+ homepage: https://github.com/sidewaysmilk/rt_watchdog
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>'
44
+ - !ruby/object:Gem::Version
45
+ version: 1.3.1
46
+ requirements:
47
+ - Request Tracker 4
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.15
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Restart the Request Tracker fcgi when it bloats, hangs or crashes
53
+ test_files: []