capistrano-pm2 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffda96769c385338ad1973fabf3816edd16df7e7
4
- data.tar.gz: ca51a5917d09dedd3cd43f2fd6d273de3311e21a
3
+ metadata.gz: 045f273a83e6ae8e68ad2497b7fd0efd72069ae4
4
+ data.tar.gz: 551fa9799c731e6e71a81731b76bd165ba9d941b
5
5
  SHA512:
6
- metadata.gz: 26f6ca106220a5a0b55310d094a1652a32d6c1bfed301bdac18dbeed8b129f5cd9d17571828776b398cbdd509f5ded6e0dc84451406ac3df2012b210ea925ffd
7
- data.tar.gz: 64ae35b315c423d40bc4ac0aeb682dd45905588463a68fc3f06dce21f4fd85f11273434a100a479d6cf88a86d7d2e0f701338eb9c701e24100be636ba41397d5
6
+ metadata.gz: 053da5f4133f05a7b120d60dff2ae675733b4052b15b98b36355ac607f9646edb46b4aa41618c66cfdaf945128682a3fc4023143e4689f6eb520a5369a4562c1
7
+ data.tar.gz: a34b39ef9ae9ce2e56b1243f655cba0a3af0f0b95147da3cf01a4737614246293e24b3bde97442cb5f8d65da9aa92ec09c0777ee86bf9cc95aea3294b6e66dbd
data/README.md CHANGED
@@ -1,7 +1,4 @@
1
- # capistrano-pm2
2
- This is a pm2 handler for capistrano 3.x.
3
-
4
- # Capistrano::pm2
1
+ # Capistrano::pm2 [![Gem Version](https://badge.fury.io/rb/capistrano-pm2.svg)](http://badge.fury.io/rb/capistrano-pm2)
5
2
 
6
3
  nodejs [pm2](https://github.com/Unitech/pm2) support for Capistrano 3.x
7
4
 
@@ -47,20 +44,24 @@ end
47
44
 
48
45
  Available Tasks
49
46
  ```ruby
47
+ cap pm2:delete # Delete pm2 application
48
+ cap pm2:list # Show pm2 application info
49
+ cap pm2:logs # Watch pm2 logs
50
50
  cap pm2:restart # Restart app gracefully
51
- cap pm2:show # Show pm2 application info
51
+ cap pm2:setup # Install pm2 via npm on the remote host
52
52
  cap pm2:start # Start pm2 application
53
- cap pm2:status # Show pm2 status
53
+ cap pm2:status # List all pm2 applications
54
54
  cap pm2:stop # Stop pm2 application
55
55
  ```
56
56
 
57
57
  Configurable options:
58
-
59
58
  ```ruby
60
- set :pm2_app_command, 'main' # default, runs main.js
59
+ set :pm2_app_command, 'main.js' # default, runs main.js
60
+ set :pm2_app_name, nil # app name for pm2, default cap :application
61
61
  set :pm2_target_path, -> { release_path.join('subdir') } # default not set
62
- set :pm2_roles, :all # default
63
- set :pm2_env_variables, {} # default
62
+ set :pm2_roles, :all # default, cap roles to run on
63
+ set :pm2_env_variables, {} # default, env vars for pm2
64
+ set :pm2_start_params, '' # default, pm2 start params see http://pm2.keymetrics.io/docs/usage/quick-start/#cheat-sheet
64
65
  ```
65
66
 
66
67
  ## Contributing
@@ -4,15 +4,15 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'capistrano-pm2'
7
- spec.version = '1.0.1'
7
+ spec.version = '1.0.2'
8
8
  spec.authors = ['Tom Hanoldt']
9
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}
10
+ spec.description = 'nodejs pm2 support for Capistrano 3.x'
11
+ spec.summary = 'nodejs pm2 support for Capistrano 3.x'
12
12
  spec.homepage = 'https://github.com/creative-workflow/capistrano-pm2'
13
13
  spec.license = 'MIT'
14
14
 
15
- spec.files = `git ls-files`.split($/)
15
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ['lib']
@@ -1,41 +1,6 @@
1
1
  require 'json'
2
2
 
3
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
4
  desc 'Restart app gracefully'
40
5
  task :restart do
41
6
  on roles fetch(:pm2_roles) do
@@ -58,30 +23,78 @@ namespace :pm2 do
58
23
 
59
24
  before 'deploy:restart', 'pm2:restart'
60
25
 
61
- desc 'Show pm2 status'
26
+ desc 'List all pm2 applications'
62
27
  task :status do
63
- run_task :pm2, :status
28
+ run_task :pm2, :list
64
29
  end
65
30
 
66
31
  desc 'Start pm2 application'
67
32
  task :start do
68
- run_task :pm2, :start, app_command_with_js_extension
33
+ run_task :pm2, :start, fetch(:pm2_app_command), "--name #{app_name} #{fetch(:pm2_start_params)}"
69
34
  end
70
35
 
71
36
  desc 'Stop pm2 application'
72
37
  task :stop do
73
- run_task :pm2, :stop, app_command_without_js_extension
38
+ run_task :pm2, :stop, app_name
39
+ end
40
+
41
+ desc 'Delete pm2 application'
42
+ task :delete do
43
+ run_task :pm2, :delete, app_name
74
44
  end
75
45
 
76
46
  desc 'Show pm2 application info'
77
- task :show do
78
- run_task :pm2, :show, app_command_without_js_extension
47
+ task :list do
48
+ run_task :pm2, :show, app_name
49
+ end
50
+
51
+ desc 'Watch pm2 logs'
52
+ task :logs do
53
+ run_task :pm2, :logs
54
+ end
55
+
56
+ desc 'Install pm2 via npm on the remote host'
57
+ task :setup do
58
+ run_task :npm, :install, 'pm2 -g'
59
+ end
60
+
61
+ def app_name
62
+ fetch(:pm2_app_name) || fetch(:application)
63
+ end
64
+
65
+ def app_status
66
+ within current_path do
67
+ ps = JSON.parse(capture :pm2, :jlist, app_name)
68
+
69
+ return nil if ps.empty?
70
+
71
+ # status: online, errored, stopped
72
+ return ps[0]["pm2_env"]["status"]
73
+ end
74
+ end
75
+
76
+ def restart_app
77
+ within current_path do
78
+ execute :pm2, :restart, app_name
79
+ end
80
+ end
81
+
82
+ def run_task(*args)
83
+ on roles fetch(:pm2_roles) do
84
+ within fetch(:pm2_target_path, release_path) do
85
+ with fetch(:pm2_env_variables) do
86
+ execute *args
87
+ end
88
+ end
89
+ end
79
90
  end
80
91
  end
81
92
 
82
93
  namespace :load do
83
94
  task :defaults do
84
- set :pm2_app_command, 'main'
95
+ set :pm2_app_command, 'main.js'
96
+ set :pm2_app_name, nil
97
+ set :pm2_start_params, ''
85
98
  set :pm2_roles, :all
86
99
  set :pm2_env_variables, {}
87
100
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-pm2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Hanoldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-03 00:00:00.000000000 Z
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano