whenever-elasticbeanstalk 1.0.0 → 1.1.0
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/README.md +6 -3
- data/bin/create_cron_leader +10 -4
- data/bin/ensure_one_cron_leader +12 -6
- data/bin/remove_cron_leader +11 -5
- data/bin/setup_cron +2 -2
- data/lib/whenever-elasticbeanstalk/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -4,8 +4,6 @@ Whenever-elasticbeanstalk is an extension gem to [Whenever](https://github.com/j
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
**Whenever-elasticbeanstalk is still under development and not packaged as a gem yet**
|
8
|
-
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
@@ -30,7 +28,7 @@ $ cd /apps/my-great-project
|
|
30
28
|
$ wheneverize-eb .
|
31
29
|
```
|
32
30
|
|
33
|
-
This will create an initial `config/schedule.rb` file for you with the `ensure_leader` job set to run every minute. It will also create a `.ebextensions/cron.config` file that will automatically choose a leader on environment initialization, and start up Whenever with the correct `leader` role.
|
31
|
+
This will create an initial `config/schedule.rb` file for you with the `ensure_leader` job set to run every minute. It will also create a `.ebextensions/cron.config` file that will automatically choose a leader on environment initialization, and start up Whenever with the correct `leader` role. Lastly, it creates the `config/whenever-elasticbeanstalk.yml` file that will contain your AWS credentials for retrieving your environment information.
|
34
32
|
|
35
33
|
### Manually updating schedule
|
36
34
|
|
@@ -75,6 +73,11 @@ staging:
|
|
75
73
|
secret_access_key: 'your secret access key'
|
76
74
|
```
|
77
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
|
79
|
+
```
|
80
|
+
|
78
81
|
## Usage
|
79
82
|
|
80
83
|
For `config/schedule.rb` usage, please see the documentation for the [Whenever gem](https://github.com/javan/whenever).
|
data/bin/create_cron_leader
CHANGED
@@ -26,14 +26,20 @@ end
|
|
26
26
|
|
27
27
|
optparse.parse!
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
ENVIRONMENT_NAME_FILE = "/var/app/support/env_name"
|
30
|
+
AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[ENV["RAILS_ENV"]]
|
31
31
|
|
32
|
-
AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[environment]
|
33
32
|
AWS.config(AWS_CREDENTIALS)
|
34
33
|
ec2 = AWS::EC2.new
|
35
34
|
|
36
|
-
environment_name =
|
35
|
+
environment_name = if File.exists?(ENVIRONMENT_NAME_FILE)
|
36
|
+
File.read(ENVIRONMENT_NAME_FILE)
|
37
|
+
else
|
38
|
+
instance_id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
|
39
|
+
env_name = ec2.instances[instance_id].tags["elasticbeanstalk:environment-name"]
|
40
|
+
File.open(ENVIRONMENT_NAME_FILE, 'w') {|f| f.write(env_name) }
|
41
|
+
env_name
|
42
|
+
end
|
37
43
|
|
38
44
|
leader_instances = ec2.instances.inject([]) do |m, i|
|
39
45
|
m << i.id if i.tags["elasticbeanstalk:environment-name"] == environment_name &&
|
data/bin/ensure_one_cron_leader
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
+
|
2
3
|
require 'rubygems'
|
3
4
|
gem 'aws-sdk'
|
4
|
-
|
5
5
|
require 'aws-sdk'
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
ENVIRONMENT_NAME_FILE = "/var/app/support/env_name"
|
8
|
+
AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[ENV["RAILS_ENV"]]
|
9
9
|
|
10
|
-
AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[environment]
|
11
10
|
AWS.config(AWS_CREDENTIALS)
|
12
11
|
ec2 = AWS::EC2.new
|
13
12
|
|
14
|
-
environment_name =
|
13
|
+
environment_name = if File.exists?(ENVIRONMENT_NAME_FILE)
|
14
|
+
File.read(ENVIRONMENT_NAME_FILE)
|
15
|
+
else
|
16
|
+
instance_id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
|
17
|
+
env_name = ec2.instances[instance_id].tags["elasticbeanstalk:environment-name"]
|
18
|
+
File.open(ENVIRONMENT_NAME_FILE, 'w') {|f| f.write(env_name) }
|
19
|
+
env_name
|
20
|
+
end
|
15
21
|
|
16
22
|
leader_instances = ec2.instances.inject([]) do |m, i|
|
17
23
|
m << i.id if i.tags["elasticbeanstalk:environment-name"] == environment_name &&
|
@@ -22,6 +28,6 @@ end
|
|
22
28
|
|
23
29
|
if leader_instances.count < 1
|
24
30
|
`bundle exec create_cron_leader`
|
25
|
-
elsif leader_instances.count > 1 && leader_instances.
|
31
|
+
elsif leader_instances.count > 1 && leader_instances.include?(this_instance_id)
|
26
32
|
`bundle exec remove_cron_leader`
|
27
33
|
end
|
data/bin/remove_cron_leader
CHANGED
@@ -4,14 +4,20 @@ gem 'aws-sdk'
|
|
4
4
|
|
5
5
|
require 'aws-sdk'
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
ENVIRONMENT_NAME_FILE = "/var/app/support/env_name"
|
8
|
+
AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[ENV["RAILS_ENV"]]
|
9
9
|
|
10
|
-
AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[environment]
|
11
10
|
AWS.config(AWS_CREDENTIALS)
|
12
11
|
ec2 = AWS::EC2.new
|
13
12
|
|
14
|
-
environment_name =
|
13
|
+
environment_name = if File.exists?(ENVIRONMENT_NAME_FILE)
|
14
|
+
File.read(ENVIRONMENT_NAME_FILE)
|
15
|
+
else
|
16
|
+
instance_id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
|
17
|
+
env_name = ec2.instances[instance_id].tags["elasticbeanstalk:environment-name"]
|
18
|
+
File.open(ENVIRONMENT_NAME_FILE, 'w') {|f| f.write(env_name) }
|
19
|
+
env_name
|
20
|
+
end
|
15
21
|
|
16
22
|
leader_instances = ec2.instances.inject([]) do |m, i|
|
17
23
|
m << i.id if i.tags["elasticbeanstalk:environment-name"] == environment_name &&
|
@@ -20,7 +26,7 @@ leader_instances = ec2.instances.inject([]) do |m, i|
|
|
20
26
|
m
|
21
27
|
end
|
22
28
|
|
23
|
-
if leader_instances.count > 1 && leader_instances.
|
29
|
+
if leader_instances.count > 1 && leader_instances.include?(this_instance_id)
|
24
30
|
ec2.instances[this_instance_id].tags["leader"] = "false"
|
25
31
|
end
|
26
32
|
|
data/bin/setup_cron
CHANGED
@@ -4,14 +4,14 @@ gem 'aws-sdk'
|
|
4
4
|
|
5
5
|
require 'aws-sdk'
|
6
6
|
|
7
|
-
|
7
|
+
instance_id = `/opt/aws/bin/ec2-metadata -i | awk '{print $2}'`.strip
|
8
8
|
environment = ENV["RAILS_ENV"]
|
9
9
|
|
10
10
|
AWS_CREDENTIALS = YAML.load_file("config/whenever-elasticbeanstalk.yml")[environment]
|
11
11
|
AWS.config(AWS_CREDENTIALS)
|
12
12
|
ec2 = AWS::EC2.new
|
13
13
|
|
14
|
-
if ec2.instances[
|
14
|
+
if ec2.instances[instance_id].tags["leader"] == "true"
|
15
15
|
`bundle exec whenever --roles leader --set 'environment=#{environment}&path=/var/app/current' --update-crontab`
|
16
16
|
else
|
17
17
|
`bundle exec whenever --set 'environment=#{environment}&path=/var/app/current' --update-crontab`
|
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.
|
4
|
+
version: 1.1.0
|
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-
|
12
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: whenever
|