mina-sidekiq-upstart 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3142e282119266a06790d3aee4b7b98a39b4f5c1f61d90b1a69516a4864066df
4
+ data.tar.gz: e15ca89d1aac02ebd648a0a2f2b346c3e6d2aa4d6ff263adf1203531aa0037fa
5
+ SHA512:
6
+ metadata.gz: 77d26f5cc4302f04d452d212c8c1076340e65b6e2375ad109cddfa7cab7d7b47eccbd5e9be2a9e9d8b03ccce9532ab7d687c6560ff9a2b269d9cd9ffc885b707
7
+ data.tar.gz: d66c69e93770be26534e074015be13d14d7a47adfdc0c10a6b5c4eae74d7da40f4242270b655a580ee29d0c258556c31efd35572fae54d55fb54625cdeea65ed
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ test_env/deploy/
20
+ .idea
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - "1.9.3"
5
+ - "2.0.0"
6
+ - "2.1.0"
7
+ services: redis
8
+ env: FORCE_ADD_SSH_KEY=1
data/Changelog.md ADDED
@@ -0,0 +1,19 @@
1
+ Changelog
2
+ =========
3
+
4
+ 0.3.1 2015-01-18
5
+ ----------------
6
+
7
+ * fix starting in background
8
+
9
+ 0.2.0 2013-08-18
10
+ ----------------
11
+
12
+ Breaking Changes:
13
+
14
+ * to load the tasks requiring 'mina_sidekiq_upstart/tasks' is needed now
15
+
16
+ Enhancements:
17
+
18
+ * add sidekiq_processes to allow launching multiple sidekiq instances
19
+ * improved checking, if old instances of sidekiq are still running
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://www.rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mina-sidekiq-upstart (0.3.1)
5
+ mina
6
+
7
+ GEM
8
+ remote: http://www.rubygems.org/
9
+ specs:
10
+ mina (0.3.1)
11
+ open4 (~> 1.3.4)
12
+ rake
13
+ open4 (1.3.4)
14
+ rake (10.4.2)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ mina-sidekiq-upstart!
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ LICENSE
2
+
3
+ The MIT License
4
+
5
+ Copyright (c) 2012 Nadarei, Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ mina-sidekiq-upstart
2
+ ============
3
+
4
+ [![Build Status](https://travis-ci.org/Mic92/mina-sidekiq-upstart.png?branch=master)](https://travis-ci.org/Mic92/mina-sidekiq-upstart)
5
+
6
+ mina-sidekiq-upstart is a gem that adds tasks to aid in the deployment of [Sidekiq] (http://mperham.github.com/sidekiq/)
7
+ using [Mina] (http://nadarei.co/mina).
8
+
9
+ # Getting Start
10
+
11
+ ## Installation
12
+
13
+ gem install mina-sidekiq-upstart
14
+
15
+ ## Example
16
+
17
+ ## Usage example
18
+
19
+ require 'mina_sidekiq_upstart/tasks'
20
+ ...
21
+ # to make logs persistent between deploys
22
+ set :shared_paths, ['log']
23
+
24
+ task :setup do
25
+ # sidekiq needs a place to store its pid file and log file
26
+ queue! %[mkdir -p "#{deploy_to}/shared/pids/"]
27
+ queue! %[mkdir -p "#{deploy_to}/shared/log/"]
28
+ end
29
+
30
+ task :deploy do
31
+ deploy do
32
+ # stop accepting new workers
33
+ invoke :'sidekiq:quiet'
34
+ invoke :'git:clone'
35
+ invoke :'deploy:link_shared_paths'
36
+ ...
37
+
38
+ to :launch do
39
+ ...
40
+ invoke :'sidekiq:restart'
41
+ end
42
+ end
43
+ end
44
+
45
+ ## Available Tasks
46
+
47
+ * sidekiq:stop
48
+ * sidekiq:start
49
+ * sidekiq:restart
50
+ * sidekiq:quiet
51
+
52
+ ## Available Options
53
+
54
+ | Option | Description |
55
+ | ------------------- | ------------------------------------------------------------------------------ |
56
+ | *sidekiq* | Sets the path to sidekiq. |
57
+ | *sidekiqctl* | Sets the path to sidekiqctl. |
58
+ | *sidekiq\_timeout* | Sets a upper limit of time a worker is allowed to finish, before it is killed. |
59
+ | *sidekiq\_log* | Sets the path to the log file of sidekiq. |
60
+ | *sidekiq\_pid* | Sets the path to the pid file of a sidekiq worker. |
61
+ | *sidekiq_processes* | Sets the number of sidekiq processes launched. |
62
+
63
+ ## Testing
64
+
65
+ The test requires a local running ssh server with the ssh keys of the current
66
+ user added to its `~/.ssh/authorized_keys`. In OS X, this is "Remote Login"
67
+ under the Sharing pref pane.
68
+
69
+ To run the full blown test suite use:
70
+
71
+ bundle exec rake test
72
+
73
+ For faster release cycle use
74
+
75
+ cd test_env
76
+ bundle exec mina deploy --verbose
77
+
78
+ ## Copyright
79
+
80
+ Copyright (c) 2013 Jörg Thalheim http://higgsboson.tk/joerg
81
+
82
+ See LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "rake"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList["test/**/*_test.rb"]
7
+ end
8
+
9
+ task default: :test
@@ -0,0 +1,125 @@
1
+ # # Modules: Sidekiq
2
+ # Adds settings and tasks for managing Sidekiq workers.
3
+ #
4
+ # ## Usage example
5
+ # require 'mina_sidekiq_upstart/tasks'
6
+ # ...
7
+ # task :setup do
8
+ # # sidekiq needs a place to store its pid file
9
+ # queue! %[mkdir -p "#{deploy_to}/shared/pids/"]
10
+ # end
11
+ #
12
+ # task :deploy do
13
+ # deploy do
14
+ # invoke :'sidekiq:quiet'
15
+ # invoke :'git:clone'
16
+ # ...
17
+ #
18
+ # to :launch do
19
+ # ...
20
+ # invoke :'sidekiq:restart'
21
+ # end
22
+ # end
23
+ # end
24
+
25
+ require 'mina/bundler'
26
+ require 'mina/rails'
27
+
28
+ # ## Settings
29
+ # Any and all of these settings can be overriden in your `deploy.rb`.
30
+
31
+ # ### sidekiq
32
+ # Sets the path to sidekiq.
33
+ set_default :sidekiq, lambda { "#{bundle_bin} exec sidekiq" }
34
+
35
+ # ### sidekiqctl
36
+ # Sets the path to sidekiqctl.
37
+ set_default :sidekiqctl, lambda { "#{bundle_prefix} sidekiqctl" }
38
+
39
+ # ### sidekiq_timeout
40
+ # Sets a upper limit of time a worker is allowed to finish, before it is killed.
41
+ set_default :sidekiq_timeout, 10
42
+
43
+ # ### sidekiq_config
44
+ # Sets the path to the configuration file of sidekiq
45
+ set_default :sidekiq_config, lambda { "#{deploy_to}/#{current_path}/config/sidekiq.yml" }
46
+
47
+ # ### sidekiq_log
48
+ # Sets the path to the log file of sidekiq
49
+ #
50
+ # To disable logging set it to "/dev/null"
51
+ set_default :sidekiq_log, lambda { "#{deploy_to}/#{current_path}/log/sidekiq.log" }
52
+
53
+ # ### sidekiq_pid
54
+ # Sets the path to the pid file of a sidekiq worker
55
+ set_default :sidekiq_pid, lambda { "#{deploy_to}/#{shared_path}/pids/sidekiq.pid" }
56
+
57
+ # ### sidekiq_processes
58
+ # Sets the number of sidekiq processes launched
59
+ set_default :sidekiq_processes, 1
60
+
61
+ # ## Control Tasks
62
+ namespace :sidekiq do
63
+ def for_each_process(&block)
64
+ sidekiq_processes.times do |idx|
65
+ pid_file = if idx == 0
66
+ sidekiq_pid
67
+ else
68
+ "#{sidekiq_pid}-#{idx}"
69
+ end
70
+ yield(pid_file, idx)
71
+ end
72
+ end
73
+
74
+ # ### sidekiq:quiet
75
+ desc "Quiet sidekiq (stop accepting new work)"
76
+ task :quiet => :environment do
77
+ queue %[echo "-----> Quiet sidekiq (stop accepting new work)"]
78
+ for_each_process do |pid_file, idx|
79
+ queue %{
80
+ if [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then
81
+ cd "#{deploy_to}/#{current_path}"
82
+ #{echo_cmd %{#{sidekiqctl} quiet #{pid_file}} }
83
+ else
84
+ echo 'Skip quiet command (no pid file found)'
85
+ fi
86
+ }
87
+ end
88
+ end
89
+
90
+ # ### sidekiq:stop
91
+ desc "Stop sidekiq"
92
+ task :stop => :environment do
93
+ queue %[echo "-----> Stop sidekiq"]
94
+ for_each_process do |pid_file, idx|
95
+ queue %[
96
+ if [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then
97
+ cd "#{deploy_to}/#{current_path}"
98
+ #{echo_cmd %[#{sidekiqctl} stop #{pid_file} #{sidekiq_timeout}]}
99
+ else
100
+ echo 'Skip stopping sidekiq (no pid file found)'
101
+ fi
102
+ ]
103
+ end
104
+ end
105
+
106
+ # ### sidekiq:start
107
+ desc "Start sidekiq"
108
+ task :start => :environment do
109
+ queue %[echo "-----> Start sidekiq"]
110
+ for_each_process do |pid_file, idx|
111
+ #queue %{
112
+ # cd "#{deploy_to}/#{current_path}"
113
+ # #{echo_cmd %[#{sidekiq} -d -e #{rails_env} -C #{sidekiq_config} -i #{idx} -P #{pid_file} -L #{sidekiq_log}] }
114
+ #}
115
+ queue %[sudo start sidekiq app=#{deploy_to}/#{current_path} index=0 ]
116
+ end
117
+ end
118
+
119
+ # ### sidekiq:restart
120
+ desc "Restart sidekiq"
121
+ task :restart do
122
+ invoke :'sidekiq:stop'
123
+ invoke :'sidekiq:start'
124
+ end
125
+ end
@@ -0,0 +1,5 @@
1
+ module MinaSidekiqUpstart
2
+ def self.version
3
+ "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'mina_sidekiq_upstart/version'
2
+
3
+ module MinaSidekiqUpstart
4
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require "./lib/mina_sidekiq_upstart/version.rb"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mina-sidekiq-upstart"
7
+ s.version = MinaSidekiqUpstart.version
8
+ s.authors = ["Максим Столбухин"]
9
+ s.email = ["maxstbn@gmail.com"]
10
+ s.homepage = "https://github.com/vened/mina-sidekiq-upstart"
11
+ s.summary = "Tasks to deploy Sidekiq with mina."
12
+ s.description = "Adds tasks to aid in the deployment of Sidekiq"
13
+ s.license = "MIT"
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
+ s.post_install_message = <<-MESSAGE
20
+ Starting with 0.2.0, you have to add:
21
+
22
+ require "mina_sidekiq_upstart/tasks"
23
+
24
+ in your deploy.rb to load the library
25
+ MESSAGE
26
+
27
+ s.add_runtime_dependency "mina"
28
+ end
@@ -0,0 +1,61 @@
1
+ require "test_helper"
2
+
3
+ describe "mina_sidekiq_upstart" do
4
+ before do
5
+ @old_cwd = Dir.pwd
6
+ @env_root = TEST_ROOT.join("..", "test_env")
7
+ Dir.chdir(@env_root)
8
+ FileUtils.rm_rf("deploy")
9
+ end
10
+ after { Dir.chdir(@old_cwd) }
11
+
12
+ def mina(task)
13
+ cmd = "bundle exec mina --verbose #{task}"
14
+ puts "$ #{cmd}"
15
+ system cmd
16
+ end
17
+
18
+ def check_process(pid)
19
+ begin
20
+ Process.kill(0, pid)
21
+ return true
22
+ rescue Errno::EPERM => e
23
+ puts "No permission to query #{pid}!"
24
+ raise e
25
+ rescue Errno::ESRCH
26
+ puts "#{pid} is NOT running."
27
+ return false
28
+ rescue
29
+ puts "Unable to determine status for #{pid} : #{$!}"
30
+ end
31
+ end
32
+
33
+ describe "setup" do
34
+ before { mina "setup" }
35
+ it "should deploy" do
36
+ begin
37
+ # fresh deploy
38
+ mina "deploy"
39
+ # second deploy
40
+ mina "deploy"
41
+ rescue Exception => e
42
+ log = "./deploy/shared/sidekiq.log"
43
+ if File.exists?(log)
44
+ puts "cat #{log}"
45
+ puts File.open(log).read
46
+ end
47
+ raise e
48
+ end
49
+ end
50
+ it "should start/stop sidekiq" do
51
+ sidekiq_pid_path = @env_root.join("deploy", "shared", "pids", "sidekiq.pid")
52
+ # fresh deploy
53
+ mina "sidekiq:start"
54
+ pid = File.read(sidekiq_pid_path)
55
+ check_process(pid).must_equal true
56
+ # second deploy
57
+ mina "sidekiq:stop"
58
+ check_process(pid).must_equal true
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,63 @@
1
+ require "minitest/spec"
2
+ require "minitest/autorun"
3
+ require 'pathname'
4
+
5
+ TEST_ROOT = Pathname.new(File.dirname(__FILE__))
6
+
7
+ module MiniTestWithHooks
8
+ class Unit < MiniTest::Unit
9
+ def before_suites; end
10
+ def after_suites; end
11
+
12
+ def _run_suites(suites, type)
13
+ begin
14
+ before_suites
15
+ super(suites, type)
16
+ ensure
17
+ after_suites
18
+ end
19
+ end
20
+
21
+ def _run_suite(suite, type)
22
+ begin
23
+ suite.before_suite
24
+ super(suite, type)
25
+ ensure
26
+ suite.after_suite
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ module MiniTestWithTransactions
33
+ class Unit < MiniTestWithHooks::Unit
34
+ def before_suites
35
+ super
36
+ if ENV["FORCE_ADD_SSH_KEY"]
37
+ force_add_ssh_key
38
+ end
39
+ end
40
+ def force_add_ssh_key(&block)
41
+ ssh_key = File.expand_path("~/.ssh/id_rsa.pub")
42
+ unless File.exists?(ssh_key)
43
+ sh "ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa"
44
+ end
45
+ file = File.open(ssh_key)
46
+ pub_key = file.readline
47
+ file.close
48
+
49
+ authorized_keys = File.expand_path("~/.ssh/authorized_keys")
50
+ begin
51
+ File.open(authorized_keys, "a+") do |f|
52
+ File.chmod(0600, authorized_keys)
53
+ f.puts(pub_key)
54
+ end
55
+ rescue Exception => e
56
+ puts e.message
57
+ puts e.backtrace.inspect
58
+ ensure
59
+ File.chmod(0400, authorized_keys)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,47 @@
1
+ require 'mina'
2
+ require 'mina/git'
3
+ require 'mina_sidekiq_upstart/tasks'
4
+ require 'mina/git'
5
+ require 'mina/bundler'
6
+ require 'mina/rvm'
7
+ require 'fileutils'
8
+
9
+
10
+ FileUtils.mkdir_p "#{Dir.pwd}/deploy"
11
+
12
+ set :ssh_options, '-o StrictHostKeyChecking=no'
13
+
14
+ set :domain, 'localhost'
15
+ set :deploy_to, "#{Dir.pwd}/deploy"
16
+ set :repository, 'https://github.com/Mic92/mina-sidekiq-upstart-test-rails.git'
17
+ set :keep_releases, 2
18
+ set :sidekiq_processes, 2
19
+
20
+ set :shared_paths, ['log']
21
+
22
+ task :environment do
23
+ invoke :'rvm:use[ruby-2.1.2]'
24
+ end
25
+
26
+ task setup: :environment do
27
+ queue! %[mkdir -p "#{deploy_to}/shared/pids/"]
28
+ queue! %[mkdir -p "#{deploy_to}/shared/log/"]
29
+ end
30
+
31
+ task deploy: :environment do
32
+ deploy do
33
+ invoke :'git:clone'
34
+ invoke :'deploy:link_shared_paths'
35
+ invoke :'bundle:install'
36
+
37
+ to :launch do
38
+ invoke :'sidekiq:start'
39
+ queue! %[sleep 3; kill -0 `cat #{sidekiq_pid}`]
40
+
41
+ invoke :'sidekiq:quiet'
42
+
43
+ invoke :'sidekiq:stop'
44
+ queue! %[(kill -0 `cat #{sidekiq_pid}`) 2> /dev/null && exit 1 || exit 0]
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mina-sidekiq-upstart
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Максим Столбухин
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mina
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Adds tasks to aid in the deployment of Sidekiq
28
+ email:
29
+ - maxstbn@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".travis.yml"
36
+ - Changelog.md
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - lib/mina_sidekiq_upstart.rb
43
+ - lib/mina_sidekiq_upstart/tasks.rb
44
+ - lib/mina_sidekiq_upstart/version.rb
45
+ - mina-sidekiq-upstart.gemspec
46
+ - test/deploy_test.rb
47
+ - test/test_helper.rb
48
+ - test_env/config/deploy.rb
49
+ homepage: https://github.com/vened/mina-sidekiq-upstart
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message: |
54
+ Starting with 0.2.0, you have to add:
55
+
56
+ require "mina_sidekiq_upstart/tasks"
57
+
58
+ in your deploy.rb to load the library
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.7.8
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Tasks to deploy Sidekiq with mina.
78
+ test_files:
79
+ - test/deploy_test.rb
80
+ - test/test_helper.rb