foreman-upstart-scaling 0.3 → 0.4.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ respawn
4
4
  respawn limit 10 5
5
5
  kill timeout 20
6
6
 
7
- instance $<%= app.upcase %>_<%= process.name.upcase %>_INSTANCE
7
+ instance $INSTANCE
8
8
 
9
9
  env PORT=<%= port %>
10
10
  <% engine.environment.each_pair do |var,value| %>
@@ -12,8 +12,7 @@ env <%= var.upcase %>=<%= value %>
12
12
  <% end %>
13
13
 
14
14
  script
15
- cd <%= engine.directory %>
16
- export name="<%= app %>-<%=process.name%>-$<%= app.upcase %>_<%= process.name.upcase %>_INSTANCE"
15
+ export name="<%= app %>-<%=process.name%>-$INSTANCE"
17
16
 
18
17
  # This little dance pipes output into logger with three
19
18
  # goals in mind:
@@ -32,6 +31,11 @@ script
32
31
  mkfifo $stdout_fifo
33
32
  mkfifo $stderr_fifo
34
33
 
34
+ # Capture our pid so we can pass it to logger to record
35
+ # the pid of the actual job and not the pid of the logger
36
+ # background process.
37
+ job_pid=$$
38
+
35
39
  # Start logger reading from the fifos, in the background.
36
40
  # The parens cause the logger process to be reparented to
37
41
  # init, rather than remaining a child of the current proc.
@@ -41,28 +45,21 @@ script
41
45
  # process group as the main process, they would be killed
42
46
  # by upstart together with the main process, and all output
43
47
  # would be suppressed during termination.
44
- ( exec setsid logger -i -p local0.notice -t $name <$stdout_fifo & )
45
- ( exec setsid logger -i -p local0.err -t $name <$stderr_fifo & )
48
+ ( exec setsid logger -p local0.notice -t "$name[$job_pid]" <$stdout_fifo & )
49
+ ( exec setsid logger -p local0.err -t "$name[$job_pid]" <$stderr_fifo & )
46
50
 
47
51
  # Redirect the current shell's output to the fifos. Now that
48
52
  # we have open fds for those fifos, we don't need the file
49
53
  # system entries any more...
50
54
  exec >$stdout_fifo 2>$stderr_fifo
51
55
 
52
- # ...so we'll remove it.
56
+ # ...so we'll remove them.
53
57
  rm $stdout_fifo
54
58
  rm $stderr_fifo
55
59
 
56
- # store ENV, as `sudo -i` don't preserve it
57
-
58
- envfile=$(mktemp)
59
- echo "PORT=$PORT <%= app.upcase %>_<%= process.name.upcase %>_INSTANCE=$<%= app.upcase %>_<%= process.name.upcase %>_INSTANCE<% engine.environment.each_pair do |var,value| %> <%= var.upcase %>=<%= value %><% end %>" > $envfile
60
- chmod 0700 $envfile
61
- chown <%= user %> $envfile
62
-
63
60
  # Run the service in the usual way. Our output is already
64
61
  # going to the fifos; that won't change when the new
65
62
  # program executes.
66
- exec sudo -u <%= user %> $(envline=$(cat $envfile); rm -f $envfile; echo $envline) -i '<%= process.command %>'
67
- end script
68
63
 
64
+ exec sudo -u <%= user %> PORT=$(( $PORT + $INSTANCE )) <%= process.name.upcase.gsub('-', '_') %>_INSTANCE=$INSTANCE<% engine.environment.each_pair do |var,value| %> <%= var.upcase %>=<%= value %><% end %> -i "<%= process.command %>"
65
+ end script
@@ -3,15 +3,13 @@ start on starting <%= app %>-<%= process.name %>
3
3
  task
4
4
 
5
5
  script
6
- <%= app.upcase %>_<%= process.name.upcase %>_SCALE=$(su - <%= user %> -c 'echo $<%= app.upcase %>_<%= process.name.upcase %>_SCALE')
7
- [ -z $<%= app.upcase %>_<%= process.name.upcase %>_SCALE ] && <%= app.upcase %>_<%= process.name.upcase %>_SCALE=0
8
- export <%= app.upcase %>_<%= process.name.upcase %>_SCALE
6
+ SCALE=$(su - <%= user %> -c 'echo $<%= process.name.upcase.gsub("-", "_") %>_SCALE')
7
+ [ -z $SCALE ] && SCALE=0
8
+ export SCALE
9
9
 
10
10
  i=1
11
- while [ $i -le $<%= app.upcase %>_<%= process.name.upcase %>_SCALE ]; do
12
- start <%= app %>-<%= process.name %>-instance <%= app.upcase %>_<%= process.name.upcase %>_INSTANCE=$i
11
+ while [ $i -le $SCALE ]; do
12
+ start <%= app %>-<%= process.name %>-instance INSTANCE=$i
13
13
  i=$(( $i + 1 ))
14
14
  done
15
-
16
15
  end script
17
-
@@ -32,7 +32,7 @@ class Foreman::Export::UpstartScaling < Foreman::Export::Base
32
32
  process_instances_config = ERB.new(process_instances_template).result(binding)
33
33
  write_file "#{location}/#{app}-#{process.name}-instances.conf", process_instances_config
34
34
 
35
- port = self.port
35
+ port = engine.port_for(process, 1, self.port)
36
36
  process_template = export_template("upstart_scaling", "process.conf.erb", template_root)
37
37
  process_config = ERB.new(process_template).result(binding)
38
38
  write_file "#{location}/#{app}-#{process.name}-instance.conf", process_config
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman-upstart-scaling
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
5
- prerelease:
4
+ version: 0.4.pre
5
+ prerelease: 4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Fabio Kung
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-08 00:00:00.000000000Z
12
+ date: 2012-06-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: foreman
16
- requirement: &70309399709520 !ruby/object:Gem::Requirement
16
+ requirement: &70129330100600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.46.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70309399709520
24
+ version_requirements: *70129330100600
25
25
  description: Upstart exporter for foreman, that supports worker scaling via env vars.
26
26
  email: fabio.kung@gmail.com
27
27
  executables: []
@@ -48,9 +48,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
48
  required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - ! '>'
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: 1.3.1
54
54
  requirements: []
55
55
  rubyforge_project:
56
56
  rubygems_version: 1.8.12