capistrano-monit_runit 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 705f5e797d5a2516fb2900e85ae3252d732119bc
4
- data.tar.gz: 0d0b76890fb55a86ab800ccd445c97ed28d78d1b
3
+ metadata.gz: 8d99cd3e4764b444da5342e877f62b6d84d2fcd5
4
+ data.tar.gz: 48ba994ea84122c81668d642103a33f66528abca
5
5
  SHA512:
6
- metadata.gz: 21406a6ee4f05b0df8bf3bd766eda7bd1fd052d73b3d6c82193ff353700a1ccf9839bedc41088513d564d0455aaa38c0bcf061bc3182679d8ebc32e97bacebca
7
- data.tar.gz: 64b1200212abc514a4f7755aa07772e91b7d44c3701bcf43ec1c7949c55cf2881ab482965c003384f27bf8d55a33eb09515f20eb90811855f3c8dcd095b360b0
6
+ metadata.gz: 0cd9646a68f5b3aacba56b4cd89f956e86acd345038bf6445ed37f7496e3aeb315749096015caae946040208c4272e461838670a005a14bf0314ceb34308af37
7
+ data.tar.gz: 08d39d78a5fe06176a1f98f7de46015985e599204ee9bd4fee280f2e51581b7398635373b902d082b723ad66bac81f2912abf3586985bdd5d5125904b246fb35
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'capistrano', '~> 3.4'
4
+ gem 'activesupport', '>= 3.0'
4
5
  group :development do
5
6
  gem 'bundler', '~> 1.7'
6
7
  gem 'jeweler', '~> 2.0'
data/Gemfile.lock CHANGED
@@ -1,6 +1,12 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ activesupport (4.2.0)
5
+ i18n (~> 0.7)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.3, >= 0.3.4)
9
+ tzinfo (~> 1.1)
4
10
  addressable (2.3.7)
5
11
  builder (3.2.2)
6
12
  capistrano (3.4.0)
@@ -33,8 +39,10 @@ GEM
33
39
  nokogiri (>= 1.5.10)
34
40
  rake
35
41
  rdoc
42
+ json (1.8.2)
36
43
  jwt (1.4.1)
37
44
  mini_portile (0.6.2)
45
+ minitest (5.5.1)
38
46
  multi_json (1.11.0)
39
47
  multi_xml (0.5.5)
40
48
  multipart-post (2.0.0)
@@ -57,11 +65,14 @@ GEM
57
65
  net-scp (>= 1.1.2)
58
66
  net-ssh (>= 2.8.0)
59
67
  thread_safe (0.3.5)
68
+ tzinfo (1.2.2)
69
+ thread_safe (~> 0.1)
60
70
 
61
71
  PLATFORMS
62
72
  ruby
63
73
 
64
74
  DEPENDENCIES
75
+ activesupport (>= 3.0)
65
76
  bundler (~> 1.7)
66
77
  capistrano (~> 3.4)
67
78
  jeweler (~> 2.0)
data/README.md CHANGED
@@ -6,32 +6,38 @@ Note: This has been updated to support Capistrano >= 3.4. If you still use Capis
6
6
 
7
7
  ## Versioning
8
8
 
9
- This gem stays at 3.x for capistrano 3, as it seems logical.
9
+ Use 3.x for capistrano 3
10
10
 
11
- ## Sudoing
11
+ For capistrano2, see the capistrano2 branch (will not be updated)
12
12
 
13
- The setup process requires sudo on some files and folders upon creation.
13
+ ## Usage
14
+
15
+ You are unlikely to require this library without any of the libraries
16
+ depending on it.
14
17
 
15
- You must either do the job manually or add this to the sudoers file:
18
+ But if you do require only Runit and Monit capistrano helpers, add this to your Gemfile in the development section.
16
19
 
20
+ ```ruby
21
+ gem 'capistrano-runit_monit', require: false
17
22
  ```
18
- Cmnd_Alias RUNITCAPISTRANO = ,
19
- deploy ALL=NOPASSWD: /bin/chmod u+x /etc/sv/*
20
- deploy ALL=NOPASSWD: /bin/chmod g+x /etc/sv/*
21
- deploy ALL=NOPASSWD: /bin/chown deploy\:root /etc/sv/*
22
- deploy ALL=NOPASSWD: /bin/chown -R deploy\:root /etc/sv/*
23
- deploy ALL=NOPASSWD: /bin/chown -R deploy\:root /etc/service/*
24
- deploy ALL=NOPASSWD: /bin/chown -R syslog\:syslog /var/log/service*
25
- deploy ALL=NOPASSWD: /bin/mkdir -p /etc/service/*
26
- deploy ALL=NOPASSWD: /bin/mkdir /etc/service/*
27
- deploy ALL=NOPASSWD: /bin/mkdir -p /var/log/service*
28
- deploy ALL=NOPASSWD: /bin/mkdir -p /etc/sv/*
29
- deploy ALL=NOPASSWD: /bin/mkdir /etc/sv/*
30
- deploy ALL=NOPASSWD: /bin/rm -rf /etc/service/*
31
23
 
24
+ In your Capfile:
25
+
26
+ ```ruby
27
+ require 'capistrano/monit'
28
+ require 'capistrano/runit'
32
29
  ```
33
- ,/bin/chown myuser:mygroup /var/www/html/*,/bin/chmod 755 /var/www/html2/myapp/*.txt
34
30
 
31
+ ## Sudoing
32
+
33
+ The setup process requires sudo on some files and folders upon creation.
34
+
35
+ You should run the following commands to get the proper list for entries to be created in /etc/sudoers.d
36
+
37
+ ```
38
+ cap production runit:sudoers
39
+ cap production monit:sudoers
40
+ ```
35
41
 
36
42
  ## Services for Monit and Runit
37
43
 
@@ -75,8 +81,8 @@ You can add this to deploy.rb or env.rb in order to automatically monitor/unmoni
75
81
  It is important to unmonitor tasks while deploying as they can trigger stops/restarts to the app that monit thinks are "crashes"
76
82
 
77
83
  ```ruby
78
- before "deploy:started", "monit:unmonitor"
79
- after "deploy:finished", "monit:monitor"
84
+ before 'deploy:updating', 'monit:unmonitor'
85
+ after 'deploy:finished', 'monit:monitor'
80
86
  ```
81
87
 
82
88
  If you want monit to automatically start/stop runit instead of triggering seperately
@@ -105,8 +111,15 @@ cap runit:stop # Stop all runit services for current applicatio
105
111
  You can add this to deploy.rb or env.rb in order to automatically start/stop tasks
106
112
 
107
113
  ```ruby
108
- before "deploy", "runit:stop"
109
- after "deploy", "runit:start"
114
+ before "deploy:updating", "runit:stop"
115
+ after "deploy:finished", "runit:start"
116
+ ```
117
+
118
+ Or just before finishing the update:
119
+
120
+ ```ruby
121
+ before "deploy:finished", "runit:stop"
122
+ after "deploy:finished", "runit:start"
110
123
  ```
111
124
 
112
125
  See each gem if you want to start/stop each service separate instead of together.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.0.1
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: capistrano-monit_runit 3.0.0 ruby lib
5
+ # stub: capistrano-monit_runit 3.0.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "capistrano-monit_runit"
9
- s.version = "3.0.0"
9
+ s.version = "3.0.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Leif Ringstad"]
14
- s.date = "2015-03-13"
14
+ s.date = "2015-03-26"
15
15
  s.description = "Helpers for capistrano recipes using runit/monit."
16
16
  s.email = "leifcr@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -54,15 +54,18 @@ Gem::Specification.new do |s|
54
54
 
55
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
56
  s.add_runtime_dependency(%q<capistrano>, ["~> 3.4"])
57
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0"])
57
58
  s.add_development_dependency(%q<bundler>, ["~> 1.7"])
58
59
  s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
59
60
  else
60
61
  s.add_dependency(%q<capistrano>, ["~> 3.4"])
62
+ s.add_dependency(%q<activesupport>, [">= 3.0"])
61
63
  s.add_dependency(%q<bundler>, ["~> 1.7"])
62
64
  s.add_dependency(%q<jeweler>, ["~> 2.0"])
63
65
  end
64
66
  else
65
67
  s.add_dependency(%q<capistrano>, ["~> 3.4"])
68
+ s.add_dependency(%q<activesupport>, [">= 3.0"])
66
69
  s.add_dependency(%q<bundler>, ["~> 1.7"])
67
70
  s.add_dependency(%q<jeweler>, ["~> 2.0"])
68
71
  end
@@ -1,60 +1,66 @@
1
- module Capistrano
2
- module Helpers
3
- ##
4
- # Helper functions for both runit and monit
5
- module Base
6
- def user_app_env_underscore
7
- "#{fetch(:user)}_#{fetch(:application)}_#{environment}"
8
- end
9
-
10
- def user_app_env_underscore_short
11
- "#{fetch(:user)[0...1]}_#{environment[0...1]}_#{fetch(:application)}"
12
- end
13
-
14
- def user_app_env_underscore_short_char_safe
15
- user_app_env_underscore_short.gsub!('-', '_')
16
- end
17
-
18
- ##
19
- # Automatically sets the environment based on presence of
20
- # :stage (multistage)
21
- # :rails_env
22
- # RAILS_ENV variable;
23
- #
24
- # Defaults to "production" if not found
25
- #
26
- def environment # rubocop:disable Metrics/MethodLength
27
- if !fetch(:rails_env).nil?
28
- fetch(:rails_env)
29
- elsif !fetch(:rack_env).nil?
30
- fetch(:rack_env)
31
- elsif !fetch(:stage).nil?
32
- fetch(:stage)
33
- else
34
- info '---------------------------------------------------------------'
35
- info '- Stage, rack or rails environment isn\'t set in -'
36
- info '- :stage, :rails_env or :rack_env, defaulting to \'production\' -'
37
- info '---------------------------------------------------------------'
38
- 'production'
39
- end
40
- end
41
-
42
- def template_to_s_io(template_file)
43
- fail "Cannot find templte #{template_file}" unless File.exist?(template_file)
44
- StringIO.new(ERB.new(File.read(template_file)).result(binding))
45
- end
46
-
47
- ##
48
- # Execute a rake taske using the proper env.
49
- # run_rake db:migrate
50
- #
51
- def run_rake(task)
52
- within(current_path) do
53
- with rails_env: fetch(:rails_env) do
54
- execute :rake, "#{task}"
55
- end
56
- end
57
- end
58
- end
59
- end
60
- end
1
+ require 'active_support'
2
+ require 'active_support/core_ext/string/filters'
3
+ module Capistrano
4
+ module Helpers
5
+ ##
6
+ # Helper functions for both runit and monit
7
+ module Base
8
+ def user_app_env_underscore
9
+ "#{fetch(:user)}_#{fetch(:application)}_#{environment}".squish.downcase.gsub(/[\s|-]/, '_')
10
+ end
11
+
12
+ def user_app_env_underscore_short
13
+ "#{fetch(:user)[0...1]}_#{environment[0...1]}_#{fetch(:application)}".squish.downcase.gsub(/[\s|-]/, '_')
14
+ end
15
+
16
+ def user_app_env_underscore_short_char_safe
17
+ user_app_env_underscore_short.squish.downcase.gsub(/[\s|-]/, '_')
18
+ end
19
+
20
+ def app_env_underscore
21
+ "#{fetch(:application)}_#{environment}".squish.downcase.gsub(/[\s|-]/, '_')
22
+ end
23
+
24
+ ##
25
+ # Automatically sets the environment based on presence of
26
+ # :stage (multistage)
27
+ # :rails_env
28
+ # RAILS_ENV variable;
29
+ #
30
+ # Defaults to "production" if not found
31
+ #
32
+ def environment # rubocop:disable Metrics/MethodLength
33
+ if !fetch(:rails_env).nil?
34
+ fetch(:rails_env)
35
+ elsif !fetch(:rack_env).nil?
36
+ fetch(:rack_env)
37
+ elsif !fetch(:stage).nil?
38
+ fetch(:stage)
39
+ else
40
+ info '---------------------------------------------------------------'
41
+ info '- Stage, rack or rails environment isn\'t set in -'
42
+ info '- :stage, :rails_env or :rack_env, defaulting to \'production\' -'
43
+ info '---------------------------------------------------------------'
44
+ 'production'
45
+ end
46
+ end
47
+
48
+ def template_to_s_io(template_file)
49
+ fail "Cannot find template #{template_file}" unless File.exist?(template_file)
50
+ StringIO.new(ERB.new(File.read(template_file)).result(binding))
51
+ end
52
+
53
+ ##
54
+ # Execute a rake taske using the proper env.
55
+ # run_rake db:migrate
56
+ #
57
+ def run_rake(task)
58
+ within(current_path) do
59
+ with rails_env: fetch(:rails_env) do
60
+ execute :rake, "#{task}"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -34,13 +34,13 @@ module Capistrano
34
34
  #
35
35
  # This will symlink the service to enabled service, but not start or reload monit configuration
36
36
  #
37
- def enable_service(service_conf_filename)
38
- return unless test("[ -h #{File.join(c.fetch(:monit_enabled_path), service_conf_filename)} ]")
39
- execute :ln, "-sf #{File.join(c.fetch(:monit_available_path), service_conf_filename)} #{File.join(c.fetch(:monit_enabled_path), service_conf_filename)}" # rubocop:disable Metrics/LineLength:
37
+ def enable_monitor(service_conf_filename)
38
+ return unless test("[ ! -h #{File.join(fetch(:monit_enabled_path), service_conf_filename)} ]")
39
+ execute :ln, "-sf #{File.join(fetch(:monit_available_path), service_conf_filename)} #{File.join(fetch(:monit_enabled_path), service_conf_filename)}" # rubocop:disable Metrics/LineLength:
40
40
  end
41
41
 
42
- def disable_service(service_conf_filename)
43
- execute :rm, "-f #{File.join(c.fetch(:monit_enabled_path), service_conf_filename)}"
42
+ def disable_monitor(service_conf_filename)
43
+ execute :rm, "-f #{File.join(fetch(:monit_enabled_path), service_conf_filename)}"
44
44
  end
45
45
  end
46
46
  end
@@ -3,7 +3,7 @@ module Capistrano
3
3
  module Runit
4
4
  # Any command sent to this function controls _all_ services related to the app
5
5
  def runit_app_services_control(command)
6
- return unless test("[ ! -h #{runit_etc_service_app_symlink_name} ]")
6
+ return unless test("[ -h '#{runit_etc_service_app_symlink_name}' ]")
7
7
  execute :sudo, :sv, "#{command} #{runit_etc_service_app_symlink_name}"
8
8
  end
9
9
 
@@ -25,8 +25,8 @@ module Capistrano
25
25
  # control_service(service_name, "restart")
26
26
  # end
27
27
 
28
- def control_service(service_name, command, arguments, _ignore_error = false)
29
- return unless test "[ ! -h #{runit_service_path(service_name)}/run ]"
28
+ def control_service(service_name, command, arguments = '', _ignore_error = false)
29
+ return unless test "[ -h '#{runit_service_path(service_name)}/run' ]"
30
30
  execute :sv, "#{arguments} #{command} #{runit_service_path(service_name)}"
31
31
  end
32
32
 
@@ -36,17 +36,20 @@ module Capistrano
36
36
  end
37
37
 
38
38
  def disable_service(service_name)
39
- force_control_service(service_name, 'force-stop', '', true) # force-stop the service before disabling it
39
+ begin
40
+ force_control_service(service_name, 'force-stop', '', true) # force-stop the service before disabling it
41
+ rescue
42
+ end
40
43
  within(runit_service_path(service_name)) do
41
- execute :rm, '-f ./run' if test '[ ! -h ./run ]'
42
- execute :rm, '-f ./finish' if test '[ ! -h ./finish ]'
44
+ execute :rm, '-f ./run' if test "[ -h '#{runit_service_run_file(service_name)}' ]"
45
+ execute :rm, '-f ./finish' if test "[ -h '#{runit_service_finish_file(service_name)}' ]"
43
46
  end
44
47
  end
45
48
 
46
49
  def enable_service(service_name)
47
50
  within(runit_service_path(service_name)) do
48
- execute :ln, "-sf #{runit_service_run_config_file} ./run" if test '[ -h ./run ]'
49
- execute :ln, "-sf #{runit_service_finish_config_file} ./finish" if test '[ -h ./finish ]'
51
+ execute :ln, "-sf #{runit_service_run_config_file(service_name)} ./run" if test "[ ! -h '#{runit_service_run_file(service_name)}' ]"
52
+ execute :ln, "-sf #{runit_service_finish_config_file(service_name)} ./finish" if test "[ ! -h '#{runit_service_finish_file(service_name)}' ]"
50
53
  end
51
54
  end
52
55
 
@@ -55,21 +58,19 @@ module Capistrano
55
58
  end
56
59
 
57
60
  def runit_set_executable_files(service_name) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
58
- if test("[ -f '#{runit_service_run_config_file(service_name)}']")
61
+ if test("[ -f '#{runit_service_run_config_file(service_name)}' ]")
59
62
  execute :chmod, "775 #{runit_service_run_config_file(service_name)}"
60
63
  end
61
- if test("[ -f '#{runit_service_finish_config_file(service_name)}']")
62
- execute :chmod, "775 #{runit_service_finish_config_file(service_name)}"
64
+ if test("[ -f '#{runit_service_finish_config_file(service_name)}' ]")
65
+ execute :chmod, "775 #{runit_service_finish_config_file (service_name)}"
63
66
  end
64
67
 
65
- if test("[ -f '#{runit_service_log_run_file(service_name)}']")
68
+ if test("[ -f '#{runit_service_log_run_file(service_name)}' ]")
66
69
  execute :chmod, "775 #{runit_service_log_run_file(service_name)}"
67
70
  end
68
71
 
69
- if test("[ -d '#{runit_service_control_path(service_name)}']") # rubocop:disable Style/GuardClause
72
+ if test("[ -d '#{runit_service_control_path(service_name)}' ]") # rubocop:disable Style/GuardClause
70
73
  execute :chmod, "775 -R #{runit_service_control_path(service_name)}"
71
- # execute :chmod, 'u+x -R runit_service_control_path(service_name)'
72
- # execute :chmod, 'g+x -R runit_service_control_path(service_name)'
73
74
  end
74
75
  end
75
76
 
@@ -7,6 +7,11 @@
7
7
  # Let monit monitor any long-running processes to ensure they keep
8
8
  # within the limits set by you.
9
9
 
10
+ require 'capistrano/dsl/base_paths'
11
+ require 'capistrano/dsl/monit_paths'
12
+ require 'capistrano/helpers/base'
13
+ require 'capistrano/helpers/monit'
14
+
10
15
  include Capistrano::DSL::BasePaths
11
16
  include Capistrano::DSL::MonitPaths
12
17
  include Capistrano::Helpers::Base
@@ -28,37 +33,24 @@ namespace :load do
28
33
  set :monit_httpd_signature, 'enable' # or enable
29
34
  set :monit_httpd_port, '2812'
30
35
 
31
- set :monit_daemon_time, '60'
32
- set :monit_start_delay, '60'
36
+ set :monit_daemon_time, '30'
37
+ set :monit_start_delay, '30'
33
38
 
34
39
  set :monit_monitrc_template, File.join(File.expand_path(File.join(File.dirname(__FILE__), '../../../templates', 'monit')), 'monitrc.erb') # rubocop:disable Metrics/LineLength:
35
40
  set :monit_application_conf_template, File.join(File.expand_path(File.join(File.dirname(__FILE__), '../../../templates', 'monit')), 'app_include.conf.erb') # rubocop:disable Metrics/LineLength:
36
41
 
37
42
  set :monit_application_conf_file, proc { File.join(fetch(:monit_dir), 'monit.conf') }
43
+
44
+ set :monit_event_dir, File.join('/var', 'run', 'monit')
38
45
  end
39
46
  end
40
47
 
41
48
  namespace :monit do
42
- desc 'Setup monit for the application'
43
- task :setup do
44
- on roles(:app) do |host|
45
- info "MONIT: Setting up initial monit configuration on #{host}"
46
- if test "[ ! -d #{fetch(:monit_dir)} ]"
47
- execute :mkdir, "-p #{fetch(:monit_dir)}"
48
- end
49
- if test "[ ! -d #{fetch(:monit_available_path)} ]"
50
- execute :mkdir, "-p #{fetch(:monit_available_path)}"
51
- end
52
- if test "[ ! -d #{fetch(:monit_enabled_path)} ]"
53
- execute :mkdir, "-p #{fetch(:monit_enabled_path)}"
54
- end
55
- end
56
- end
57
-
58
49
  desc 'Get the config needed to add to sudoers'
59
50
  task :sudoers do
60
51
  run_locally do
61
52
  info '---------------ENTRIES FOR SUDOERS (Monit)---------------------'
53
+ puts "# Sudo monit entries for #{fetch(:application)}"
62
54
  puts "#{fetch(:user)} ALL=NOPASSWD: /bin/chmod 0700 #{monit_monitrc_file}"
63
55
  puts "#{fetch(:user)} ALL=NOPASSWD: /bin/chmod 0775 #{monit_etc_path}"
64
56
  puts "#{fetch(:user)} ALL=NOPASSWD: /bin/chmod 0700 #{monit_etc_path}"
@@ -70,22 +62,43 @@ namespace :monit do
70
62
  puts "#{fetch(:user)} ALL=NOPASSWD: /bin/chown root\\:root #{monit_monitrc_file}"
71
63
  puts "#{fetch(:user)} ALL=NOPASSWD: /usr/bin/monit *"
72
64
  puts "#{fetch(:user)} ALL=NOPASSWD: /usr/sbin/service monit *"
65
+ puts "#{fetch(:user)} ALL=NOPASSWD: /bin/mkdir -p #{fetch(:monit_event_dir)}"
73
66
  info '---------------------------------------------------------------'
74
67
  end
75
68
  # info "#{fetch(:user)} ALL=NOPASSWD: /bin/chown deploy:root #{monit_monitrc_file}"
76
69
  end
77
70
 
71
+ desc 'Setup monit for the application'
72
+ task :setup do
73
+ on roles(:app) do |host|
74
+ info "MONIT: Setting up initial monit configuration on #{host}"
75
+ if test "[ ! -d #{fetch(:monit_dir)} ]"
76
+ execute :mkdir, "-p #{fetch(:monit_dir)}"
77
+ end
78
+ if test "[ ! -d #{fetch(:monit_available_path)} ]"
79
+ execute :mkdir, "-p #{fetch(:monit_available_path)}"
80
+ end
81
+ if test "[ ! -d #{fetch(:monit_enabled_path)} ]"
82
+ execute :mkdir, "-p #{fetch(:monit_enabled_path)}"
83
+ end
84
+
85
+ if test("[ ! -d #{monit_etc_conf_d_path} ]")
86
+ execute :sudo, :mkdir, "-p #{monit_etc_conf_d_path}"
87
+ end
88
+ execute :sudo, :chmod, "6775 #{monit_etc_conf_d_path}"
89
+ execute :sudo, :chown, "#{fetch(:user)}:root #{monit_etc_conf_d_path}"
90
+
91
+ # Upload application global monit include file
92
+ upload! template_to_s_io(fetch(:monit_application_conf_template)), fetch(:monit_application_conf_file)
93
+ end
94
+ end
95
+
78
96
  desc 'Setup main monit config file (/etc/monit/monitrc)'
79
97
  task :main_config do
80
98
  on roles(:app) do |host|
81
99
  set :createmonitrc, ask("Create #{monit_monitrc_file} [Y/n]", 'Y')
82
100
  if fetch(:createmonitrc) == 'Y'
83
101
  info "MONIT: Creating #{monit_monitrc_file} on #{host}"
84
- if test("[ ! -d #{monit_etc_conf_d_path} ]")
85
- execute :sudo, :mkdir, "-p #{monit_etc_conf_d_path}"
86
- execute :sudo, :chmod, "6775 #{monit_etc_conf_d_path}"
87
- execute :sudo, :chown, "#{fetch(:user)}:root #{monit_etc_conf_d_path}"
88
- end
89
102
  execute :sudo, :chown, "#{fetch(:user)}:root #{monit_etc_path}"
90
103
  execute :sudo, :chmod, "0775 #{monit_etc_path}"
91
104
  execute :sudo, :chown, "#{fetch(:user)}:root #{monit_monitrc_file}"
@@ -93,6 +106,7 @@ namespace :monit do
93
106
  execute :sudo, :chmod, "0700 #{monit_monitrc_file}"
94
107
  execute :sudo, :chown, "root:root #{monit_monitrc_file}"
95
108
  execute :sudo, :service, 'monit restart'
109
+ execute :sudo, :mkdir, "-p #{fetch(:monit_event_dir)}"
96
110
  info "MONIT: Sleeping for #{fetch(:monit_start_delay).to_i} seconds to wait for monit to be ready"
97
111
  sleep(fetch(:monit_start_delay).to_i)
98
112
  end
@@ -36,6 +36,7 @@ namespace :runit do
36
36
  task :sudoers do
37
37
  run_locally do
38
38
  info '---------------ENTRIES FOR SUDOERS (Runit)---------------------'
39
+ puts "# Sudo runit entries for #{fetch(:application)}"
39
40
  puts "#{fetch(:user)} ALL=NOPASSWD: /bin/mkdir -p #{runit_user_base_path}"
40
41
  puts "#{fetch(:user)} ALL=NOPASSWD: /bin/chown #{fetch(:user)}\\:root #{runit_user_base_path}"
41
42
  puts "#{fetch(:user)} ALL=NOPASSWD: /bin/chmod 6775 #{runit_user_base_path}"
@@ -71,16 +72,13 @@ namespace :runit do
71
72
  on roles(:app) do |host|
72
73
  # set :pw, ask("Sudo password", '')
73
74
  # execute :echo, "#{fetch(:pw)} | sudo -S ls /"
74
- if test("[ ! -d '#{runit_user_base_path}' ]")
75
- execute :sudo, :mkdir, "-p '#{runit_user_base_path}'"
76
- execute :sudo, :chown, "#{fetch(:user)}:root '#{runit_user_base_path}'"
77
- execute :sudo, :chmod, "6775 '#{runit_user_base_path}'"
78
- end
79
- if test("[ ! -d '#{runit_etc_service_path}' ]")
80
- execute :sudo, :mkdir, "-p '#{runit_etc_service_path}'"
81
- execute :sudo, :chown, "#{fetch(:user)}:root '#{runit_etc_service_path}'"
82
- execute :sudo, :chmod, "6775 '#{runit_etc_service_path}'"
83
- end
75
+ execute :sudo, :mkdir, "-p '#{runit_user_base_path}'" if test("[ ! -d '#{runit_user_base_path}' ]")
76
+ execute :sudo, :chown, "#{fetch(:user)}:root '#{runit_user_base_path}'"
77
+ execute :sudo, :chmod, "6775 '#{runit_user_base_path}'"
78
+
79
+ execute :sudo, :mkdir, "-p '#{runit_etc_service_path}'" if test("[ ! -d '#{runit_etc_service_path}' ]")
80
+ execute :sudo, :chown, "#{fetch(:user)}:root '#{runit_etc_service_path}'"
81
+ execute :sudo, :chmod, "6775 '#{runit_etc_service_path}'"
84
82
  within("#{runit_user_base_path}") do
85
83
  execute :mkdir, "-p #{app_env_folder}"
86
84
  end
@@ -113,6 +111,13 @@ namespace :runit do
113
111
  info "RUNIT: Created inital runit log services in #{runit_base_log_path} for #{fetch(:application)} on #{host}"
114
112
  end
115
113
  end
114
+ # '[INTERNAL] create /etc/sv folders and upload base templates needed'
115
+ task :runit_ensure_shared_sockets_and_pids_folders do
116
+ on roles(:app) do |host|
117
+ execute :mkdir, fetch(:pids_path) if test("[ ! -d #{fetch(:pids_path)} ]")
118
+ execute :mkdir, fetch(:sockets_path) if test("[ ! -d #{fetch(:sockets_path)} ]")
119
+ end
120
+ end
116
121
  end
117
122
 
118
123
  desc 'Disable runit services for application'
@@ -148,19 +153,14 @@ namespace :runit do
148
153
  end
149
154
  end
150
155
 
151
- desc 'Stop all runit services for current application'
152
- task :stop do
153
- runit_app_services_control('stop')
154
- end
155
-
156
- desc 'Start all runit services for current application'
157
- task :start do
158
- runit_app_services_control('start')
159
- end
160
-
161
- desc 'Only start services once. Will not restart if they fail.'
162
- task :once do
163
- runit_app_services_control('once')
156
+ %w(stop start once restart).each do |single_cmd|
157
+ desc "#{single_cmd} runit services for application"
158
+ task single_cmd.to_sym do
159
+ on roles(:app) do |host|
160
+ info "RUNIT: #{single_cmd} on #{host}"
161
+ runit_app_services_control(single_cmd)
162
+ end
163
+ end
164
164
  end
165
165
  end
166
166
 
@@ -170,3 +170,4 @@ after 'deploy:updated', 'runit:enable'
170
170
  # after 'deploy:setup', 'runit:setup'
171
171
  after 'runit:setup', 'runit:setup:runit_create_app_services'
172
172
  after 'runit:setup:runit_create_app_services', 'runit:setup:runit_create_app_log_services'
173
+ after 'runit:setup:runit_create_app_services', 'runit:setup:runit_ensure_shared_sockets_and_pids_folders'
@@ -8,8 +8,8 @@ set statefile /var/lib/monit/state
8
8
  set idfile /var/lib/monit/id
9
9
 
10
10
  set eventqueue
11
- basedir /var/monit # set the base directory where events will be stored
12
- slots 100 # optionaly limit the queue size
11
+ basedir <%= fetch(:monit_event_dir) %> # set the base directory where events will be stored
12
+ slots 100 # optionaly limit the queue size
13
13
 
14
14
  <%= fetch(:mail_alert_settings) %>
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-monit_runit
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leif Ringstad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-13 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement