procodile 1.0.14 → 1.0.15

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: 52606401641f665e09ce9beae6a752e70e3a680a
4
- data.tar.gz: 052b223485baa0c66d5f67a3ff52afb9ed5a4ed4
3
+ metadata.gz: b2df02f31fea5565a5b982cd4d1ae98b53e6256d
4
+ data.tar.gz: a758543c9bb33dbe1f5520c0d38ad9c128cb1255
5
5
  SHA512:
6
- metadata.gz: 9c97e8abbcade5ed3e51553ff97a0b658f69a326e4afc84029070e288b5882ea8b4b2d5c6e22bcfae15afd31c2305ac30a353a5c20e39849be41ddeafbf40fbb
7
- data.tar.gz: eae3e1a71001a027ab132e5797a59c1b78e383bd6aac1f68dfe8ccba7b33afe81db7efc5ed8bf09212a7606d82fade99da6afb54f5e062eb480d75aad9cb8762
6
+ metadata.gz: f2ef597c33f6475992e64d577b543d50b4b70da16e634afd61a3a74339cdca4b1cdb20f7ba2bf8ca79939a1b5e0d1d132d0f61ccd4b08f4ae41c528377f7dc81
7
+ data.tar.gz: f6bdaa3e8caccccb8a6761536f5f8e77ad7911fd4f0b63f5bb0f318228c29ceec671011622816a4573be0c67411585167dbacfe541d2721a41bad75b95f3bd39
@@ -29,10 +29,6 @@ begin
29
29
  options[:root] = root
30
30
  end
31
31
 
32
- opts.on("-e", "--environment NAME", "The config environment to use") do |name|
33
- options[:environment] = name
34
- end
35
-
36
32
  opts.on("--procfile PATH", "The path to the Procfile (defaults to: Procfile)") do |path|
37
33
  options[:procfile] = path
38
34
  end
@@ -57,7 +53,7 @@ end
57
53
 
58
54
  # Create a determination to work out where we want to load our app from
59
55
  require 'procodile/app_determination'
60
- ap = Procodile::AppDetermination.new(FileUtils.pwd, options[:root], options[:procfile], options[:environment], global_config)
56
+ ap = Procodile::AppDetermination.new(FileUtils.pwd, options[:root], options[:procfile], global_config)
61
57
  if ap.ambiguous?
62
58
  if ENV['PROCODILE_APP_ID']
63
59
  ap.set_app(ENV['PROCODILE_APP_ID'].to_i)
@@ -85,20 +81,15 @@ if ap.ambiguous?
85
81
  end
86
82
  end
87
83
 
88
- if ap.user && ENV['USER'] != ap.user
89
- if global_config['user_reexec']
90
- $stderr.puts "\e[31mProcodile must be run as #{ap.user}. Re-executing as #{ap.user}...\e[0m"
91
- exec("sudo -E -u #{ap.user} -- #{$0} #{ORIGINAL_ARGV}")
92
- else
93
- $stderr.puts "\e[31mError: Procodile must be run as #{ap.user}\e[0m"
94
- exit 1
95
- end
96
- end
97
-
98
84
  begin
99
85
  if command != 'help'
100
- cli.config = Procodile::Config.new(ap.root, ap.environment, ap.procfile)
86
+ cli.config = Procodile::Config.new(ap.root, ap.procfile)
87
+ if cli.config.user && ENV['USER'] != cli.config.user
88
+ $stderr.puts "\e[31mProcodile must be run as #{cli.config.user}. Re-executing as #{cli.config.user}...\e[0m"
89
+ exec("sudo -H -u #{cli.config.user} -- #{$0} #{ORIGINAL_ARGV}")
90
+ end
101
91
  end
92
+
102
93
  cli.dispatch(command)
103
94
  rescue Procodile::Error => e
104
95
  $stderr.puts "Error: #{e.message}".color(31)
@@ -1,26 +1,20 @@
1
1
  module Procodile
2
2
  #
3
- # This class is responsible for determining which application should be
3
+ # This class is responsible for determining which application should be
4
4
  # sued
5
5
  #
6
6
  class AppDetermination
7
7
 
8
8
  # Start by creating an determination ased on the root and procfile that has been provided
9
9
  # to us by the user (from --root and/or --procfile)
10
- def initialize(pwd, given_root, given_procfile, given_environment, global_options = {})
10
+ def initialize(pwd, given_root, given_procfile, global_options = {})
11
11
  @pwd = pwd
12
- @given_root = given_root
12
+ @given_root = given_root ? File.expand_path(given_root, pwd) : nil
13
13
  @given_procfile = given_procfile
14
- @given_environment = given_environment
15
14
  @global_options = global_options
16
15
  calculate
17
16
  end
18
17
 
19
- # Return the environment
20
- def environment
21
- @given_environment || @environment || 'production'
22
- end
23
-
24
18
  # Return the root directory
25
19
  def root
26
20
  @root
@@ -31,16 +25,6 @@ module Procodile
31
25
  @procfile
32
26
  end
33
27
 
34
- # Return the user that we must be executing as if not current user
35
- def user
36
- @user
37
- end
38
-
39
- # Should this be reexeced
40
- def reexec?
41
- @reexec == true
42
- end
43
-
44
28
  # Are we in an app's directory?
45
29
  def in_app_directory?
46
30
  @in_app_directory == true
@@ -65,7 +49,9 @@ module Procodile
65
49
  def app_options
66
50
  if ambiguous?
67
51
  hash = {}
68
- @global_options.each_with_index { |option, i| hash[i] = option['name'] || option['root'] }
52
+ @global_options.each_with_index do |option, i|
53
+ hash[i] = option['name'] || option['root']
54
+ end
69
55
  hash
70
56
  else
71
57
  {}
@@ -80,11 +66,6 @@ module Procodile
80
66
  if ambiguous?
81
67
  # Otherwise, try and use the global config we have been given
82
68
  find_root_and_procfile_from_options(@global_options)
83
- else
84
- # Try to load additional global details on to the existing app
85
- if @root && options = global_options_for_path(@root)
86
- add_global_options(options)
87
- end
88
69
  end
89
70
  end
90
71
 
@@ -119,7 +100,6 @@ module Procodile
119
100
  if options.is_a?(Hash)
120
101
  # Use the current hash
121
102
  find_root_and_procfile(@pwd, options['root'], options['procfile'])
122
- add_global_options(options)
123
103
  elsif options.is_a?(Array)
124
104
  # Global options is provides a list of apps. We need to know which one of
125
105
  # these we should be looking at.
@@ -129,23 +109,6 @@ module Procodile
129
109
  end
130
110
  end
131
111
 
132
- def global_options_for_path(root)
133
- root = expand_path(root)
134
- if @global_options.is_a?(Hash) && @global_options['root'] && expand_path(@global_options['root']) == root
135
- @global_options
136
- elsif @global_options.is_a?(Array) && option = @global_options.select { |o| o['root'] && expand_path(o['root']) == root }.first
137
- option
138
- else
139
- nil
140
- end
141
- end
142
-
143
- def add_global_options(options)
144
- @user = options['user'] if options['user']
145
- @reexec = options['user_reexec'] if options['user_reexec']
146
- @environment = options['environment'] if options['environment']
147
- end
148
-
149
112
  def expand_path(path, root = nil)
150
113
  # Remove trailing slashes for normalization
151
114
  path = path.gsub(/\/\z/, '')
@@ -8,12 +8,8 @@ module Procodile
8
8
 
9
9
  COLORS = [35, 31, 36, 32, 33, 34]
10
10
 
11
- attr_reader :root
12
- attr_reader :environment
13
-
14
- def initialize(root, environment = nil, procfile = nil)
11
+ def initialize(root, procfile = nil)
15
12
  @root = root
16
- @environment = environment || 'production'
17
13
  @procfile_path = procfile
18
14
  unless File.file?(procfile_path)
19
15
  raise Error, "Procfile not found at #{procfile_path}"
@@ -59,12 +55,20 @@ module Procodile
59
55
  end
60
56
  end
61
57
 
58
+ def root
59
+ local_options['root'] || options['root'] || @root
60
+ end
61
+
62
+ def user
63
+ local_options['user'] || options['user']
64
+ end
65
+
62
66
  def app_name
63
- @app_name ||= fetch(local_options['app_name']) || fetch(options['app_name']) || 'Procodile'
67
+ @app_name ||= local_options['app_name'] || options['app_name'] || 'Procodile'
64
68
  end
65
69
 
66
70
  def console_command
67
- fetch(local_options['console_command']) || fetch(options['console_command'])
71
+ local_options['console_command'] || options['console_command']
68
72
  end
69
73
 
70
74
  def processes
@@ -96,11 +100,11 @@ module Procodile
96
100
  end
97
101
 
98
102
  def environment_variables
99
- fetch_hash_values(options['env'] || {}).merge(fetch_hash_values(local_options['env'] || {}))
103
+ (options['env'] || {}).merge(local_options['env'] || {})
100
104
  end
101
105
 
102
106
  def pid_root
103
- @pid_root ||= File.expand_path(fetch(local_options['pid_root']) || fetch(options['pid_root']) || 'pids', @root)
107
+ @pid_root ||= File.expand_path(local_options['pid_root'] || options['pid_root'] || 'pids', self.root)
104
108
  end
105
109
 
106
110
  def supervisor_pid_path
@@ -108,19 +112,19 @@ module Procodile
108
112
  end
109
113
 
110
114
  def log_path
111
- log_path = fetch(local_options['log_path']) || fetch(options['log_path'])
115
+ log_path = local_options['log_path'] || options['log_path']
112
116
  if log_path
113
- File.expand_path(log_path, @root)
117
+ File.expand_path(log_path, self.root)
114
118
  elsif log_path.nil? && self.log_root
115
119
  File.join(self.log_root, 'procodile.log')
116
120
  else
117
- File.expand_path("procodile.log", @root)
121
+ File.expand_path("procodile.log", self.root)
118
122
  end
119
123
  end
120
124
 
121
125
  def log_root
122
- if log_root = (fetch(local_options['log_root']) || fetch(options['log_root']))
123
- File.expand_path(log_root, @root)
126
+ if log_root = (local_options['log_root'] || options['log_root'])
127
+ File.expand_path(log_root, self.root)
124
128
  else
125
129
  nil
126
130
  end
@@ -150,26 +154,6 @@ module Procodile
150
154
  process
151
155
  end
152
156
 
153
- def fetch(value, default = nil)
154
- if value.is_a?(Hash)
155
- if value.has_key?(@environment)
156
- value[@environment]
157
- else
158
- default
159
- end
160
- else
161
- value.nil? ? default : value
162
- end
163
- end
164
-
165
- def fetch_hash_values(hash)
166
- hash.each_with_object({}) do |(key, value), h|
167
- if value = fetch(value)
168
- h[key] = value
169
- end
170
- end
171
- end
172
-
173
157
  def load_process_list_from_file
174
158
  YAML.load_file(procfile_path)
175
159
  end
@@ -72,7 +72,6 @@ module Procodile
72
72
  :version => Procodile::VERSION,
73
73
  :messages => @supervisor.messages,
74
74
  :root => @supervisor.config.root,
75
- :environment => @supervisor.config.environment,
76
75
  :app_name => @supervisor.config.app_name,
77
76
  :supervisor => @supervisor.to_hash,
78
77
  :instances => instances,
@@ -15,7 +15,6 @@ module Procodile
15
15
  def print_header
16
16
  puts "Procodile Version " + @status['version'].to_s.color(34)
17
17
  puts "Application Root " + "#{@status['root']}".color(34)
18
- puts "Environment " + "#{@status['environment']}".color(34)
19
18
  puts "Supervisor PID " + "#{@status['supervisor']['pid']}".color(34)
20
19
  if time = @status['supervisor']['started_at']
21
20
  time = Time.at(time)
@@ -30,7 +30,7 @@ module Procodile
30
30
 
31
31
  def start(&after_start)
32
32
  Procodile.log nil, "system", "Procodile supervisor started with PID #{::Process.pid}"
33
- Procodile.log nil, "system", "Environment is #{@config.environment}"
33
+ Procodile.log nil, "system", "Application root is #{@config.root}"
34
34
  if @run_options[:respawn] == false
35
35
  Procodile.log nil, "system", "Automatic respawning is disabled"
36
36
  end
@@ -1,3 +1,3 @@
1
1
  module Procodile
2
- VERSION = '1.0.14'
2
+ VERSION = '1.0.15'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procodile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.14
4
+ version: 1.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-27 00:00:00.000000000 Z
11
+ date: 2017-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -70,9 +70,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  requirements: []
72
72
  rubyforge_project:
73
- rubygems_version: 2.5.1
73
+ rubygems_version: 2.5.2
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: This gem will help you run Ruby processes from a Procfile on Linux servers
77
77
  in the background.
78
78
  test_files: []
79
+ has_rdoc: