eycloud-recipe-sidekiq 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg
2
+ tmp
3
+ Gemfile.lock
data/ChangeLog.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Sidekiq recipe for EY Cloud
2
+
3
+ DESCRIPTION HERE
4
+
5
+ ## Installation
6
+
7
+ INSTALLATION HERE
8
+
9
+ ## Contributing
10
+
11
+ 1. Fork it
12
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
13
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
14
+ 4. Push to the branch (`git push origin my-new-feature`)
15
+ 5. Create new Pull Request
16
+
17
+ ## License
18
+
19
+ MIT LICENSE
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ version = "0.1.0" # TODO get from metadata.json or .rb
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "eycloud-recipe-sidekiq"
8
+ s.version = version
9
+ s.authors = ["Dr Nic Williams"]
10
+ s.email = ["drnicwilliams@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Sidekiq recipe for EY Cloud} # TODO from metadata
13
+ s.description = %q{Sidekiq recipe for EY Cloud} # TODO from metadata long_description
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ # s.add_dependency("eycloud-helper-cronjobs")
21
+ s.add_development_dependency("rake")
22
+ end
@@ -0,0 +1,21 @@
1
+ class Chef
2
+ class Recipe
3
+ # Return which instance is to have redis installed on it
4
+ # This is determind as follows:
5
+ # 1. A utility prefixed with 'resque'
6
+ # 2. A solo
7
+ # Returns array of hash of instance data, including { "id" => "i-123456", }
8
+ def sidekiq_instances
9
+ @resque_instances ||= node[:engineyard][:environment][:instances].find do |x|
10
+ x[:role] == "solo" || node[:instance_role] == "eylocal" ||
11
+ (node[:role] == "util" && node[:name] == "sidekiq"
12
+ end
13
+ end
14
+
15
+ # Does this instance run resque?
16
+ def sidekiq_instance?
17
+ node[:instance_role] == "solo" || node[:instance_role] == "eylocal" ||
18
+ (node[:instance_role] == "util" && node[:name] == "sidekiq"
19
+ end
20
+ end
21
+ end
data/metadata.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "sidekiq",
3
+ "description": "Sidekiq recipe for EY Cloud",
4
+ "long_description": "",
5
+ "license": "MIT",
6
+ "maintainer": "Dr Nic Williams",
7
+ "maintainer_email": "drnicwilliams@gmail.com",
8
+ "version": "0.1.0",
9
+ "attributes": {
10
+ },
11
+ "dependencies": {
12
+ }
13
+ }
data/metadata.rb ADDED
@@ -0,0 +1,7 @@
1
+ name "sidekiq"
2
+ description "Sidekiq recipe for EY Cloud"
3
+ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
4
+ maintainer "Dr Nic Williams"
5
+ maintainer_email "drnicwilliams@gmail.com"
6
+ version "0.1.0"
7
+ # depends "cronjobs"
@@ -0,0 +1,22 @@
1
+ #
2
+ # Cookbook Name:: sidekiq
3
+ # Recipe:: restart
4
+ #
5
+
6
+ if sidekiq_instance?
7
+
8
+ node[:applications].each do |app_name, data|
9
+
10
+ template "/etc/monit.d/sidekiq_#{app_name}.monitrc" do
11
+ owner 'root'
12
+ group 'root'
13
+ mode 0644
14
+ source "monitrc.erb"
15
+ variables({
16
+ :command_name => "sidekiq",
17
+ :app_name => app_name
18
+ })
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ #
2
+ # Cookbook Name:: sidekiq
3
+ # Recipe:: default
4
+ #
5
+
6
+ require_recipe "sidekiq::configure"
7
+ require_recipe "sidekiq::restart"
@@ -0,0 +1,19 @@
1
+ #
2
+ # Cookbook Name:: sidekiq
3
+ # Recipe:: install
4
+ #
5
+
6
+ if sidekiq_instance?
7
+
8
+ template "/engineyard/bin/sidekiq" do
9
+ source "sidekiq.erb"
10
+ owner "root"
11
+ group "root"
12
+ mode 0655
13
+ variables({
14
+ :command_name => "sidekiq",
15
+ :command => "bundle exec sidekiq"
16
+ })
17
+ end
18
+
19
+ end
@@ -0,0 +1,7 @@
1
+ #
2
+ # Cookbook Name:: sidekiq
3
+ # Recipe:: restart
4
+ #
5
+
6
+ if sidekiq_instance?
7
+ end
@@ -0,0 +1,7 @@
1
+ check process <%= "#{@app_name}_#{@command_name}" %>
2
+ with pidfile /var/run/engineyard/<%= @command_name %>/<%= @app_name %>/<%=@command_name %>.pid
3
+ start program = "/engineyard/bin/<%= "#{@command_name}" %>_wrapper <%= @app_name %> start"
4
+ stop program = "/engineyard/bin/<%= "#{@command_name}" %>_wrapper <%= @app_name %> stop"
5
+ # if mem > 200 MB for 2 cycles then restart
6
+ # if cpu > 100% for 2 cycles then restart
7
+ group <%= "#{@app_name}_#{@command_name}" %>
@@ -0,0 +1,78 @@
1
+ #!/bin/sh
2
+ #
3
+ # This script starts and stops the Sidekiq daemon
4
+ # This script belongs in /engineyard/bin/sidekiq
5
+ #
6
+ # Run the script as follows:
7
+ # /engineyard/bin/sidekiq app_name start|stop
8
+ #
9
+
10
+ # These variables are managed by Chef - modify them in recipes/default.rb
11
+ COMMAND_NAME="<%= @command_name %>" # Alpha-numeric characters and underscores only
12
+ COMMAND="sidekiq"
13
+
14
+ CURDIR=`pwd`
15
+ PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
16
+
17
+ RAILS_ROOT=/data/$1/current
18
+
19
+ PID_FILE=/var/run/engineyard/$COMMAND_NAME/$1/$COMMAND_NAME.pid
20
+ EXEC_LOG_FILE=/var/log/engineyard/$COMMAND_NAME/wrapper_$1.log
21
+
22
+ usage() {
23
+ echo "Usage: $0 <appname> {start|stop}"
24
+ exit 1
25
+ }
26
+
27
+ if [ $# -lt 2 ]; then usage; fi
28
+
29
+ if [ -d $RAILS_ROOT ]; then
30
+ mkdir -p /var/log/engineyard/$COMMAND_NAME/$1
31
+ mkdir -p /var/run/engineyard/$COMMAND_NAME/$1
32
+
33
+ # handle the second param, don't start if already existing
34
+ case "$2" in
35
+ start)
36
+ cd $RAILS_ROOT
37
+ echo "Starting $COMMAND_NAME"
38
+ if [ -f $PID_FILE ]; then
39
+ PID=`cat $PID_FILE`
40
+ if [ -d /proc/$PID ]; then
41
+ echo "$COMMAND_NAME is already running."
42
+ exit 1
43
+ fi
44
+ rm -f $PID_FILE
45
+ fi
46
+ exec $COMMAND 1>$EXEC_LOG_FILE 2>&1 <%= "&" if @run_in_background %>
47
+ <%= @run_in_background ? "echo $! > $PID_FILE;" : "echo $$ > $PID_FILE" %>
48
+ ;;
49
+ stop)
50
+ GRACE_TIME=${GRACE_TIME:-40}
51
+ echo "Stopping $COMMAND_NAME"
52
+ if [ -f $PID_FILE ]; then
53
+ PID=`cat $PID_FILE`
54
+ kill $PID 2>/dev/null; true
55
+ SLEEP_COUNT=0
56
+ while [ -e /proc/$PID ]; do
57
+ sleep .25
58
+ let "SLEEP_COUNT+=1"
59
+ if(( "$SLEEP_COUNT" > $GRACE_TIME )); then
60
+ echo "Stop wait time exceeded. Killing..."
61
+ kill -9 $PID 2>/dev/null; true
62
+ break
63
+ fi
64
+ done
65
+ rm $PID_FILE
66
+ else
67
+ echo "No PID file found! Cannot stop $COMMAND_NAME"
68
+ fi
69
+ ;;
70
+ *)
71
+ usage
72
+ ;;
73
+ esac
74
+ else
75
+ echo "$RAILS_ROOT doesn't exist."
76
+ usage
77
+ fi
78
+ cd $CURDIR
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eycloud-recipe-sidekiq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dr Nic Williams
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70160749094480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70160749094480
25
+ description: Sidekiq recipe for EY Cloud
26
+ email:
27
+ - drnicwilliams@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - ChangeLog.md
34
+ - Gemfile
35
+ - README.md
36
+ - Rakefile
37
+ - eycloud-recipe-sidekiq.gemspec
38
+ - libraries/find_sidekiq_instances.rb
39
+ - metadata.json
40
+ - metadata.rb
41
+ - recipes/configure.rb
42
+ - recipes/default.rb
43
+ - recipes/install.rb
44
+ - recipes/restart.rb
45
+ - template/default/monitrc.erb
46
+ - template/default/sidekiq.erb
47
+ homepage: ''
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ segments:
60
+ - 0
61
+ hash: 3628996913867977882
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ segments:
69
+ - 0
70
+ hash: 3628996913867977882
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.17
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Sidekiq recipe for EY Cloud
77
+ test_files: []