foreman_maintain 0.0.11 → 0.1.0
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aba1f4178b0ced3fb12c5107f5dc6b0b160fc9ff
|
4
|
+
data.tar.gz: 1caeb8621f21079907611b38310980d3697b4b08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 231e7d4e8697b04cb0117607fbb2e70537aca9a9a83bb24c6fb7e5f985018821af9a4b3b215d829e87fde012a185489b6b16e1a2a81a7a7ec81837cf59d27dac
|
7
|
+
data.tar.gz: a61285f8c9e2546f79e6b004e110db24b8984c93243417dca97b52c5e12928845ed07325f1f316b2ca7dd6c426d9da93ea1f884a59449783dc7cd6b794c682a0
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Trivial Passenger memory monitor and recycler. See the configuration file
|
4
|
+
# /etc/passenger-recycler.yaml for options. Execute via SCL.
|
5
|
+
#
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
CONFIG = {}.freeze
|
9
|
+
CONFIG_FILE = '/etc/passenger-recycler.yaml'.freeze
|
10
|
+
CONFIG = YAML.load_file(CONFIG_FILE) if File.readable?(CONFIG_FILE)
|
11
|
+
exit 0 unless CONFIG[:ENABLED]
|
12
|
+
|
13
|
+
def running?(pid)
|
14
|
+
return Process.getpgid(pid) != -1
|
15
|
+
rescue Errno::ESRCH
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
|
19
|
+
def debug(msg)
|
20
|
+
puts(msg) if CONFIG[:DEBUG]
|
21
|
+
end
|
22
|
+
|
23
|
+
def verbose(msg)
|
24
|
+
puts(msg) if CONFIG[:VERBOSE]
|
25
|
+
end
|
26
|
+
|
27
|
+
def kill(pid)
|
28
|
+
if running?(pid) && CONFIG[:KILL_BUSY]
|
29
|
+
verbose "Process #{pid} is still running, sending SIGKILL"
|
30
|
+
Process.kill 'KILL', pid
|
31
|
+
sleep 5
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def process_status?(pid)
|
36
|
+
if running?(pid)
|
37
|
+
verbose "Process #{pid} still terminating, moving on..."
|
38
|
+
else
|
39
|
+
verbose "Process successfully #{pid} terminated"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
require 'phusion_passenger'
|
44
|
+
require 'phusion_passenger/platform_info'
|
45
|
+
require 'phusion_passenger/platform_info/ruby'
|
46
|
+
require 'phusion_passenger/admin_tools/memory_stats'
|
47
|
+
PhusionPassenger.locate_directories
|
48
|
+
stats = PhusionPassenger::AdminTools::MemoryStats.new
|
49
|
+
unless stats.platform_provides_private_dirty_rss_information?
|
50
|
+
puts 'Please run as root or platform unsupported'
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
killed = 0
|
54
|
+
stats.passenger_processes.each do |p|
|
55
|
+
pid = p.pid.to_i
|
56
|
+
debug "Checking #{pid} with RSS of #{p.private_dirty_rss}"
|
57
|
+
next unless p.private_dirty_rss > CONFIG[:MAX_PRIV_RSS_MEMORY]
|
58
|
+
started = begin
|
59
|
+
`ps -p#{pid} -o start=`.strip
|
60
|
+
rescue StandardError => e
|
61
|
+
verbose "Error: #{e.message} \nReturning '?'"
|
62
|
+
'?'
|
63
|
+
end
|
64
|
+
status_ps = `ps -p#{pid} -u`
|
65
|
+
status_all = `passenger-status 2> /dev/null`
|
66
|
+
status_backtraces = `passenger-status --show=backtraces 2>/dev/null`
|
67
|
+
verbose "Terminating #{pid} (started #{started}) with private dirty RSS" \
|
68
|
+
" size of #{p.private_dirty_rss} MB"
|
69
|
+
Process.kill 'SIGUSR1', pid
|
70
|
+
sleep CONFIG[:GRACEFUL_SHUTDOWN_SLEEP]
|
71
|
+
kill(pid)
|
72
|
+
process_status?(pid)
|
73
|
+
if CONFIG[:SEND_STATUS]
|
74
|
+
verbose status_ps
|
75
|
+
verbose status_all
|
76
|
+
verbose status_backtraces
|
77
|
+
end
|
78
|
+
killed += 1
|
79
|
+
exit(1) if killed >= CONFIG[:MAX_TERMINATION]
|
80
|
+
end
|
81
|
+
exit 0
|
@@ -26,12 +26,16 @@ class Features::ForemanProxy < ForemanMaintain::Feature
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def find_http_error_msg(array_output, curl_http_status)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
http_line =
|
29
|
+
if curl_http_status == 0
|
30
|
+
'No valid HTTP response (Connection failed)'
|
31
|
+
else
|
32
|
+
http_line = ''
|
33
|
+
array_output.each do |str|
|
34
|
+
next unless str.include?('HTTP')
|
35
|
+
http_line = str
|
36
|
+
end
|
37
|
+
http_line.split(curl_http_status.to_s).last.strip
|
33
38
|
end
|
34
|
-
http_line.split(curl_http_status.to_s).last.strip
|
35
39
|
end
|
36
40
|
|
37
41
|
def run_dhcp_curl
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Procedures::PassengerRecycler < ForemanMaintain::Procedure
|
2
|
+
metadata do
|
3
|
+
description 'Perform Passenger memory recycling'
|
4
|
+
|
5
|
+
confine do
|
6
|
+
execute?('which scl') && execute?('which passenger-recycler')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
execute!('scl enable tfm -- ruby passenger-recycler')
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_maintain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- LICENSE
|
108
108
|
- README.md
|
109
109
|
- bin/foreman-maintain
|
110
|
+
- bin/passenger-recycler
|
110
111
|
- config/foreman_maintain.yml.example
|
111
112
|
- config/foreman_maintain.yml.packaging
|
112
113
|
- definitions/checks/disk_speed_minimal.rb
|
@@ -143,6 +144,7 @@ files:
|
|
143
144
|
- definitions/procedures/maintenance_mode/enable.rb
|
144
145
|
- definitions/procedures/packages/install.rb
|
145
146
|
- definitions/procedures/packages/update.rb
|
147
|
+
- definitions/procedures/passenger_recycler.rb
|
146
148
|
- definitions/procedures/repositories/setup.rb
|
147
149
|
- definitions/procedures/sync_plans/disable.rb
|
148
150
|
- definitions/procedures/sync_plans/enable.rb
|