whenever-elasticbeanstalk 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f0349fecdc40d7d0b003bf8bb8491385973f099
4
+ data.tar.gz: 1318ba5f99fb398a99b88ef0256596e43dd36033
5
+ SHA512:
6
+ metadata.gz: 48ade216b71c196734f8bbd82349ecb265286c3896fa47473af564665c091260ded245bf5cbcf6098add354315279b9ceb8d8b638873abfd34d15568f0f32d2d
7
+ data.tar.gz: 40b1ceec1c70cc0ce210411e57d14c19c144e8d9a6054286bdb90bb1de1bbefccfa8f003a6dfa133e9f858e305752e908d6ce42598cdf114b006b40a40441584
data/README.md CHANGED
@@ -40,9 +40,9 @@ every 1.minute do
40
40
  end
41
41
  ```
42
42
 
43
- ### Create AWS IAM user
43
+ ### EC2 Instance IAM Role Permissions
44
44
 
45
- In order for the scripts to work, you need to supply AWS credentials for a user with access to EC2 instances and tags. It is recommended to create a new user with limited access.
45
+ In order for the scripts to work, you need to ensure that the EC2 Instance Role has access to EC2 instances and tags (further reading at [AWS Documentation](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.iam.roles.aeb.html) ). Ensure that your EC2 instance has at a minimum the following permissions:
46
46
 
47
47
  Example policy:
48
48
  ```json
@@ -66,16 +66,9 @@ Example policy:
66
66
  }
67
67
  ```
68
68
 
69
- Then add the credentials to your `config/whenever-elasticbeanstalk.yml` file.
69
+ Make sure to add the `RACK_ENV` environment variable to your environment if you haven't already done so. This variable is not created automatically by AWS. You can add the following line to your `.elasticbeanstalk/optionsettings.appname-env` file:
70
70
  ```yaml
71
- staging:
72
- access_key_id: 'your access key'
73
- secret_access_key: 'your secret access key'
74
- ```
75
-
76
- Make sure to add the `RAILS_ENV` environment variable to your environment if you haven't already done so. This variable is not created automatically by AWS. You can add the following line to your `.elasticbeanstalk/optionsettings.appname-env` file:
77
- ```yaml
78
- RAILS_ENV=staging
71
+ RACK_ENV=staging
79
72
  ```
80
73
 
81
74
  ## Usage
@@ -96,7 +89,7 @@ end
96
89
  To run a task on all instance, omit the `roles` option.
97
90
  ```ruby
98
91
  every 1.minute do
99
- command "touch /opt/elasticbeanstalk/support/.cron_check"
92
+ command "touch /opt/elasticbeanstalk/containerfiles/.cron_check"
100
93
  end
101
94
  ```
102
95
 
@@ -1,12 +1,16 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require 'optparse'
4
- require 'rubygems'
5
- gem 'aws-sdk'
6
- require 'aws-sdk'
3
+ require 'optparse'
4
+ require 'rubygems'
5
+ gem 'aws-sdk'
6
+ require 'aws-sdk'
7
+ require 'erb'
7
8
 
8
- options = {}
9
+ EB_CONFIG_APP_SUPPORT = ENV['EB_CONFIG_APP_SUPPORT']
10
+ ENVIRONMENT_NAME_FILE = File.join(EB_CONFIG_APP_SUPPORT,'env_name')
9
11
 
12
+ # Options Parsing
13
+ options = {}
10
14
  optparse = OptionParser.new do |opts|
11
15
  opts.banner = "Usage: #{File.basename($0)} [options]"
12
16
 
@@ -23,22 +27,20 @@ optparse = OptionParser.new do |opts|
23
27
  exit
24
28
  end
25
29
  end
26
-
27
30
  optparse.parse!
28
31
 
29
- ENVIRONMENT_NAME_FILE = "/var/app/support/env_name"
30
- AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[ENV["RAILS_ENV"]]
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
32
+ instance_id = if File.exists?(File.join(EB_CONFIG_APP_SUPPORT,'instance_id'))
33
+ File.read(File.join(EB_CONFIG_APP_SUPPORT,'instance_id'))
34
+ else
35
+ if id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
36
+ File.open(File.join(EB_CONFIG_APP_SUPPORT,'instance_id'), 'w') {|f| f.write(id) }
37
+ id
38
+ end
39
+ end
40
+ availability_zone = `/opt/aws/bin/ec2-metadata -z | awk '{print $2}'`.strip
41
+ region = availability_zone.slice(0..availability_zone.length-2)
40
42
 
41
- AWS.config(AWS_CREDENTIALS)
43
+ AWS.config({:credential_provider => AWS::Core::CredentialProviders::EC2Provider.new,:region => region})
42
44
  ec2 = AWS::EC2.new
43
45
 
44
46
  environment_name = if File.exists?(ENVIRONMENT_NAME_FILE)
@@ -49,7 +51,7 @@ else
49
51
  env_name
50
52
  end
51
53
 
52
- leader_instances = ec2.instances.inject([]) do |m, i|
54
+ leader_instances = ec2.instances.to_a.inject([]) do |m, i|
53
55
  m << i.id if i.tags["elasticbeanstalk:environment-name"] == environment_name &&
54
56
  i.status == :running &&
55
57
  i.tags["leader"] == "true"
@@ -57,10 +59,9 @@ leader_instances = ec2.instances.inject([]) do |m, i|
57
59
  end
58
60
 
59
61
  if leader_instances.count < 1
60
- instance_id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
61
62
  ec2.instances[instance_id].tags["leader"] = "true"
62
63
  end
63
64
 
64
65
  unless options[:no_update]
65
- `bundle exec setup_cron`
66
+ `/usr/local/bin/bundle exec setup_cron`
66
67
  end
@@ -1,22 +1,24 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require 'rubygems'
4
- gem 'aws-sdk'
5
- require 'aws-sdk'
3
+ require 'rubygems'
4
+ gem 'aws-sdk'
5
+ require 'aws-sdk'
6
+ require 'erb'
6
7
 
7
- ENVIRONMENT_NAME_FILE = "/var/app/support/env_name"
8
- AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[ENV["RAILS_ENV"]]
8
+ EB_CONFIG_APP_SUPPORT = ENV['EB_CONFIG_APP_SUPPORT']
9
+ ENVIRONMENT_NAME_FILE = File.join(EB_CONFIG_APP_SUPPORT,'env_name')
10
+ instance_id = if File.exists?(File.join(EB_CONFIG_APP_SUPPORT,'instance_id'))
11
+ File.read(File.join(EB_CONFIG_APP_SUPPORT,'instance_id'))
12
+ else
13
+ if id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
14
+ File.open(File.join(EB_CONFIG_APP_SUPPORT,'instance_id'), 'w') {|f| f.write(id) }
15
+ id
16
+ end
17
+ end
18
+ availability_zone = `/opt/aws/bin/ec2-metadata -z | awk '{print $2}'`.strip
19
+ region = availability_zone.slice(0..availability_zone.length-2)
9
20
 
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
-
19
- AWS.config(AWS_CREDENTIALS)
21
+ AWS.config({:credential_provider => AWS::Core::CredentialProviders::EC2Provider.new,:region => region})
20
22
  ec2 = AWS::EC2.new
21
23
 
22
24
  environment_name = if File.exists?(ENVIRONMENT_NAME_FILE)
@@ -27,7 +29,7 @@ else
27
29
  env_name
28
30
  end
29
31
 
30
- leader_instances = ec2.instances.inject([]) do |m, i|
32
+ leader_instances = ec2.instances.to_a.inject([]) do |m, i|
31
33
  m << i.id if i.tags["elasticbeanstalk:environment-name"] == environment_name &&
32
34
  i.status == :running &&
33
35
  i.tags["leader"] == "true"
@@ -35,7 +37,7 @@ leader_instances = ec2.instances.inject([]) do |m, i|
35
37
  end
36
38
 
37
39
  if leader_instances.count < 1
38
- `bundle exec create_cron_leader`
40
+ `/usr/local/bin/bundle exec create_cron_leader`
39
41
  elsif leader_instances.count > 1 && leader_instances.include?(instance_id)
40
- `bundle exec remove_cron_leader`
41
- end
42
+ `/usr/local/bin/bundle exec create_cron_leader`
43
+ end
@@ -1,22 +1,25 @@
1
1
  #!/usr/bin/ruby
2
- require 'rubygems'
3
- gem 'aws-sdk'
4
2
 
5
- require 'aws-sdk'
6
-
7
- ENVIRONMENT_NAME_FILE = "/var/app/support/env_name"
8
- AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[ENV["RAILS_ENV"]]
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
-
19
- AWS.config(AWS_CREDENTIALS)
3
+ require 'rubygems'
4
+ gem 'aws-sdk'
5
+ require 'aws-sdk'
6
+ require 'erb'
7
+
8
+ EB_CONFIG_APP_SUPPORT = ENV['EB_CONFIG_APP_SUPPORT']
9
+ ENVIRONMENT_NAME_FILE = File.join(EB_CONFIG_APP_SUPPORT,'env_name')
10
+
11
+ instance_id = if File.exists?(File.join(EB_CONFIG_APP_SUPPORT,'instance_id'))
12
+ File.read(File.join(EB_CONFIG_APP_SUPPORT,'instance_id'))
13
+ else
14
+ if id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
15
+ File.open(File.join(EB_CONFIG_APP_SUPPORT,'instance_id'), 'w') {|f| f.write(id) }
16
+ id
17
+ end
18
+ end
19
+ availability_zone = `/opt/aws/bin/ec2-metadata -z | awk '{print $2}'`.strip
20
+ region = availability_zone.slice(0..availability_zone.length-2)
21
+
22
+ AWS.config({:credential_provider => AWS::Core::CredentialProviders::EC2Provider.new,:region => region})
20
23
  ec2 = AWS::EC2.new
21
24
 
22
25
  environment_name = if File.exists?(ENVIRONMENT_NAME_FILE)
@@ -27,7 +30,7 @@ else
27
30
  env_name
28
31
  end
29
32
 
30
- leader_instances = ec2.instances.inject([]) do |m, i|
33
+ leader_instances = ec2.instances.to_a.inject([]) do |m, i|
31
34
  m << i.id if i.tags["elasticbeanstalk:environment-name"] == environment_name &&
32
35
  i.status == :running &&
33
36
  i.tags["leader"] == "true"
@@ -38,4 +41,4 @@ if leader_instances.count > 1 && leader_instances.include?(instance_id)
38
41
  ec2.instances[instance_id].tags["leader"] = "false"
39
42
  end
40
43
 
41
- `bundle exec setup_cron`
44
+ `/usr/local/bin/bundle exec setup_cron`
@@ -1,26 +1,32 @@
1
1
  #!/usr/bin/ruby
2
- require 'rubygems'
3
- gem 'aws-sdk'
4
2
 
5
- require 'aws-sdk'
3
+ require 'rubygems'
4
+ gem 'aws-sdk'
5
+ require 'aws-sdk'
6
+ require 'erb'
6
7
 
7
- environment = ENV["RAILS_ENV"]
8
- AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[environment]
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
8
+ EB_CONFIG_APP_SUPPORT = ENV['EB_CONFIG_APP_SUPPORT']
9
+ ENVIRONMENT = ENV["RACK_ENV"]
10
+ instance_id = if File.exists?(File.join(EB_CONFIG_APP_SUPPORT,'instance_id'))
11
+ File.read(File.join(EB_CONFIG_APP_SUPPORT,'instance_id'))
12
+ else
13
+ if id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
14
+ File.open(File.join(EB_CONFIG_APP_SUPPORT,'instance_id'), 'w') {|f| f.write(id) }
15
+ id
16
+ end
16
17
  end
17
- end
18
+ availability_zone = `/opt/aws/bin/ec2-metadata -z | awk '{print $2}'`.strip
19
+ region = availability_zone.slice(0..availability_zone.length-2)
18
20
 
19
- AWS.config(AWS_CREDENTIALS)
21
+ AWS.config({:credential_provider => AWS::Core::CredentialProviders::EC2Provider.new,:region => region})
20
22
  ec2 = AWS::EC2.new
21
23
 
24
+ unless (`echo $PATH`).match("/usr/local/bin")
25
+ `export PATH=/usr/local/bin:$PATH`
26
+ end
27
+
22
28
  if ec2.instances[instance_id].tags["leader"] == "true"
23
- `bundle exec whenever --roles leader --set 'environment=#{environment}&path=/var/app/current' --update-crontab`
29
+ `/usr/local/bin/bundle exec whenever --roles leader --set 'environment=#{ENVIRONMENT}&path=/var/app/current' --update-crontab`
24
30
  else
25
- `bundle exec whenever --roles non-leader --set 'environment=#{environment}&path=/var/app/current' --update-crontab`
31
+ `/usr/local/bin/bundle exec whenever --roles non-leader --set 'environment=#{ENVIRONMENT}&path=/var/app/current' --update-crontab`
26
32
  end
@@ -4,6 +4,7 @@
4
4
 
5
5
  require 'optparse'
6
6
  require 'fileutils'
7
+ require 'erb'
7
8
 
8
9
  OptionParser.new do |opts|
9
10
  opts.banner = "Usage: #{File.basename($0)} [path]"
@@ -52,7 +53,7 @@ schedule_content = <<-FILE
52
53
  # Learn more: http://github.com/javan/whenever
53
54
 
54
55
  every 1.minute do
55
- command "cd /var/app/current && bundle exec ensure_one_cron_leader"
56
+ command "cd /var/app/current && /usr/local/bin/bundle exec ensure_one_cron_leader"
56
57
  end
57
58
  FILE
58
59
 
@@ -72,24 +73,33 @@ end
72
73
 
73
74
  eb_config_content = <<-FILE
74
75
  files:
76
+ # Reload the on deployment
75
77
  /opt/elasticbeanstalk/hooks/appdeploy/post/10_reload_cron.sh:
76
78
  mode: "00700"
77
79
  owner: root
78
80
  group: root
79
81
  content: |
80
82
  #!/usr/bin/env bash
81
- . /opt/elasticbeanstalk/support/envvars
83
+ . /opt/elasticbeanstalk/containerfiles/envvars
82
84
  cd $EB_CONFIG_APP_CURRENT
83
- bundle exec setup_cron
84
-
85
+ su -c "/usr/local/bin/bundle exec setup_cron" $EB_CONFIG_APP_USER
86
+ # Add Bundle to the PATH
87
+ "/etc/profile.d/bundle.sh":
88
+ mode: "000755"
89
+ owner: root
90
+ group: root
91
+ content: |
92
+ #!/usr/bin/env bash
93
+ export PATH=$PATH:/usr/local/bin
94
+ encoding: plain
85
95
  container_commands:
86
96
  cron_01_set_leader:
87
- test: test ! -f /opt/elasticbeanstalk/support/.cron-setup-complete
97
+ test: test ! -f /opt/elasticbeanstalk/containerfiles/.cron-setup-complete
88
98
  leader_only: true
89
99
  cwd: /var/app/ondeck
90
- command: bundle exec create_cron_leader --no-update
100
+ command: su -c "/usr/local/bin/bundle exec create_cron_leader --no-update" $EB_CONFIG_APP_USER
91
101
  cron_02_write_cron_setup_complete_file:
92
- cwd: /opt/elasticbeanstalk/support
102
+ cwd: /opt/elasticbeanstalk/containerfiles
93
103
  command: touch .cron-setup-complete
94
104
  FILE
95
105
 
@@ -129,4 +139,4 @@ else
129
139
  File.open(file, "w") { |f| f.write(aws_credentials_content) }
130
140
  end
131
141
 
132
- puts "[done] wheneverized for Elastic Beanstalk!"
142
+ puts "[done] wheneverized for Elastic Beanstalk!"
@@ -1,5 +1,5 @@
1
1
  module Whenever
2
2
  module Elasticbeanstalk
3
- VERSION = "1.1.3"
3
+ VERSION = "1.1.4"
4
4
  end
5
5
  end
@@ -7,15 +7,15 @@ Gem::Specification.new do |gem|
7
7
  gem.name = "whenever-elasticbeanstalk"
8
8
  gem.version = Whenever::Elasticbeanstalk::VERSION
9
9
  gem.platform = Gem::Platform::RUBY
10
- gem.authors = ["Chad McGimpsey"]
11
- gem.email = ["chad.mcgimpsey@gmail.com"]
10
+ gem.authors = ["Chad McGimpsey","Joel Courtney"]
11
+ gem.email = ["chad.mcgimpsey@gmail.com","euphemize@gmail.com"]
12
12
  gem.description = %q{Use Whenever on AWS Elastic Beanstalk}
13
13
  gem.summary = %q{Allows you to run cron jobs easily on one or all AWS Elastic Beanstalk instances.}
14
14
  gem.homepage = "https://github.com/dignoe/whenever-elasticbeanstalk"
15
15
  gem.license = 'MIT'
16
16
 
17
- gem.add_dependency('whenever')
18
- gem.add_dependency('aws-sdk')
17
+ gem.add_dependency('whenever','~> 0.9', '>= 0.9.2')
18
+ gem.add_dependency('aws-sdk', '~> 1.50', '>= 1.50.0')
19
19
 
20
20
  gem.files = `git ls-files`.split($/)
21
21
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,51 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whenever-elasticbeanstalk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
5
- prerelease:
4
+ version: 1.1.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Chad McGimpsey
8
+ - Joel Courtney
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-12 00:00:00.000000000 Z
12
+ date: 2014-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: whenever
16
16
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
17
  requirements:
19
- - - ! '>='
18
+ - - "~>"
20
19
  - !ruby/object:Gem::Version
21
- version: '0'
20
+ version: '0.9'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.2
22
24
  type: :runtime
23
25
  prerelease: false
24
26
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
27
  requirements:
27
- - - ! '>='
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '0.9'
31
+ - - ">="
28
32
  - !ruby/object:Gem::Version
29
- version: '0'
33
+ version: 0.9.2
30
34
  - !ruby/object:Gem::Dependency
31
35
  name: aws-sdk
32
36
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
37
  requirements:
35
- - - ! '>='
38
+ - - "~>"
36
39
  - !ruby/object:Gem::Version
37
- version: '0'
40
+ version: '1.50'
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.50.0
38
44
  type: :runtime
39
45
  prerelease: false
40
46
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
47
  requirements:
43
- - - ! '>='
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: '1.50'
51
+ - - ">="
44
52
  - !ruby/object:Gem::Version
45
- version: '0'
53
+ version: 1.50.0
46
54
  description: Use Whenever on AWS Elastic Beanstalk
47
55
  email:
48
56
  - chad.mcgimpsey@gmail.com
57
+ - euphemize@gmail.com
49
58
  executables:
50
59
  - create_cron_leader
51
60
  - ensure_one_cron_leader
@@ -55,7 +64,7 @@ executables:
55
64
  extensions: []
56
65
  extra_rdoc_files: []
57
66
  files:
58
- - .gitignore
67
+ - ".gitignore"
59
68
  - Gemfile
60
69
  - LICENSE.txt
61
70
  - README.md
@@ -71,26 +80,25 @@ files:
71
80
  homepage: https://github.com/dignoe/whenever-elasticbeanstalk
72
81
  licenses:
73
82
  - MIT
83
+ metadata: {}
74
84
  post_install_message:
75
85
  rdoc_options: []
76
86
  require_paths:
77
87
  - lib
78
88
  required_ruby_version: !ruby/object:Gem::Requirement
79
- none: false
80
89
  requirements:
81
- - - ! '>='
90
+ - - ">="
82
91
  - !ruby/object:Gem::Version
83
92
  version: '0'
84
93
  required_rubygems_version: !ruby/object:Gem::Requirement
85
- none: false
86
94
  requirements:
87
- - - ! '>='
95
+ - - ">="
88
96
  - !ruby/object:Gem::Version
89
97
  version: '0'
90
98
  requirements: []
91
99
  rubyforge_project:
92
- rubygems_version: 1.8.25
100
+ rubygems_version: 2.2.2
93
101
  signing_key:
94
- specification_version: 3
102
+ specification_version: 4
95
103
  summary: Allows you to run cron jobs easily on one or all AWS Elastic Beanstalk instances.
96
104
  test_files: []