capistrano-pm2 1.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: ffda96769c385338ad1973fabf3816edd16df7e7
4
+ data.tar.gz: ca51a5917d09dedd3cd43f2fd6d273de3311e21a
5
+ SHA512:
6
+ metadata.gz: 26f6ca106220a5a0b55310d094a1652a32d6c1bfed301bdac18dbeed8b129f5cd9d17571828776b398cbdd509f5ded6e0dc84451406ac3df2012b210ea925ffd
7
+ data.tar.gz: 64ae35b315c423d40bc4ac0aeb682dd45905588463a68fc3f06dce21f4fd85f11273434a100a479d6cf88a86d7d2e0f701338eb9c701e24100be636ba41397d5
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-bundler.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 creative-workflow
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # capistrano-pm2
2
+ This is a pm2 handler for capistrano 3.x.
3
+
4
+ # Capistrano::pm2
5
+
6
+ nodejs [pm2](https://github.com/Unitech/pm2) support for Capistrano 3.x
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'capistrano', '~> 3.1.0'
14
+ gem 'capistrano-pm2'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install capistrano-pm2
24
+
25
+ ## Usage
26
+
27
+ Require in `Capfile` to use the default task:
28
+
29
+ ```ruby
30
+ require 'capistrano/pm2'
31
+ ```
32
+
33
+ The task will run before `deploy:restart` as part of Capistrano's default deploy,
34
+ or can be run in isolation with `cap production pm2:restart`. You can also invoke it in your `deploy.rb`:
35
+ ```ruby
36
+ namespace :deploy do
37
+ desc 'Restart application'
38
+ task :restart do
39
+ # invoke 'npm:install'
40
+ invoke 'pm2:restart'
41
+ end
42
+
43
+ after :publishing, :restart
44
+ end
45
+ ```
46
+
47
+
48
+ Available Tasks
49
+ ```ruby
50
+ cap pm2:restart # Restart app gracefully
51
+ cap pm2:show # Show pm2 application info
52
+ cap pm2:start # Start pm2 application
53
+ cap pm2:status # Show pm2 status
54
+ cap pm2:stop # Stop pm2 application
55
+ ```
56
+
57
+ Configurable options:
58
+
59
+ ```ruby
60
+ set :pm2_app_command, 'main' # default, runs main.js
61
+ set :pm2_target_path, -> { release_path.join('subdir') } # default not set
62
+ set :pm2_roles, :all # default
63
+ set :pm2_env_variables, {} # default
64
+ ```
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'capistrano-pm2'
7
+ spec.version = '1.0.1'
8
+ spec.authors = ['Tom Hanoldt']
9
+ spec.email = ['monotom@gmail.com']
10
+ spec.description = %q{nodejs pm2 support for Capistrano 3.x}
11
+ spec.summary = %q{nodejs pm2 support for Capistrano 3.x}
12
+ spec.homepage = 'https://github.com/creative-workflow/capistrano-pm2'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'capistrano', '>= 3.0.0'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
+ end
File without changes
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/pm2.rake', __FILE__)
@@ -0,0 +1,88 @@
1
+ require 'json'
2
+
3
+ namespace :pm2 do
4
+ def app_status
5
+ within current_path do
6
+ ps = JSON.parse(capture :pm2, :jlist, fetch(:pm2_app_command))
7
+
8
+ return nil if ps.empty?
9
+
10
+ # status: online, errored, stopped
11
+ return ps[0]["pm2_env"]["status"]
12
+ end
13
+ end
14
+
15
+ def restart_app
16
+ within current_path do
17
+ execute :pm2, :restart, app_command_with_js_extension
18
+ end
19
+ end
20
+
21
+ def app_command_with_js_extension
22
+ "#{app_command_without_js_extension}.js"
23
+ end
24
+
25
+ def app_command_without_js_extension
26
+ fetch(:pm2_app_command).sub(/\.js$/, '')
27
+ end
28
+
29
+ def run_task(*args)
30
+ on roles fetch(:pm2_roles) do
31
+ within fetch(:pm2_target_path, release_path) do
32
+ with fetch(:pm2_env_variables) do
33
+ execute *args
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ desc 'Restart app gracefully'
40
+ task :restart do
41
+ on roles fetch(:pm2_roles) do
42
+ case app_status
43
+ when nil
44
+ info 'App is not registerd'
45
+ invoke 'pm2:start'
46
+ when 'stopped'
47
+ info 'App is stopped'
48
+ restart_app
49
+ when 'errored'
50
+ info 'App has errored'
51
+ restart_app
52
+ when 'online'
53
+ info 'App is online'
54
+ restart_app
55
+ end
56
+ end
57
+ end
58
+
59
+ before 'deploy:restart', 'pm2:restart'
60
+
61
+ desc 'Show pm2 status'
62
+ task :status do
63
+ run_task :pm2, :status
64
+ end
65
+
66
+ desc 'Start pm2 application'
67
+ task :start do
68
+ run_task :pm2, :start, app_command_with_js_extension
69
+ end
70
+
71
+ desc 'Stop pm2 application'
72
+ task :stop do
73
+ run_task :pm2, :stop, app_command_without_js_extension
74
+ end
75
+
76
+ desc 'Show pm2 application info'
77
+ task :show do
78
+ run_task :pm2, :show, app_command_without_js_extension
79
+ end
80
+ end
81
+
82
+ namespace :load do
83
+ task :defaults do
84
+ set :pm2_app_command, 'main'
85
+ set :pm2_roles, :all
86
+ set :pm2_env_variables, {}
87
+ end
88
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-pm2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tom Hanoldt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: nodejs pm2 support for Capistrano 3.x
56
+ email:
57
+ - monotom@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - capistrano-pm2.gemspec
68
+ - lib/capistrano-pm2.rb
69
+ - lib/capistrano/pm2.rb
70
+ - lib/capistrano/tasks/pm2.rake
71
+ homepage: https://github.com/creative-workflow/capistrano-pm2
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: nodejs pm2 support for Capistrano 3.x
95
+ test_files: []