oysters 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f13f9c91f634f44bb5eb195a8bdecd72124ae63e
4
+ data.tar.gz: b9016fa7eded94b4590f8c7a1a74789459a491cb
5
+ SHA512:
6
+ metadata.gz: 0a620d805b44475410b75d7ee57fb3f60b1d03a93d4e361d2eb6dd828e70d950c887748e75d9b9326ddd4d49c8b9773505297daf5bc34b1916adc4e2c000f450
7
+ data.tar.gz: fb7152f7c55ac131e15b66f7e3154c4f3c34af5c9186968213a9d26de546f6a8c05748881f1457ce78550aa5d6105e317b09b9dcde3c6be2ee4629782f9c7433
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in oysters.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Roman Samoilov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Oysters
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'oysters'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install oysters
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/[my-github-username]/oysters/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "oysters"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ require 'oysters'
2
+
3
+ Oysters.with_configuration do
4
+
5
+ namespace :dalli do
6
+ desc 'Clear cache'
7
+ task :clear_cache, :roles => :memcache do
8
+ run "cd #{latest_release}; bundle exec rails runner -e #{rails_env} 'Rails.cache.clear'"
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,110 @@
1
+ require 'oysters'
2
+
3
+ Oysters.with_configuration do
4
+
5
+ namespace :initd do
6
+
7
+ namespace :unicorn do
8
+ desc 'Generate unicorn init.d script'
9
+ task :setup, roles: :app do
10
+ su_command = "su - #{user} -c"
11
+ CapistranoUnicorn::Config.load self
12
+ CapistranoUnicorn::Utility.send(:alias_method, :old_try_unicorn_user, :try_unicorn_user)
13
+ CapistranoUnicorn::Utility.send(:define_method, :try_unicorn_user, Proc.new { su_command })
14
+ run "mkdir -p #{shared_path}/config"
15
+ location = fetch(:template_dir, 'config/templates') + "/#{application}_unicorn_init.sh.erb"
16
+ config = ERB.new(File.read(location))
17
+ text_config = config.result(binding)
18
+ text_config.gsub!(/(#{su_command}) (.*);/,'\1 "\2";')
19
+ put text_config, "#{shared_path}/config/#{application}_unicorn_init.sh"
20
+ CapistranoUnicorn::Utility.send(:alias_method, :try_unicorn_user, :old_try_unicorn_user)
21
+ end
22
+
23
+ desc 'Copy unicorn into an init.d and add to chkconfig'
24
+ task :install, roles: :app do
25
+ sudo "cp #{shared_path}/config/#{application}_unicorn_init.sh /etc/init.d/#{application}_unicorn_#{rails_env};\
26
+ sudo chmod +x /etc/init.d/#{application}_unicorn_#{rails_env};\
27
+ sudo chkconfig --add #{application}_unicorn_#{rails_env}", pty: true
28
+ end
29
+
30
+ desc 'Removes unicorn from an init.d and deletes from chkconfig'
31
+ task :uninstall, roles: :app do
32
+ sudo "chkconfig --del #{application}_unicorn_#{rails_env};\
33
+ sudo rm -f /etc/init.d/#{application}_unicorn_#{rails_env}", pty: true
34
+ end
35
+ end
36
+
37
+ set :ntp_host, 'pool.ntp.org' unless exists?(:ntp_host)
38
+
39
+ namespace :ntp do
40
+ desc 'Installs and configures ntp service'
41
+ task :install do
42
+ sudo "yum install -y ntp;\
43
+ sudo chkconfig ntpd on;\
44
+ sudo service ntpd stop;\
45
+ sleep 3;\
46
+ if [[ ! `grep 'server #{ntp_host}' /etc/ntp.conf` ]];
47
+ then
48
+ sudo sed -i '0,/^server /s//server #{ntp_host}\n&/' /etc/ntp.conf;\
49
+ fi;\
50
+ if [[ ! `grep '#{ntp_host}' /etc/ntp/step-tickers` ]];
51
+ then
52
+ sudo sed -i '0,/^#.*$/s//&\n#{ntp_host}/' /etc/ntp/step-tickers;\
53
+ fi;\
54
+ sudo ntpdate #{ntp_host};\
55
+ sleep 1;\
56
+ sudo service ntpd start;
57
+ "
58
+ end
59
+ end
60
+
61
+ INITD_SERVICES = %w(nginx memcached redis unicorn thin god mysql postgres)
62
+ set :initd_services, INITD_SERVICES unless exists?(:initd_services)
63
+
64
+ desc "Check if all needed services are enabled to run on system start-up"
65
+ task :check do
66
+ services_str = initd_services.join('|')
67
+ results = capture("/sbin/chkconfig --list | egrep '#{services_str}'").split("\n")
68
+
69
+ results.each do |result|
70
+ service_name = result.match(/\S+/)[0]
71
+
72
+ print "Checking #{service_name}... "
73
+ if result =~ /3:on/ && result =~ /4:on/ && result =~ /5:on/
74
+ puts 'OK'
75
+ else
76
+ puts 'Failed! Fixing...'
77
+ sudo "/sbin/chkconfig --level 345 #{service_name} on"
78
+ end
79
+
80
+ puts "\n"
81
+ end
82
+
83
+ puts 'Done!'
84
+ end
85
+
86
+ namespace :kewatcher do
87
+ desc 'Generate kewatcher init.d script'
88
+ task :setup, roles: :app do
89
+ run "mkdir -p #{shared_path}/config"
90
+ location = fetch(:template_dir, 'config/templates') + "/#{application}_kewatcher_init.sh.erb"
91
+ config = ERB.new(File.read(location))
92
+ put config.result(binding), "#{shared_path}/config/#{application}_kewatcher_init.sh"
93
+ end
94
+
95
+ desc 'Copy kewatcher into an init.d and adds to chkconfig'
96
+ task :install, roles: :app do
97
+ sudo "cp #{shared_path}/config/#{application}_kewatcher_init.sh /etc/init.d/#{application}_kewatcher;\
98
+ sudo chmod +x /etc/init.d/#{application}_kewatcher;\
99
+ sudo chkconfig --add #{application}_kewatcher", pty: true
100
+ end
101
+
102
+ desc 'Removes kewatcher from an init.d and deletes from chkconfig'
103
+ task :uninstall, roles: :app do
104
+ sudo "chkconfig --del #{application}_kewatcher;\
105
+ sudo rm -f /etc/init.d/#{application}_kewatcher", pty: true
106
+ end
107
+ end
108
+ end
109
+
110
+ end
@@ -0,0 +1,27 @@
1
+ require 'oysters'
2
+
3
+ Oysters.with_configuration do
4
+
5
+ namespace :resque do
6
+ namespace :scheduler do
7
+ task :start do
8
+ run "cd #{current_path} && RAILS_ENV=#{rails_env} PIDFILE=#{current_path}/tmp/pids/scheduler.pid \
9
+ BACKGROUND=yes VERBOSE=1 #{fetch(:bundle_cmd, 'bundle')} exec \
10
+ rake resque:scheduler >/dev/null 2>&1 &"
11
+ end
12
+
13
+ task :stop do
14
+ run "if [ -e #{current_path}/tmp/pids/scheduler.pid ]; then \
15
+ #{try_sudo} kill -QUIT $(cat #{current_path}/tmp/pids/scheduler.pid) ; rm #{current_path}/tmp/pids/scheduler.pid \
16
+ ;fi"
17
+ end
18
+
19
+ task :restart do
20
+ stop
21
+ sleep 5
22
+ start
23
+ end
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,112 @@
1
+ require 'oysters'
2
+
3
+ Oysters.with_configuration do
4
+
5
+ namespace :resque do
6
+ namespace :kewatcher do
7
+ desc 'Starts kewatcher'
8
+ task :start do
9
+ command = %Q%
10
+ if [ -e #{shared_path}/pids/kewatcher.pid ] && kill -0 `cat #{shared_path}/pids/kewatcher.pid` >/dev/null 2>&1; then
11
+ echo "Kewatcher is already running. Sending restart command...";
12
+ kill -s HUP `cat #{shared_path}/pids/kewatcher.pid`;
13
+ else
14
+ echo "Kewatcher is not running. Executing start command...";
15
+ cd #{current_path};
16
+ RAILS_ENV=#{rails_env} #{fetch(:bundle_cmd, "bundle")} exec \
17
+ #{current_path}/bin/kewatcher \
18
+ -m #{fetch(:kewatcher_max_workers, 30)} \
19
+ -c #{current_path}/config/redis.yml \
20
+ -p #{shared_path}/pids/kewatcher.pid \
21
+ >/dev/null 2>&1 &
22
+ tries_count=10;
23
+ success=0;
24
+ while [ $((tries_count-=1)) -ge 0 ]; do
25
+ if [[ -n `pgrep -xf "[K]EWatcher.*"` ]] >/dev/null 2>&1; then
26
+ success=1;
27
+ break;
28
+ fi;
29
+ sleep 1;
30
+ done;
31
+ if [ $success -eq 0 ]; then
32
+ echo "***KEWatcher has failed to start. Please try again...";
33
+ else
34
+ echo "+++KEWatcher has been started successfully.";
35
+ fi;
36
+ fi;
37
+ %
38
+
39
+ run command
40
+ end
41
+
42
+ desc 'Stops kewatcher'
43
+ task :stop do
44
+ command = %Q%
45
+ if [ -e #{shared_path}/pids/kewatcher.pid ] && kill -0 `cat #{shared_path}/pids/kewatcher.pid` >/dev/null 2>&1; then
46
+ echo "Stopping Kewatcher...";
47
+ kill -s QUIT `cat #{shared_path}/pids/kewatcher.pid`;
48
+ tries_count=50;
49
+ success=0;
50
+ while [ $((tries_count-=1)) -ge 0 ]; do
51
+ if [[ -n `pgrep -xf "[K]EWatcher.*|[r]esque-[0-9]+.*"` ]] >/dev/null 2>&1; then
52
+ sleep 1;
53
+ else
54
+ success=1;
55
+ break;
56
+ fi;
57
+ done;
58
+ if [ $success -eq 0 ]; then
59
+ pidkewat=`pgrep -xf [K]EWatcher.*`;
60
+ if [[ -n $pidkewat ]] >/dev/null 2>&1; then
61
+ echo "~~~KEWatcher has failed to stop. So kill pid=$pidkewat ...";
62
+ kill -s KILL `cat #{shared_path}/pids/kewatcher.pid`;
63
+ rm -f #{shared_path}/pids/kewatcher.pid;
64
+ echo "~~~ killing workers as well ...";
65
+ kill -s KILL `pgrep -xf "[r]esque-[0-9]+.*" | xargs`;
66
+ else
67
+ echo "***KEWatcher has been stopped. But some workers still running. Kill'em all...";
68
+ kill -s KILL `pgrep -xf "[r]esque-[0-9]+.*" | xargs`;
69
+ fi;
70
+ else
71
+ echo "+++KEWatcher has been stopped successfully.";
72
+ fi;
73
+ sleep 1;
74
+ else
75
+ echo "Kewatcher is not running.";
76
+ fi;
77
+ %
78
+
79
+ run command
80
+ end
81
+
82
+ desc 'Restarts kewatcher'
83
+ task :restart do
84
+ #command = %Q%
85
+ # if [ -e #{shared_path}/pids/kewatcher.pid ] && kill -0 `cat #{shared_path}/pids/kewatcher.pid` > /dev/null 2>&1; then
86
+ # echo "Kewatcher is running. Sending restart signal...";
87
+ # kill -s HUP `cat #{shared_path}/pids/kewatcher.pid`;
88
+ # else
89
+ # echo "Kewatcher is not running. Executing start command...";
90
+ # cd #{current_path}; RAILS_ENV=#{rails_env} #{fetch(:bundle_cmd, "bundle")} exec kewatcher -m #{fetch(:kewatcher_max_workers, 130)} -c #{current_path}/config/redis.yml -p #{shared_path}/pids/kewatcher.pid >/dev/null 2>&1 &
91
+ # fi;
92
+ #%
93
+ #
94
+ #run command
95
+ stop; start
96
+ end
97
+ end
98
+
99
+ namespace :sliders do
100
+ desc 'Setup resque sliders'
101
+ task :setup do
102
+ command = %Q%
103
+ echo "Setting up resque sliders...";
104
+ cd #{current_path}; RAILS_ENV=#{rails_env} #{fetch(:bundle_cmd, "bundle")} exec rake resque:setup_resque_slider >/dev/null 2>&1 &
105
+ %
106
+
107
+ run command
108
+ end
109
+ end
110
+ end
111
+
112
+ end
@@ -0,0 +1,3 @@
1
+ module Oysters
2
+ VERSION = "0.0.1"
3
+ end
data/lib/oysters.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "oysters/version"
2
+ require "capistrano"
3
+
4
+ unless Capistrano::Configuration.respond_to?(:instance)
5
+ abort "oysters require Capistrano 2 and a bottle of champagne"
6
+ end
7
+
8
+ module Oysters
9
+ def self.with_configuration(&block)
10
+ Capistrano::Configuration.instance(:must_exist).load do
11
+ namespace :oysters, &block
12
+ end
13
+ end
14
+ end
data/oysters.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'oysters/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "oysters"
8
+ spec.version = Oysters::VERSION
9
+ spec.authors = ["Roman Samoilov"]
10
+ spec.email = ["rsamoilov@productengine.com"]
11
+
12
+ spec.summary = %q{Common capistrano recipes}
13
+ spec.homepage = "https://github.com/rsamoilov/oysters"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.8"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency "capistrano", "~> 2.0"
25
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oysters
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Roman Samoilov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: capistrano
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ description:
56
+ email:
57
+ - rsamoilov@productengine.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/oysters.rb
70
+ - lib/oysters/dalli.rb
71
+ - lib/oysters/initd.rb
72
+ - lib/oysters/resque_scheduler.rb
73
+ - lib/oysters/resque_sliders.rb
74
+ - lib/oysters/version.rb
75
+ - oysters.gemspec
76
+ homepage: https://github.com/rsamoilov/oysters
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.6
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Common capistrano recipes
100
+ test_files: []