slugrunner 0.0.1 → 0.0.2
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.
- data/Vagrantfile +31 -0
- data/lib/slugrunner/cli.rb +2 -0
- data/lib/slugrunner/runner.rb +15 -3
- data/lib/slugrunner/version.rb +1 -1
- metadata +3 -2
data/Vagrantfile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
ROOT = File.dirname(File.expand_path(__FILE__))
|
4
|
+
|
5
|
+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
6
|
+
VAGRANTFILE_API_VERSION = "2"
|
7
|
+
|
8
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
9
|
+
config.vm.box = "phusion-open-ubuntu-12.04-amd64"
|
10
|
+
config.vm.box_url = "https://oss-binaries.phusionpassenger.com/vagrant/boxes/ubuntu-12.04.3-amd64-vbox.box"
|
11
|
+
config.ssh.forward_agent = true
|
12
|
+
if File.directory?("#{ROOT}/../passenger-docker")
|
13
|
+
config.vm.synced_folder File.expand_path("#{ROOT}/../passenger-docker"),
|
14
|
+
"/vagrant/passenger-docker"
|
15
|
+
end
|
16
|
+
|
17
|
+
config.vm.provider :vmware_fusion do |f, override|
|
18
|
+
override.vm.box_url = "https://oss-binaries.phusionpassenger.com/vagrant/boxes/ubuntu-12.04.3-amd64-vmwarefusion.box"
|
19
|
+
f.vmx["displayName"] = "baseimage-docker"
|
20
|
+
end
|
21
|
+
|
22
|
+
if Dir.glob("#{File.dirname(__FILE__)}/.vagrant/machines/default/*/id").empty?
|
23
|
+
# Add lxc-docker package
|
24
|
+
pkg_cmd = "wget -q -O - https://get.docker.io/gpg | apt-key add -;" \
|
25
|
+
"echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list;" \
|
26
|
+
"apt-get update -qq; apt-get install -q -y --force-yes lxc-docker; "
|
27
|
+
# Add vagrant user to the docker group
|
28
|
+
pkg_cmd << "usermod -a -G docker vagrant; "
|
29
|
+
config.vm.provision :shell, :inline => pkg_cmd
|
30
|
+
end
|
31
|
+
end
|
data/lib/slugrunner/cli.rb
CHANGED
@@ -12,6 +12,7 @@ module Slugrunner
|
|
12
12
|
opt :delayed_bind, 'Port bind allowance', default: 0
|
13
13
|
opt :ping, 'Notify state updates', type: :string
|
14
14
|
opt :ping_interval, 'Update interval in seconds', default: 30
|
15
|
+
opt :env, 'Append to environment', type: :strings
|
15
16
|
opt :bash, 'Run interactive shell', default: false
|
16
17
|
end
|
17
18
|
|
@@ -26,6 +27,7 @@ module Slugrunner
|
|
26
27
|
end
|
27
28
|
|
28
29
|
runner.shell = opts[:bash]
|
30
|
+
runner.extra_env = opts[:env] if opts[:env]
|
29
31
|
|
30
32
|
if opts[:delayed_bind] > 0
|
31
33
|
runner.bind_delay = opts[:delayed_bind]
|
data/lib/slugrunner/runner.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
require 'yaml'
|
4
|
+
require 'shellwords'
|
4
5
|
require 'tempfile'
|
5
6
|
require 'socket'
|
6
7
|
require 'timeout'
|
@@ -12,6 +13,7 @@ module Slugrunner
|
|
12
13
|
attr_accessor :ping_url
|
13
14
|
attr_accessor :ping_interval
|
14
15
|
attr_accessor :shell
|
16
|
+
attr_accessor :extra_env
|
15
17
|
|
16
18
|
def initialize(slug, process_type, instance_number)
|
17
19
|
@slug = slug
|
@@ -22,6 +24,7 @@ module Slugrunner
|
|
22
24
|
@ping_interval = 0
|
23
25
|
@alive = false
|
24
26
|
@shell = false
|
27
|
+
@extra_env = []
|
25
28
|
@hostname = "#{@process_type}.#{instance_number}"
|
26
29
|
end
|
27
30
|
|
@@ -52,6 +55,7 @@ module Slugrunner
|
|
52
55
|
fail "Couldn't find command for process type #{@process_type}" unless proc_command
|
53
56
|
|
54
57
|
command = prepare_env(proc_command)
|
58
|
+
puts(command)
|
55
59
|
@child = fork { exec(command) }
|
56
60
|
trap_signals
|
57
61
|
|
@@ -166,7 +170,7 @@ module Slugrunner
|
|
166
170
|
end
|
167
171
|
|
168
172
|
def prepare_env(cmd)
|
169
|
-
<<-eos
|
173
|
+
blob = <<-eos
|
170
174
|
env - bash -c '
|
171
175
|
cd #{@slug_dir}
|
172
176
|
export HOME=#{@slug_dir}
|
@@ -176,9 +180,17 @@ module Slugrunner
|
|
176
180
|
export SLUG_ENV=1
|
177
181
|
PORT=#{ENV['PORT'] || 0}
|
178
182
|
for file in .profile.d/*; do source $file; done
|
179
|
-
exec #{cmd}
|
180
|
-
'
|
181
183
|
eos
|
184
|
+
|
185
|
+
@extra_env.each do |e|
|
186
|
+
pair = e.split(/=/, 2)
|
187
|
+
next unless pair.length == 2
|
188
|
+
escaped = pair.map { |n| Shellwords.escape(n) }
|
189
|
+
blob += "export #{escaped[0]}=#{escaped[1]}\n"
|
190
|
+
end
|
191
|
+
|
192
|
+
blob += "exec #{cmd}'"
|
193
|
+
blob
|
182
194
|
end
|
183
195
|
end
|
184
196
|
end
|
data/lib/slugrunner/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slugrunner
|
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:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- LICENSE.txt
|
73
73
|
- README.md
|
74
74
|
- Rakefile
|
75
|
+
- Vagrantfile
|
75
76
|
- bin/slugrunner
|
76
77
|
- lib/slugrunner.rb
|
77
78
|
- lib/slugrunner/cli.rb
|