capistrano-nginx-unit 0.2 → 0.3

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
  SHA256:
3
- metadata.gz: 62b0d922cb2c6e70e8027253e76fd5b9cb0be6fbfb25a8ee31ec5c12a14661a2
4
- data.tar.gz: 939506d0e5896d0f6e0c9058a8953a900543ab533410d2ddb89888bc3607d995
3
+ metadata.gz: 46570db097e14918f9d04863542c5832a9fbdb72cbd8fb974296a534608f9c69
4
+ data.tar.gz: dd0b9a3ab22b37c83598322d0842af3e46e0189f9dc508fc45065a5e73cc9191
5
5
  SHA512:
6
- metadata.gz: 3992ecbc1b83746ec29ef21a65e511e252d1e1267f0ad9df70b2841b377367b16c4c9d8bdd7e01b14afd9e8984cea89eb9252aa50cced62bb913a809bbff766d
7
- data.tar.gz: 3b4480dd832694971899c0a6f83cac055490a4aa62bbfa302bef2bae17d57457d97a66bae093ee7499a4749e2278f97184f0b224a83e913b0c5b280f1b677b77
6
+ metadata.gz: 84a684b6ee4c2576d52bafb6fd19501ea8434b9057a7390c3710744329ddd0e7643969261f083cbc819192ce707a50f9219da84b2311b87e6e1521e0f9800ca9
7
+ data.tar.gz: 168c9932f4b17f74d5bf8ece2859595596026ce960afdb4e8c01d141aca9dd445e2cb4700b4c1dc0672b2e64f76111674debbd9090e6d8dd64df512ac386cf27
data/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ [*]
2
+ end_of_line = lf
3
+ insert_final_newline = true
4
+ indent_size = 2
5
+
6
+ [*.rb]
7
+ trim_trailing_whitespace = true
8
+
9
+ [*.rake]
10
+ trim_trailing_whitespace = true
data/README.md CHANGED
@@ -18,9 +18,12 @@ require "capistrano/nginx-unit"
18
18
  Defined following tasks.
19
19
 
20
20
  ```
21
- cap nginx_unit:configure # Set listener and application configuration for NGINX Unit
22
- cap nginx_unit:configure_app # Set application configuration for NGINX Unit
23
- cap nginx_unit:configure_listener # Set listener configuration for NGINX Unit
21
+ cap nginx_unit:attach # Attach listener and application configuration to NGINX Unit
22
+ cap nginx_unit:attach_app # Attach application configuration to NGINX Unit
23
+ cap nginx_unit:attach_listener # Attach listener configuration to NGINX Unit
24
+ cap nginx_unit:detach # Detach listener and application configuration from NGINX Unit
25
+ cap nginx_unit:detach_app # Detach application configuration from NGINX Unit
26
+ cap nginx_unit:detach_listener # Detach listener configuration from NGINX Unit
24
27
  cap nginx_unit:start # Start NGINX Unit process
25
28
  ```
26
29
 
@@ -39,9 +42,9 @@ set :nginx_unit_group, -> { nil }
39
42
  set :nginx_unit_script, -> { "config.ru" }
40
43
  ```
41
44
 
42
- If you want to apply new code when deployed, please invoke `nginx_unit:configure` task after `deploy:published`.
45
+ If you want to apply new code when deployed, please invoke `nginx_unit:attach` task after `deploy:published`.
43
46
 
44
47
  ```rb
45
48
  # deploy.rb
46
- after "deploy:published", "nginx_unit:configure"
49
+ after "deploy:published", "nginx_unit:attach"
47
50
  ```
@@ -1,3 +1,3 @@
1
1
  module Capistrano
2
- NGINX_UNIT_VERSION = "0.2"
2
+ NGINX_UNIT_VERSION = "0.3"
3
3
  end
@@ -22,8 +22,8 @@ namespace :nginx_unit do
22
22
  if test("[ -e #{pid_file} ] && kill -0 `cat #{pid_file}`")
23
23
  info "NGINX Unit is already started"
24
24
  else
25
- execute :sudo, :unitd,
26
- "--pid #{pid_file}",
25
+ execute :sudo, :unitd,
26
+ "--pid #{pid_file}",
27
27
  "--control unix:#{fetch(:nginx_unit_control_sock)}",
28
28
  fetch(:nginx_unit_options)
29
29
  end
@@ -32,24 +32,23 @@ namespace :nginx_unit do
32
32
 
33
33
  # If you want to apply new code when deployed,
34
34
  # please invoke this task after deploy:published
35
- desc "Set listener and application configuration for NGINX Unit"
36
- task :configure do
35
+ desc "Attach listener and application configuration to NGINX Unit"
36
+ task :attach do
37
37
  invoke "nginx_unit:start"
38
- invoke "nginx_unit:configure_app"
39
- invoke "nginx_unit:configure_listener"
38
+ invoke "nginx_unit:attach_app"
39
+ invoke "nginx_unit:attach_listener"
40
40
  end
41
41
 
42
- desc "Set listener configuration for NGINX Unit"
43
- task :configure_listener do
42
+ desc "Attach listener configuration to NGINX Unit"
43
+ task :attach_listener do
44
44
  on release_roles(fetch(:nginx_unit_roles)) do
45
45
  listener_json = JSON.generate("application" => fetch(:application))
46
-
47
- configure_nginx_unit("/listeners/#{fetch(:nginx_unit_listen)}", listener_json)
46
+ control_nginx_unit(:put, path: "/listeners/#{fetch(:nginx_unit_listen)}", json: listener_json)
48
47
  end
49
48
  end
50
49
 
51
- desc "Set application configuration for NGINX Unit"
52
- task :configure_app do
50
+ desc "Attach application configuration to NGINX Unit"
51
+ task :attach_app do
53
52
  on release_roles(fetch(:nginx_unit_roles)) do |role|
54
53
  released_dir = capture(:readlink, "-f", current_path)
55
54
  raise "Doesn't exist released dir: #{released_dir}" unless test("[ -d #{released_dir} ]")
@@ -62,27 +61,41 @@ namespace :nginx_unit do
62
61
  script: File.join(released_dir, fetch(:nginx_unit_script))
63
62
  })
64
63
 
65
- info "application config: #{app_json}"
66
- configure_nginx_unit("/applications/#{fetch(:nginx_unit_app_name)}", app_json)
64
+ control_nginx_unit(:put, path: "/applications/#{fetch(:nginx_unit_app_name)}", json: app_json)
67
65
  end
68
66
  end
69
67
 
70
- # Send request to NGINX Unit control socket
71
- def configure_nginx_unit(path, json)
72
- info "#{path} => #{json}"
68
+ desc "Detach listener and application configuration from NGINX Unit"
69
+ task :detach do
70
+ invoke "nginx_unit:detach_listener"
71
+ invoke "nginx_unit:detach_app"
72
+ end
73
+
74
+ desc "Detach listener configuration from NGINX Unit"
75
+ task :detach_listener do
76
+ on release_roles(fetch(:nginx_unit_roles)) do
77
+ control_nginx_unit(:delete, path: "/listeners/#{fetch(:nginx_unit_listen)}")
78
+ end
79
+ end
73
80
 
74
- res = JSON.parse(capture(:curl,
75
- "-X PUT",
76
- "-d '#{json}'",
81
+ desc "Detach application configuration from NGINX Unit"
82
+ task :detach_app do
83
+ on release_roles(fetch(:nginx_unit_roles)) do
84
+ control_nginx_unit(:delete, path: "/applications/#{fetch(:nginx_unit_app_name)}")
85
+ end
86
+ end
87
+
88
+ # Send request to NGINX Unit control socket
89
+ def control_nginx_unit(method, path: "", json: nil)
90
+ args = [
91
+ "-fs",
92
+ "-X #{method.to_s.upcase}",
77
93
  "--unix-socket #{fetch(:nginx_unit_control_sock)}",
78
94
  "'http://localhost/#{path}'"
79
- ))
95
+ ]
80
96
 
81
- if res["error"]
82
- fatal res
83
- raise "Faild to configure"
84
- else
85
- info res
86
- end
97
+ args << "-d '#{json}'" if json
98
+
99
+ execute :curl, *args
87
100
  end
88
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-nginx-unit
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - murakmii
@@ -31,6 +31,7 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".editorconfig"
34
35
  - ".gitignore"
35
36
  - Gemfile
36
37
  - LICENSE.txt