foreman_god 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +47 -1
- data/foreman_god.gemspec +4 -4
- data/lib/foreman_god/god_config.rb +41 -3
- data/lib/foreman_god/version.rb +1 -1
- data/samples/rvm/.foreman +7 -0
- data/samples/rvm/Procfile +1 -0
- data/samples/rvm/rvm.god +3 -0
- data/samples/simple_loop.rb +1 -0
- data/spec/god_config_spec.rb +5 -0
- data/spec/spec_helper.rb +1 -0
- metadata +12 -9
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# ForemanGod
|
2
2
|
|
3
|
-
|
3
|
+
Monitor Procfiles with [God](http://godrb.com/).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
+
Install the gem on the machine running god - there is no need to include it as a dependency in your project.
|
8
|
+
|
7
9
|
$ gem install foreman_god
|
8
10
|
|
9
11
|
## Usage
|
@@ -24,6 +26,50 @@ To specify foreman options, add a .foreman file next to the Procfile.
|
|
24
26
|
|
25
27
|
See samples/configuration for a complete example.
|
26
28
|
|
29
|
+
### Restarting workers
|
30
|
+
|
31
|
+
If present, the `tmp/restart.txt` file in your project is watched for changes. If this file is modified, for example
|
32
|
+
with `touch tmp/restart.txt`, all workers are restarted.
|
33
|
+
|
34
|
+
### Reloading the Procfile
|
35
|
+
|
36
|
+
When the Procfile (or .env or .foreman files) changed, use `god load <god config> stop` to reload the config files.
|
37
|
+
The `stop` action tells god to stop any processes that were removed from the Procfile (available since god 0.12.0,
|
38
|
+
but not documented at the time of writing).
|
39
|
+
|
40
|
+
### RVM
|
41
|
+
|
42
|
+
To run god itself with RVM, use a wrapper script as explained at [https://rvm.io/integration/god/](https://rvm.io/integration/god/).
|
43
|
+
|
44
|
+
Using RVM is tricky when running God as root. Often you would want to run the commands in a different environment from
|
45
|
+
god (different user, different Ruby, different gems, etc).
|
46
|
+
|
47
|
+
The simplest way to tell ForemanGod to run your processes with RVM, is to specify `rvm: default` in your .foreman config
|
48
|
+
file. This tells ForemanGod to use the "default" Ruby version to run the script. Alternatively you can specify a
|
49
|
+
specific ruby version or gemset, for example `rvm: ruby-1.9.3-p194` or `rvm: ruby-1.9.3-p194@global`.
|
50
|
+
|
51
|
+
Technically this loads the environment for the ruby/gemset version, which is found in either `~/.rvm/environments/<version>`
|
52
|
+
or `/usr/local/rvm/<version>`. This is similar to the approach for [Cron scripts](https://rvm.io/integration/cron/).
|
53
|
+
|
54
|
+
### Capistrano
|
55
|
+
|
56
|
+
On each deployment, God needs to reload the configuration. Restarting of the processes happen with the `tmp/restart.txt`
|
57
|
+
solution explained earlier, which you already do if you're using Passenger.
|
58
|
+
|
59
|
+
Use a task like the following to reload the configuration (see *Reloading the Procfile* above):
|
60
|
+
|
61
|
+
namespace :god do
|
62
|
+
task :reload do
|
63
|
+
# Replace the god command and config file here with the ones used on your server
|
64
|
+
run("god load /etc/god/master.god stop")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
before "deploy:restart", "god:reload"
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
27
73
|
## Contributing
|
28
74
|
|
29
75
|
1. Fork it
|
data/foreman_god.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = ForemanGod::VERSION
|
9
9
|
gem.authors = ["Ralf Kistner"]
|
10
10
|
gem.email = ["ralf@embarkmobile.com"]
|
11
|
-
gem.description = %q{God
|
12
|
-
gem.summary = %q{
|
11
|
+
gem.description = %q{Monitor Procfiles with God. Mostly compatible with foreman.}
|
12
|
+
gem.summary = %q{Monitor Procfiles with God}
|
13
13
|
gem.homepage = ""
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
@@ -17,6 +17,6 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency 'foreman'
|
21
|
-
gem.add_dependency 'god'
|
20
|
+
gem.add_dependency 'foreman', '~> 0.60.2'
|
21
|
+
gem.add_dependency 'god', '>= 0.12.0'
|
22
22
|
end
|
@@ -17,7 +17,7 @@ module God
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def process_start_time
|
20
|
-
Time.parse(`ps -o lstart= -p #{self.watch.pid}`)
|
20
|
+
Time.parse(`ps -o lstart= -p #{self.watch.pid}`) rescue nil
|
21
21
|
end
|
22
22
|
|
23
23
|
def restart_file_modification_time
|
@@ -31,7 +31,12 @@ module God
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def test
|
34
|
-
|
34
|
+
ptime = process_start_time
|
35
|
+
if ptime
|
36
|
+
process_start_time < restart_file_modification_time
|
37
|
+
else
|
38
|
+
false
|
39
|
+
end
|
35
40
|
end
|
36
41
|
end
|
37
42
|
end
|
@@ -44,6 +49,9 @@ module ForemanGod
|
|
44
49
|
|
45
50
|
def initialize dir
|
46
51
|
@dir_name = File.basename(File.absolute_path(dir))
|
52
|
+
if @dir_name == 'current'
|
53
|
+
@dir_name = File.basename(File.dirname(File.absolute_path(dir)))
|
54
|
+
end
|
47
55
|
|
48
56
|
options_file = File.join(dir, ".foreman")
|
49
57
|
temp_options = {}
|
@@ -77,6 +85,34 @@ module ForemanGod
|
|
77
85
|
@options[:log] || 'log'
|
78
86
|
end
|
79
87
|
|
88
|
+
|
89
|
+
def wrap_command(cmd)
|
90
|
+
if user_name
|
91
|
+
user_home = File.join('/home', user_name)
|
92
|
+
else
|
93
|
+
user_home = Dir.home
|
94
|
+
end
|
95
|
+
local_rvm_version = @options[:user_rvm]
|
96
|
+
system_rvm_version = @options[:system_rvm]
|
97
|
+
auto_rvm = @options[:rvm]
|
98
|
+
if auto_rvm
|
99
|
+
if File.directory? File.join(user_home, '.rvm', 'environments')
|
100
|
+
local_rvm_version = auto_rvm
|
101
|
+
elsif File.directory? '/usr/local/rvm/environments'
|
102
|
+
system_rvm_version = auto_rvm
|
103
|
+
end
|
104
|
+
end
|
105
|
+
if local_rvm_version
|
106
|
+
rvm_env = File.join(user_home, '.rvm', 'environments', local_rvm_version)
|
107
|
+
". #{rvm_env} && exec #{cmd}"
|
108
|
+
elsif system_rvm_version
|
109
|
+
rvm_env = File.join('/usr/local/rvm/environments', system_rvm_version)
|
110
|
+
". #{rvm_env} && exec #{cmd}"
|
111
|
+
else
|
112
|
+
cmd
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
80
116
|
def watch_process(name, process, n)
|
81
117
|
port = @engine.port_for(process, n)
|
82
118
|
base_env = process.instance_variable_get(:@options)[:env]
|
@@ -88,7 +124,6 @@ module ForemanGod
|
|
88
124
|
w.group = app_name
|
89
125
|
w.interval = 60.seconds
|
90
126
|
w.env = env
|
91
|
-
w.start = process.expanded_command(env)
|
92
127
|
log = File.expand_path(log_path, process.cwd)
|
93
128
|
if File.directory? log
|
94
129
|
w.log = File.join(log, "#{app_name}-#{name}-#{n}.log")
|
@@ -96,7 +131,10 @@ module ForemanGod
|
|
96
131
|
LOG.warn "Log path does not exist: #{log}"
|
97
132
|
end
|
98
133
|
|
134
|
+
w.start = wrap_command(process.expanded_command(env))
|
135
|
+
|
99
136
|
w.uid = user_name if user_name
|
137
|
+
|
100
138
|
# w.gid = ?
|
101
139
|
|
102
140
|
w.transition(:up, :restart) do |on|
|
data/lib/foreman_god/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
loop: bundle exec ruby ../simple_loop.rb
|
data/samples/rvm/rvm.god
ADDED
data/samples/simple_loop.rb
CHANGED
data/spec/god_config_spec.rb
CHANGED
@@ -80,4 +80,9 @@ describe GodConfig do
|
|
80
80
|
God.watches.values.count.should == 1
|
81
81
|
end
|
82
82
|
|
83
|
+
it "should not use 'current' for the app name" do
|
84
|
+
FileUtils.mkdir_p 'spec/tmp/test/current'
|
85
|
+
FileUtils.touch 'spec/tmp/test/current/Procfile'
|
86
|
+
GodConfig.new('spec/tmp/test/current').app_name.should == 'test'
|
87
|
+
end
|
83
88
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_god
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -16,17 +16,17 @@ dependencies:
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 0.60.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 0.60.2
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: god
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 0.12.0
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,8 +42,8 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
46
|
-
description: God
|
45
|
+
version: 0.12.0
|
46
|
+
description: Monitor Procfiles with God. Mostly compatible with foreman.
|
47
47
|
email:
|
48
48
|
- ralf@embarkmobile.com
|
49
49
|
executables: []
|
@@ -64,6 +64,9 @@ files:
|
|
64
64
|
- samples/configuration/.env
|
65
65
|
- samples/configuration/.foreman
|
66
66
|
- samples/configuration/Procfile
|
67
|
+
- samples/rvm/.foreman
|
68
|
+
- samples/rvm/Procfile
|
69
|
+
- samples/rvm/rvm.god
|
67
70
|
- samples/simple/Procfile
|
68
71
|
- samples/simple_loop.rb
|
69
72
|
- spec/god_config_spec.rb
|
@@ -96,7 +99,7 @@ rubyforge_project:
|
|
96
99
|
rubygems_version: 1.8.24
|
97
100
|
signing_key:
|
98
101
|
specification_version: 3
|
99
|
-
summary:
|
102
|
+
summary: Monitor Procfiles with God
|
100
103
|
test_files:
|
101
104
|
- spec/god_config_spec.rb
|
102
105
|
- spec/integration_spec.rb
|