capelinhos 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +4 -0
- data/capelinhos.sublime-project +15 -0
- data/exe/capelinhos.rb +52 -0
- data/lib/capelinhos/processor.rb +23 -0
- data/lib/capelinhos/version.rb +5 -0
- data/lib/capelinhos.rb +8 -0
- data/sig/capelinhos.rbs +4 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d58321305d7a195ade76ea1869ab3348347d455e131f2c9fd0497b5b53f497c5
|
4
|
+
data.tar.gz: 86535d3c19297bb86d0c2d8ca218b70a77ede25eafe5c5404be938856c0cef26
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d23b6a9c43660a5f3208aa356398905a61198e4e9feb79ac45d7c894013091a8cc02e0fd17228224d40edace7374ce41c70ff029f25e1f8a5194b363aeac7235
|
7
|
+
data.tar.gz: 2a2cba2f982977c3b64afa29bd8ce17473da540bb81a2dba1cacb33390a66d6992e1a661a0b18fab853f0e7602e77785e8f68fe71416835223a2c7d825517b56
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Adam Hallett
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Capelinhos
|
2
|
+
|
3
|
+
This gem gracefully stops Passenger Ruby processes that have exceeded a memory threshold. It is meant to be added to cron and run at an interval of your choosing.
|
4
|
+
|
5
|
+
If Phusion Passenger is configured with `PassengerMinInstances` and the number of processes is under that number, then a new process should replace the processes that were shutdown.
|
6
|
+
|
7
|
+
Note: This doesn't skip active long running sessions. This feature be added as a default in the future.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add capelinhos
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install capelinhos
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
# kill up to 3 processes that use more than 400 megabytes
|
22
|
+
$ capelinos --max-memory 400 --max-processes 3
|
23
|
+
|
24
|
+
## Development
|
25
|
+
|
26
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
27
|
+
|
28
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/capelinhos.
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/exe/capelinhos.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'optparse'
|
6
|
+
require 'capelinhos'
|
7
|
+
|
8
|
+
source_root = File.expand_path("..", File.dirname(__FILE__))
|
9
|
+
$LOAD_PATH.unshift("#{source_root}/src/ruby_supportlib")
|
10
|
+
begin
|
11
|
+
require 'rubygems'
|
12
|
+
rescue LoadError
|
13
|
+
end
|
14
|
+
require 'phusion_passenger'
|
15
|
+
|
16
|
+
PhusionPassenger.locate_directories
|
17
|
+
PhusionPassenger.require_passenger_lib 'platform_info'
|
18
|
+
PhusionPassenger.require_passenger_lib 'platform_info/ruby'
|
19
|
+
PhusionPassenger.require_passenger_lib 'admin_tools/memory_stats'
|
20
|
+
include PhusionPassenger
|
21
|
+
|
22
|
+
options = {}
|
23
|
+
OptionParser.new do |opts|
|
24
|
+
opts.banner = "Usage: capelinhos --max-memory 320 --max-processes 3"
|
25
|
+
|
26
|
+
opts.on("--max-memory", "--max-memory MAX_MEMORY", Numeric, "Maximum memory in megabytes to trigger shutdown.") do |n|
|
27
|
+
options[:max_memory] = n
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on("--max-processes", "--max-processes=NUMBER", Numeric, "Maximum number of processes to gracefully shutdown.") do |n|
|
31
|
+
options[:max_processes] = n
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("-h", "--help", "Prints this help") do
|
35
|
+
puts opts
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
end.parse!
|
39
|
+
|
40
|
+
if !options[:max_memory]
|
41
|
+
puts "--max-memory is required"
|
42
|
+
exit(0)
|
43
|
+
end
|
44
|
+
|
45
|
+
if !options[:max_processes]
|
46
|
+
puts "--max-processes is required"
|
47
|
+
exit(0)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
Capelinhos::Processor.kill_memory_hogs!(memory_threshold: options[:max_memory],
|
52
|
+
process_limit: options[:max_processes])
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Capelinhos
|
2
|
+
class Processor
|
3
|
+
def self.kill_memory_hogs!(memory_threshold:, process_limit:)
|
4
|
+
processes_killed = 0
|
5
|
+
stats = AdminTools::MemoryStats.new
|
6
|
+
processes = stats.passenger_processes
|
7
|
+
|
8
|
+
processes.each do |process|
|
9
|
+
if process.name.include?('RubyApp')
|
10
|
+
rss_megabytes = process.rss / 1024
|
11
|
+
if rss_megabytes > memory_threshold
|
12
|
+
Process.kill('USR1', process.pid)
|
13
|
+
processes_killed += 1
|
14
|
+
end
|
15
|
+
|
16
|
+
if processes_killed >= process_limit
|
17
|
+
break
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/capelinhos.rb
ADDED
data/sig/capelinhos.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capelinhos
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Hallett
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: passenger
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- adam.t.hallett@gmail.com
|
44
|
+
executables:
|
45
|
+
- capelinhos.rb
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- CHANGELOG.md
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- capelinhos.sublime-project
|
54
|
+
- exe/capelinhos.rb
|
55
|
+
- lib/capelinhos.rb
|
56
|
+
- lib/capelinhos/processor.rb
|
57
|
+
- lib/capelinhos/version.rb
|
58
|
+
- sig/capelinhos.rbs
|
59
|
+
homepage: https://github.com/atomical/capelinhos
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata:
|
63
|
+
homepage_uri: https://github.com/atomical/capelinhos
|
64
|
+
source_code_uri: https://github.com/atomical/capelinhos
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 3.0.0
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubygems_version: 3.3.7
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Gracefully shutdown Phusion Passenger Ruby processes when they exceed specified
|
84
|
+
memory usage.
|
85
|
+
test_files: []
|