whenever-elasticbeanstalk 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,13 +29,21 @@ optparse.parse!
29
29
  ENVIRONMENT_NAME_FILE = "/var/app/support/env_name"
30
30
  AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[ENV["RAILS_ENV"]]
31
31
 
32
+ instance_id = if File.exists?("/var/app/support/instance_id")
33
+ File.read("/var/app/support/instance_id")
34
+ else
35
+ if id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
36
+ File.open("/var/app/support/instance_id", 'w') {|f| f.write(id) }
37
+ id
38
+ end
39
+ end
40
+
32
41
  AWS.config(AWS_CREDENTIALS)
33
42
  ec2 = AWS::EC2.new
34
43
 
35
44
  environment_name = if File.exists?(ENVIRONMENT_NAME_FILE)
36
45
  File.read(ENVIRONMENT_NAME_FILE)
37
46
  else
38
- instance_id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
39
47
  env_name = ec2.instances[instance_id].tags["elasticbeanstalk:environment-name"]
40
48
  File.open(ENVIRONMENT_NAME_FILE, 'w') {|f| f.write(env_name) }
41
49
  env_name
@@ -49,7 +57,8 @@ leader_instances = ec2.instances.inject([]) do |m, i|
49
57
  end
50
58
 
51
59
  if leader_instances.count < 1
52
- ec2.instances[this_instance_id].tags["leader"] = "true"
60
+ instance_id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
61
+ ec2.instances[instance_id].tags["leader"] = "true"
53
62
  end
54
63
 
55
64
  unless options[:no_update]
@@ -7,13 +7,21 @@ require 'aws-sdk'
7
7
  ENVIRONMENT_NAME_FILE = "/var/app/support/env_name"
8
8
  AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[ENV["RAILS_ENV"]]
9
9
 
10
+ instance_id = if File.exists?("/var/app/support/instance_id")
11
+ File.read("/var/app/support/instance_id")
12
+ else
13
+ if id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
14
+ File.open("/var/app/support/instance_id", 'w') {|f| f.write(id) }
15
+ id
16
+ end
17
+ end
18
+
10
19
  AWS.config(AWS_CREDENTIALS)
11
20
  ec2 = AWS::EC2.new
12
21
 
13
22
  environment_name = if File.exists?(ENVIRONMENT_NAME_FILE)
14
23
  File.read(ENVIRONMENT_NAME_FILE)
15
24
  else
16
- instance_id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
17
25
  env_name = ec2.instances[instance_id].tags["elasticbeanstalk:environment-name"]
18
26
  File.open(ENVIRONMENT_NAME_FILE, 'w') {|f| f.write(env_name) }
19
27
  env_name
@@ -28,6 +36,6 @@ end
28
36
 
29
37
  if leader_instances.count < 1
30
38
  `bundle exec create_cron_leader`
31
- elsif leader_instances.count > 1 && leader_instances.include?(this_instance_id)
39
+ elsif leader_instances.count > 1 && leader_instances.include?(instance_id)
32
40
  `bundle exec remove_cron_leader`
33
41
  end
@@ -7,13 +7,21 @@ require 'aws-sdk'
7
7
  ENVIRONMENT_NAME_FILE = "/var/app/support/env_name"
8
8
  AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[ENV["RAILS_ENV"]]
9
9
 
10
+ instance_id = if File.exists?("/var/app/support/instance_id")
11
+ File.read("/var/app/support/instance_id")
12
+ else
13
+ if id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
14
+ File.open("/var/app/support/instance_id", 'w') {|f| f.write(id) }
15
+ id
16
+ end
17
+ end
18
+
10
19
  AWS.config(AWS_CREDENTIALS)
11
20
  ec2 = AWS::EC2.new
12
21
 
13
22
  environment_name = if File.exists?(ENVIRONMENT_NAME_FILE)
14
23
  File.read(ENVIRONMENT_NAME_FILE)
15
24
  else
16
- instance_id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
17
25
  env_name = ec2.instances[instance_id].tags["elasticbeanstalk:environment-name"]
18
26
  File.open(ENVIRONMENT_NAME_FILE, 'w') {|f| f.write(env_name) }
19
27
  env_name
@@ -26,8 +34,8 @@ leader_instances = ec2.instances.inject([]) do |m, i|
26
34
  m
27
35
  end
28
36
 
29
- if leader_instances.count > 1 && leader_instances.include?(this_instance_id)
30
- ec2.instances[this_instance_id].tags["leader"] = "false"
37
+ if leader_instances.count > 1 && leader_instances.include?(instance_id)
38
+ ec2.instances[instance_id].tags["leader"] = "false"
31
39
  end
32
40
 
33
41
  `bundle exec setup_cron`
data/bin/setup_cron CHANGED
@@ -4,10 +4,17 @@ gem 'aws-sdk'
4
4
 
5
5
  require 'aws-sdk'
6
6
 
7
- instance_id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
8
- environment = ENV["RAILS_ENV"]
7
+ AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[ENV["RAILS_ENV"]]
8
+
9
+ instance_id = if File.exists?("/var/app/support/instance_id")
10
+ File.read("/var/app/support/instance_id")
11
+ else
12
+ if id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
13
+ File.open("/var/app/support/instance_id", 'w') {|f| f.write(id) }
14
+ id
15
+ end
16
+ end
9
17
 
10
- AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[environment]
11
18
  AWS.config(AWS_CREDENTIALS)
12
19
  ec2 = AWS::EC2.new
13
20
 
@@ -1,5 +1,5 @@
1
1
  module Whenever
2
2
  module Elasticbeanstalk
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whenever-elasticbeanstalk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
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: 2013-06-27 00:00:00.000000000 Z
12
+ date: 2013-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: whenever
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  requirements: []
90
90
  rubyforge_project:
91
- rubygems_version: 1.8.25
91
+ rubygems_version: 1.8.24
92
92
  signing_key:
93
93
  specification_version: 3
94
94
  summary: Allows you to run cron jobs easily on one or all AWS Elastic Beanstalk instances.