foreman_god 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,7 @@ require 'foreman/engine'
5
5
  require 'thor/core_ext/hash_with_indifferent_access'
6
6
  require 'god'
7
7
  require 'foreman_god'
8
+ require 'etc'
8
9
 
9
10
  module God
10
11
  module Conditions
@@ -47,7 +48,10 @@ module ForemanGod
47
48
  class GodConfig
48
49
  attr_reader :dir_name, :options, :engine
49
50
 
50
- def initialize dir
51
+ # Defaults to the owner of Procfile, but may be overridden with the user option in .foreman
52
+ attr_reader :user_name
53
+
54
+ def initialize dir, override_options={}
51
55
  @dir_name = File.basename(File.absolute_path(dir))
52
56
  if @dir_name == 'current'
53
57
  @dir_name = File.basename(File.dirname(File.absolute_path(dir)))
@@ -57,6 +61,7 @@ module ForemanGod
57
61
  temp_options = {}
58
62
  temp_options = (::YAML::load_file(options_file) || {}) if File.exists? options_file
59
63
  @options = Thor::CoreExt::HashWithIndifferentAccess.new(temp_options)
64
+ @options.merge! override_options
60
65
 
61
66
 
62
67
  @engine = Foreman::Engine.new(@options)
@@ -71,16 +76,15 @@ module ForemanGod
71
76
  end
72
77
 
73
78
  @engine.load_procfile(File.join(dir, "Procfile"))
79
+
80
+ procfile_owner = Etc.getpwuid(File.stat(File.join(dir, "Procfile")).uid).name
81
+ @user_name = @options[:user] || procfile_owner
74
82
  end
75
83
 
76
84
  def app_name
77
85
  @options[:app] || @dir_name
78
86
  end
79
87
 
80
- def user_name
81
- @options[:user]
82
- end
83
-
84
88
  def log_path
85
89
  @options[:log] || 'log'
86
90
  end
@@ -133,7 +137,10 @@ module ForemanGod
133
137
 
134
138
  w.start = wrap_command(process.expanded_command(env))
135
139
 
136
- w.uid = user_name if user_name
140
+ if user_name && (Etc.getlogin != user_name)
141
+ # Only set the uid if the user is different from the current user
142
+ w.uid = user_name
143
+ end
137
144
 
138
145
  # w.gid = ?
139
146
 
@@ -1,3 +1,3 @@
1
1
  module ForemanGod
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -10,7 +10,6 @@ describe GodConfig do
10
10
  it "should load basic properties" do
11
11
  config.dir_name.should == 'simple'
12
12
  config.app_name.should == 'simple'
13
- config.user_name.should == nil
14
13
  config.options.should == {}
15
14
  end
16
15
 
@@ -27,7 +26,8 @@ describe GodConfig do
27
26
  watch.env.should == {'PORT' => '5000'}
28
27
  watch.start.should == 'ruby ../simple_loop.rb -p 5000'
29
28
  watch.log.should == '/dev/null'
30
- watch.uid.should == nil
29
+
30
+ watch.uid.should == nil # The user name is the same as the current user
31
31
 
32
32
  end
33
33
 
@@ -42,11 +42,16 @@ describe GodConfig do
42
42
  end
43
43
  end
44
44
 
45
+ it "should default to using the owner of Procfile as the user" do
46
+ user_name = Etc.getpwuid(File.stat('samples/simple/Procfile').uid).name
47
+ config.user_name.should == user_name
48
+ end
49
+
45
50
  end
46
51
 
47
52
  context "configuration" do
48
- let(:config) { GodConfig.new(sample('configuration')) }
49
53
  let(:user) { Etc.getlogin }
54
+ let(:config) { GodConfig.new(sample('configuration')) }
50
55
 
51
56
  it "should load basic properties" do
52
57
  config.dir_name.should == 'configuration'
@@ -56,7 +61,7 @@ describe GodConfig do
56
61
  end
57
62
 
58
63
  it "should watch" do
59
- config.options["user"] = user # We need to override the user to the current user, otherwise god will fail
64
+ config = GodConfig.new(sample('configuration'), user: user) # we need to override the user here
60
65
 
61
66
  config.watch
62
67
  God.watches.values.count.should == 3
@@ -70,7 +75,10 @@ describe GodConfig do
70
75
  watch.env.should == {'PORT' => '5000', 'MY_VAR' => '12345', 'ANOTHER_VAR' => 'yes'}
71
76
  watch.start.should == 'ruby ../simple_loop.rb -p 5000'
72
77
  watch.log.should == File.absolute_path('samples/configuration/configured-app-loop-1.log')
73
- watch.uid.should == user
78
+
79
+ # We cannot easily test watch.uid in a single-user setup
80
+ pending "Test watch.uid"
81
+ #watch.uid.should == user
74
82
  end
75
83
  end
76
84
 
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-20 00:00:00.000000000 Z
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: foreman