foreman-upstart-scaling 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/data/export/upstart_scaling/master.conf.erb +4 -0
- data/data/export/upstart_scaling/process.conf.erb +62 -0
- data/data/export/upstart_scaling/process_instances.conf.erb +17 -0
- data/data/export/upstart_scaling/process_master.conf.erb +3 -0
- data/lib/foreman/export/upstart_scaling.rb +42 -0
- metadata +60 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
stop on stopping <%= app %>-<%= process.name %>
|
2
|
+
|
3
|
+
respawn
|
4
|
+
respawn limit 10 5
|
5
|
+
kill timeout 20
|
6
|
+
|
7
|
+
instance $<%= app.upcase %>_<%= process.name.upcase %>_INSTANCE
|
8
|
+
|
9
|
+
# TODO sudo overwrites this those env vars
|
10
|
+
env PORT=<%= port %>
|
11
|
+
<% engine.environment.each_pair do |var,value| %>
|
12
|
+
env <%= var.upcase %>=<%= value %>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
script
|
16
|
+
cd <%= engine.directory %>
|
17
|
+
name="<%= app %>-<%=process.name%>-$<%= app.upcase %>_<%= process.name.upcase %>_INSTANCE"
|
18
|
+
|
19
|
+
# This little dance pipes output into logger with three
|
20
|
+
# goals in mind:
|
21
|
+
# - Keep the process as a direct child of init (so upstart
|
22
|
+
# doesn't get confused).
|
23
|
+
# - Make sure logger isn't a child of the process (so it
|
24
|
+
# doesn't get confused).
|
25
|
+
# - Don't leave cruft sitting around in the filesystem.
|
26
|
+
|
27
|
+
# See `man 7 fifo` and `man 7 pipe` for more info.
|
28
|
+
mkdir -p <%= log_root %>
|
29
|
+
stdout_fifo="<%= log_root %>/$name-stdout-log.fifo"
|
30
|
+
stderr_fifo="<%= log_root %>/$name-stderr-log.fifo"
|
31
|
+
rm -f $stdout_fifo
|
32
|
+
rm -f $stderr_fifo
|
33
|
+
mkfifo $stdout_fifo
|
34
|
+
mkfifo $stderr_fifo
|
35
|
+
|
36
|
+
# Start logger reading from the fifos, in the background.
|
37
|
+
# The parens cause the logger process to be reparented to
|
38
|
+
# init, rather than remaining a child of the current proc.
|
39
|
+
#
|
40
|
+
# `setsid` will cause loggers to be in a different session
|
41
|
+
# and process group. If we let the loggers be in the same
|
42
|
+
# process group as the main process, they would be killed
|
43
|
+
# by upstart together with the main process, and all output
|
44
|
+
# would be suppressed during termination.
|
45
|
+
( exec setsid logger -i -p local0.notice -t $name <$stdout_fifo & )
|
46
|
+
( exec setsid logger -i -p local0.err -t $name <$stderr_fifo & )
|
47
|
+
|
48
|
+
# Redirect the current shell's output to the fifos. Now that
|
49
|
+
# we have open fds for those fifos, we don't need the file
|
50
|
+
# system entries any more...
|
51
|
+
exec >$stdout_fifo 2>$stderr_fifo
|
52
|
+
|
53
|
+
# ...so we'll remove it.
|
54
|
+
rm $stdout_fifo
|
55
|
+
rm $stderr_fifo
|
56
|
+
|
57
|
+
# Run the service in the usual way. Our output is already
|
58
|
+
# going to the fifos; that won't change when the new
|
59
|
+
# program executes.
|
60
|
+
exec sudo -H -i -u <%= user %> '<%= process.command %>'
|
61
|
+
end script
|
62
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
start on starting <%= app %>-<%= process.name %>
|
2
|
+
|
3
|
+
task
|
4
|
+
|
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
|
9
|
+
|
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
|
13
|
+
i=$(( $i + 1 ))
|
14
|
+
done
|
15
|
+
|
16
|
+
end script
|
17
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "fileutils"
|
3
|
+
require "foreman/export"
|
4
|
+
|
5
|
+
class Foreman::Export::UpstartScaling < Foreman::Export::Base
|
6
|
+
|
7
|
+
def export
|
8
|
+
error("Must specify a location") unless location
|
9
|
+
FileUtils.mkdir_p location
|
10
|
+
@location = Pathname.new(@location)
|
11
|
+
|
12
|
+
app = self.app || File.basename(engine.directory)
|
13
|
+
user = self.user || app
|
14
|
+
log_root = self.log || "/var/log/#{app}"
|
15
|
+
template_root = self.template || File.expand_path("../../../../data/export/upstart_scaling", __FILE__)
|
16
|
+
|
17
|
+
Dir["#{location}/#{app}*.conf"].each do |file|
|
18
|
+
say "cleaning up: #{file}"
|
19
|
+
FileUtils.rm(file)
|
20
|
+
end
|
21
|
+
|
22
|
+
master_template = export_template("upstart_scaling", "master.conf.erb", template_root)
|
23
|
+
master_config = ERB.new(master_template).result(binding)
|
24
|
+
write_file "#{location}/#{app}.conf", master_config
|
25
|
+
|
26
|
+
engine.procfile.entries.each do |process|
|
27
|
+
process_master_template = export_template("upstart_scaling", "process_master.conf.erb", template_root)
|
28
|
+
process_master_config = ERB.new(process_master_template).result(binding)
|
29
|
+
write_file "#{location}/#{app}-#{process.name}.conf", process_master_config
|
30
|
+
|
31
|
+
process_instances_template = export_template("upstart_scaling", "process_instances.conf.erb", template_root)
|
32
|
+
process_instances_config = ERB.new(process_instances_template).result(binding)
|
33
|
+
write_file "#{location}/#{app}-#{process.name}-instances.conf", process_instances_config
|
34
|
+
|
35
|
+
process_template = export_template("upstart_scaling", "process.conf.erb", template_root)
|
36
|
+
process_config = ERB.new(process_template).result(binding)
|
37
|
+
write_file "#{location}/#{app}-#{process.name}-instance.conf", process_config
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foreman-upstart-scaling
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Fabio Kung
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: foreman
|
16
|
+
requirement: &70179280215540 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.46.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70179280215540
|
25
|
+
description: Upstart exporter for foreman, that supports worker scaling via env vars.
|
26
|
+
email: fabio.kung@gmail.com
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- lib/foreman/export/upstart_scaling.rb
|
32
|
+
- data/export/upstart_scaling/master.conf.erb
|
33
|
+
- data/export/upstart_scaling/process.conf.erb
|
34
|
+
- data/export/upstart_scaling/process_instances.conf.erb
|
35
|
+
- data/export/upstart_scaling/process_master.conf.erb
|
36
|
+
homepage: http://github.com/fabiokung/foreman-upstart-scaling
|
37
|
+
licenses: []
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.8.12
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: Upstart configuration generator for foreman
|
60
|
+
test_files: []
|