pvcglue 0.1.25 → 0.1.26

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: 4d8e13eb849237295d92d5608720ebac8aa8d285
4
- data.tar.gz: c33ef05585ffdda58c213a6bf38bea055804ca83
3
+ metadata.gz: 04b3f92f71e7038cd74f78ac832f0d93604cd2dc
4
+ data.tar.gz: e4cf248f20b858e705e2f81496f59f1557c0d428
5
5
  SHA512:
6
- metadata.gz: 94387410ece82c63f531436d92e7616a43403a1d33d8a5cb6e3842dd8d14160718321862f3ab378e6cc510b16fd2a78712f2cee3ba72efc534ae99f74f9add78
7
- data.tar.gz: 6ccf6339855e66c432a13d09084d0f3abc934f0fc55b75141b40291878f33017d8232567febb939724bd38b7a716c869379c050fa9f3e2941c6a82829aa66248
6
+ metadata.gz: ad1bd550284cb3b4e7d59e980b7e14b4845d7d8a1185afdd832723914fe12cce6dd1a666e74bb4d6852cadc11e1ddf355cae17963c057291ec760b5cfa233da1
7
+ data.tar.gz: 71422b3c7ae4b4396b61018d4bdbb2ca57b1e59072bd3a2289b29523584be371808a0285d04b65bf63ecff05a803d7f1735221ca1a52284a55375a9d1de177e0
@@ -11,8 +11,10 @@ require "pvcglue/deploy"
11
11
  require "pvcglue/capistrano"
12
12
  require "pvcglue/ssl"
13
13
  require "pvcglue/db"
14
- require "pvcglue/toml_pvc_dumper.rb"
15
- require "pvcglue/local.rb"
14
+ require "pvcglue/toml_pvc_dumper"
15
+ require "pvcglue/local"
16
+ require "pvcglue/monit"
17
+ require "pvcglue/pvcify"
16
18
  require "tilt"
17
19
 
18
20
  # puts File.join(File.dirname(__FILE__), 'pvcglue', 'packages', '*.rb')
@@ -59,7 +59,7 @@ module Pvcglue
59
59
  # puts node.inspect
60
60
  puts "Connection to #{node_name} (#{node_data[:public_ip]}) as user 'deploy'..."
61
61
  working_dir = Pvcglue.cloud.deploy_to_app_current_dir
62
- system(%(ssh -t deploy@#{node_data[:public_ip]} "cd #{working_dir} && echo 'Starting #{options[:stage].upcase} Rails console in #{working_dir}' && RAILS_ENV=#{options[:stage].downcase} script/rails c"))
62
+ system(%(ssh -t deploy@#{node_data[:public_ip]} "cd #{working_dir} && echo 'Starting #{options[:stage].upcase} Rails console in #{working_dir}' && bundle exec rails c #{options[:stage].downcase}"))
63
63
 
64
64
  end
65
65
 
@@ -170,8 +170,7 @@ module Pvcglue
170
170
  method_option :stage, :required => true, :aliases => "-s"
171
171
 
172
172
  def pvcify
173
- Pvcglue::Capistrano.capify
174
- Pvcglue::Db.configure_database_yml
173
+ Pvcglue::Pvcify.run
175
174
  end
176
175
 
177
176
  desc "start", "start local virtual machines (build first, if required)"
@@ -27,6 +27,11 @@ module Pvcglue
27
27
  @current_node
28
28
  end
29
29
 
30
+ def current_node_data
31
+ current_node.values.first
32
+ end
33
+
34
+
30
35
  def current_hostname
31
36
  raise "Current current_hostname not set." if @current_hostname.nil?
32
37
  @current_hostname
@@ -122,6 +127,10 @@ module Pvcglue
122
127
  File.join(deploy_to_app_dir, 'shared')
123
128
  end
124
129
 
130
+ def deploy_to_app_shared_pids_dir
131
+ File.join(deploy_to_app_shared_dir, 'pids')
132
+ end
133
+
125
134
  def env_file_name
126
135
  File.join(deploy_to_app_shared_dir, ".env.#{stage_name_validated}")
127
136
  end
@@ -130,6 +139,10 @@ module Pvcglue
130
139
  File.join(deploy_to_app_current_dir, 'public')
131
140
  end
132
141
 
142
+ def deploy_to_app_current_bin_dir
143
+ File.join(deploy_to_app_current_dir, Pvcglue.configuration.rails_bin_dir)
144
+ end
145
+
133
146
  def maintenance_files_dir
134
147
  File.join(deploy_to_app_dir, 'maintenance')
135
148
  end
@@ -301,6 +314,16 @@ module Pvcglue
301
314
  puts "Setting port_in_node_context to #{@port_in_node_context}"
302
315
  @port_in_node_context
303
316
  end
317
+
318
+ def delayed_job_worker_count
319
+ return 0 unless gems[:delayed_job]
320
+ (stage[:delayed_job_workers] || 1).to_i
321
+ end
322
+
323
+ def resque_worker_count
324
+ return 0 unless gems[:resque]
325
+ (stage[:resque_workers] || 1).to_i
326
+ end
304
327
  end
305
328
 
306
329
  def self.cloud
@@ -170,6 +170,24 @@ module Pvcglue
170
170
  File.read(ruby_version_file_name).strip
171
171
  end
172
172
 
173
+ def rails_version
174
+ @rails_version ||= begin
175
+ `bundle exec rails -v`.sub('Rails ', '').strip
176
+ end
177
+ end
178
+
179
+ def rails_version_major
180
+ rails_version.split('.').first
181
+ end
182
+
183
+ def rails_bin_dir
184
+ if rails_version_major.to_i >= 4
185
+ 'bin'
186
+ else
187
+ 'script'
188
+ end
189
+ end
190
+
173
191
  def web_app_base_dir
174
192
  '/sites'
175
193
  end
@@ -253,7 +253,7 @@ module Pvcglue
253
253
  end
254
254
  raise "Public IP not found" unless machines[machine][:public_ip]
255
255
  raise "Private IP not found" unless machines[machine][:private_ip]
256
- puts "Adding you public key to the root user for #{machine_name}..."
256
+ puts "Adding your public key to the root user for #{machine_name}..."
257
257
  # cat ~/.ssh/id_rsa.pub | vagrant ssh manager -c 'sudo tee /root/.ssh/authorized_keys'
258
258
  raise $? unless system %Q(cat ~/.ssh/id_rsa.pub | vagrant ssh #{machine_name} -c 'sudo tee /root/.ssh/authorized_keys')
259
259
  end
@@ -0,0 +1,32 @@
1
+ module Pvcglue
2
+ class Monit
3
+ def self.monitify
4
+ Pvcglue.render_template('monit.app.monitrc.erb', monitrc_file_name)
5
+ end
6
+
7
+ def self.monitrc_file_name
8
+ File.join(Pvcglue.configuration.application_dir, 'monitrc')
9
+ end
10
+
11
+ def self.worker_control_name
12
+ "#{Pvcglue.cloud.app_and_stage_name}_worker_control"
13
+ end
14
+
15
+ def self.delayed_job_queue_name(n)
16
+ "#{Pvcglue.cloud.app_and_stage_name}_delayed_job.#{n}"
17
+ end
18
+
19
+ def self.resque_queue_name(n)
20
+ "#{Pvcglue.cloud.app_and_stage_name}_resque_worker.#{n}"
21
+ end
22
+
23
+ def self.resque_pid_file_name(n)
24
+ "#{Pvcglue.cloud.deploy_to_app_shared_pids_dir}/resque_worker.#{n}.pid"
25
+ end
26
+
27
+ def self.safe_name(s)
28
+ s.gsub(/\W/, '_')
29
+ end
30
+
31
+ end
32
+ end
@@ -21,7 +21,7 @@ module Pvcglue
21
21
  end
22
22
  end
23
23
 
24
- Pvcglue::Capistrano.capify
24
+ Pvcglue::Pvcify.run
25
25
 
26
26
  end
27
27
 
@@ -0,0 +1,117 @@
1
+ # check process delayed_job.0
2
+ # with pidfile /sites/pvcglue_dev_box/local/shared/pids/delayed_job.0.pid
3
+ # start program = "/home/deploy/.rvm/bin/rvm-shell -c 'cd /sites/pvcglue_dev_box/local/current && RAILS_ENV=local /sites/pvcglue_dev_box/local/current/bin/delayed_job start -i 0 --pid-dir=/sites/pvcglue_dev_box/local/shared/pids/'" as uid deploy and gid deploy
4
+ # stop program = "/home/deploy/.rvm/bin/rvm-shell -c 'cd /sites/pvcglue_dev_box/local/current && RAILS_ENV=local /sites/pvcglue_dev_box/local/current/bin/delayed_job stop -i 0 --pid-dir=/sites/pvcglue_dev_box/local/shared/pids/'" as uid deploy and gid deploy
5
+ # group delayed
6
+ # depends on deploy_in_progress
7
+ #
8
+ # check file deploy_in_progress with path /sites/pvcglue_dev_box/local/shared/pids/deploying
9
+ # if does not exist then exec "/bin/echo Does not exist" else if succeeded then exec "/bin/echo Exists"
10
+ # # group delayed
11
+ # # if changed timestamp then exec "/bin/echo"
12
+ #
13
+ # check process monit
14
+ # with pidfile /var/run/monit.pid
15
+ # restart program = "/usr/bin/monit reload"
16
+
17
+ # curl http://localhost:2812/monit -d "action=restart"
18
+
19
+ # curl http://localhost:2812/deploy_in_progress -d "action=start"
20
+
21
+ # For development
22
+ #
23
+ # Stop the service:
24
+ # sudo service monit stop
25
+ #
26
+ # Run it manually:
27
+ # sudo monit -Iv
28
+ #
29
+ #
30
+ package 'monit-bootstrap' do
31
+ depends_on 'monit-install'
32
+ depends_on 'monit-upstart'
33
+ end
34
+
35
+ package 'monit-install' do
36
+ depends_on 'monit-config-files'
37
+
38
+ validate do
39
+ # next: thanks to http://stackoverflow.com/questions/2325471/using-return-in-a-ruby-block
40
+ next false unless run('monit -V') =~ /5\.14/
41
+ next false unless sudo('monit -t') =~ /Control file syntax OK/
42
+ sudo('monit status') =~ /status\s*Running/
43
+ end
44
+
45
+ apply do
46
+ # Thanks to https://rtcamp.com/tutorials/monitoring/monit/
47
+ sudo 'rm monit-5.14-linux-x64.tar.gz'
48
+ sudo 'wget https://mmonit.com/monit/dist/binary/5.14/monit-5.14-linux-x64.tar.gz'
49
+ sudo 'tar zxvf monit-5.14-linux-x64.tar.gz'
50
+ sudo 'cp ~/monit-5.14/bin/monit /usr/bin/monit'
51
+ sudo 'ln -s /etc/monit/monitrc /etc/monitrc'
52
+ sudo 'mkdir -p /var/lib/monit/'
53
+ sudo 'mkdir -p /etc/monit/conf.d/'
54
+ sudo 'monit quit' # quit 'manually' and then start it as a service (or service monit stop, doesn't)
55
+ sudo 'service monit start'
56
+ end
57
+
58
+ remove do
59
+ raise "removing monit not supported, yet."
60
+ end
61
+ end
62
+
63
+ package 'monit-config-files' do
64
+ file({
65
+ :template => Pvcglue.template_file_name('monit.init.d.erb'),
66
+ :destination => '/etc/init.d/monit',
67
+ :permissions => 0755,
68
+ :user => 'root',
69
+ :group => 'root'
70
+ }) { sudo('service monit restart') }
71
+
72
+ file({
73
+ :template => Pvcglue.template_file_name('monit.monitrc.erb'),
74
+ :destination => '/etc/monit/monitrc',
75
+ :create_dirs => true,
76
+ :permissions => 0700,
77
+ :user => 'root',
78
+ :group => 'root'
79
+ }) { sudo('service monit restart') }
80
+
81
+ file({
82
+ :template => Pvcglue.template_file_name('monit.etc-default.erb'),
83
+ :destination => '/etc/default/monit',
84
+ :permissions => 0644,
85
+ :user => 'root',
86
+ :group => 'root'
87
+ }) {}
88
+ end
89
+
90
+ package 'monit-upstart' do
91
+ depends_on 'monit-upstart-files'
92
+
93
+ validate do
94
+ sudo('initctl status monit') =~ /monit start\/running/
95
+ end
96
+
97
+ apply do
98
+ sudo 'service monit start'
99
+ end
100
+
101
+ remove do
102
+ raise "removing monit not supported, yet."
103
+ end
104
+ end
105
+
106
+ package 'monit-upstart-files' do
107
+ file({
108
+ :template => Pvcglue.template_file_name('monit.upstart-conf.erb'),
109
+ :destination => '/etc/init/monit.conf',
110
+ :permissions => 0644,
111
+ :user => 'root',
112
+ :group => 'root'
113
+ }) { sudo 'initctl reload-configuration' }
114
+
115
+ end
116
+
117
+
@@ -0,0 +1,10 @@
1
+ package 'monit-web' do
2
+ depends_on 'monit-bootstrap'
3
+
4
+ apply do
5
+ #include /etc/monit/conf.d/*
6
+ sudo "ln -s #{Pvcglue.cloud.deploy_to_app_current_dir}/monitrc /etc/monit/conf.d/#{Pvcglue.cloud.app_name}_#{Pvcglue.cloud.stage_name}.conf"
7
+ # sudo 'service monit restart'
8
+ end
9
+ end
10
+
@@ -17,6 +17,7 @@ package 'web' do
17
17
  depends_on 'imagemagick' # TODO: app specific--will need to make system to include extra packages
18
18
  depends_on 'libpq-dev' # for pg gem
19
19
  depends_on 'nodejs'
20
+ depends_on 'monit-web'
20
21
  end
21
22
 
22
23
 
@@ -8,6 +8,8 @@ package 'rvm' do
8
8
 
9
9
  apply do
10
10
  run 'gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3'
11
+ run 'gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3' # Do it again, the first time only sets things up, and does not import the keys
12
+ # run 'curl -sSL https://rvm.io/mpapis.asc | gpg --import -'
11
13
  run '\curl -sSL https://get.rvm.io | bash -s stable --with-default-gems="bundler"'
12
14
  run "rvm requirements"
13
15
  end
@@ -0,0 +1,9 @@
1
+ module Pvcglue
2
+ class Pvcify
3
+ def self.run
4
+ Pvcglue::Monit.monitify
5
+ Pvcglue::Capistrano.capify
6
+ Pvcglue::Db.configure_database_yml
7
+ end
8
+ end
9
+ end
@@ -23,48 +23,77 @@ task :invoke, [:command] => 'deploy:set_rails_env' do |task, args|
23
23
  end
24
24
 
25
25
  namespace :deploy do
26
- <% if Pvcglue.cloud.gems[:delayed_job] %>
27
- def args
28
- fetch(:delayed_job_args, "")
29
- end
30
-
31
- def delayed_job_roles
32
- fetch(:delayed_job_server_role, :app)
33
- end
26
+ <% if Pvcglue.cloud.gems[:delayed_job] || Pvcglue.cloud.gems[:resque] %>
34
27
 
35
- desc 'Stop the delayed_job process'
36
- task :delayed_job_stop do
37
- on roles(delayed_job_roles) do
38
- within release_path do
39
- with rails_env: fetch(:rails_env) do
40
- execute :'script/delayed_job', :stop
41
- end
42
- end
28
+ desc 'Stop the workers'
29
+ task :stop_workers do
30
+ on roles(:app) do
31
+ execute :'curl -sS http://localhost:2812/<%= Pvcglue::Monit.worker_control_name %> -d "action=stop"'
43
32
  end
44
33
  end
45
34
 
46
- desc 'Start the delayed_job process'
47
- task :delayed_job_start do
48
- on roles(delayed_job_roles) do
49
- within release_path do
50
- with rails_env: fetch(:rails_env) do
51
- execute :'script/delayed_job', args, :start
52
- end
53
- end
35
+ desc 'Start the workers'
36
+ task :start_workers do
37
+ on roles(:app) do
38
+ execute :'curl -sS http://localhost:2812/monit_reload -d "action=restart"'
39
+ execute :'sleep 5' # must wait for reload
40
+ execute :'curl -sS http://localhost:2812/<%= Pvcglue::Monit.worker_control_name %> -d "action=start"'
54
41
  end
55
42
  end
56
43
 
57
- desc 'Restart the delayed_job process'
58
- task :delayed_job_restart do
59
- on roles(delayed_job_roles) do
60
- within release_path do
61
- with rails_env: fetch(:rails_env) do
62
- execute :'script/delayed_job', args, :restart
63
- end
64
- end
44
+ desc 'Restart the workers'
45
+ task :restart_workers do
46
+ on roles(:app) do
47
+ execute :'curl -sS http://localhost:2812/monit_reload -d "action=restart"'
48
+ execute :'sleep 5' # must wait for reload
49
+ execute :'curl -sS http://localhost:2812/<%= Pvcglue::Monit.worker_control_name %> -d "action=restart"'
65
50
  end
66
51
  end
67
52
 
53
+ after :started, :stop_workers
54
+ after :publishing, :start_workers
55
+
56
+ # def args
57
+ # fetch(:delayed_job_args, "")
58
+ # end
59
+ #
60
+ # def delayed_job_roles
61
+ # fetch(:delayed_job_server_role, :app)
62
+ # end
63
+ #
64
+ # desc 'Stop the delayed_job process'
65
+ # task :delayed_job_stop do
66
+ # on roles(delayed_job_roles) do
67
+ # within release_path do
68
+ # with rails_env: fetch(:rails_env) do
69
+ # execute :'<%= Pvcglue.configuration.rails_bin_dir %>/delayed_job', :stop
70
+ # end
71
+ # end
72
+ # end
73
+ # end
74
+ #
75
+ # desc 'Start the delayed_job process'
76
+ # task :delayed_job_start do
77
+ # on roles(delayed_job_roles) do
78
+ # within release_path do
79
+ # with rails_env: fetch(:rails_env) do
80
+ # execute :'<%= Pvcglue.configuration.rails_bin_dir %>/delayed_job', args, :start
81
+ # end
82
+ # end
83
+ # end
84
+ # end
85
+ #
86
+ # desc 'Restart the delayed_job process'
87
+ # task :delayed_job_restart do
88
+ # on roles(delayed_job_roles) do
89
+ # within release_path do
90
+ # with rails_env: fetch(:rails_env) do
91
+ # execute :'<%= Pvcglue.configuration.rails_bin_dir %>/delayed_job', args, :restart
92
+ # end
93
+ # end
94
+ # end
95
+ # end
96
+
68
97
  #desc 'Restart Delayed Job'
69
98
  #task :restart_delayed_job do
70
99
  # on roles(:app), in: :sequence, wait: 5 do
@@ -77,7 +106,7 @@ namespace :deploy do
77
106
  #end
78
107
 
79
108
 
80
- after :publishing, :delayed_job_restart # calling this directly is a work-around due to "NoMethodError: undefined method `verbosity'" error when calling task from a task in capistrano 3.1.0 and SSHKit 1.3.0
109
+ # after :publishing, :delayed_job_restart # calling this directly is a work-around due to "NoMethodError: undefined method `verbosity'" error when calling task from a task in capistrano 3.1.0 and SSHKit 1.3.0
81
110
  <% end %>
82
111
 
83
112
  desc 'Restart passenger app'
@@ -0,0 +1,33 @@
1
+ # Used to control the all of the workers that depend on it.
2
+ # Allows workers to be started/stopped without needing root, using the web interface
3
+ #
4
+ # Example
5
+ # curl http://localhost:2812/pvcglue_dev_box_local_control -d "action=start"
6
+ #
7
+
8
+ check file <%= Pvcglue::Monit.worker_control_name %> with path <%= "#{Pvcglue.cloud.deploy_to_app_shared_dir}/worker_control" %>
9
+ # this is a "no-op" so that the default monit actions do not execute
10
+ if does not exist then exec "/bin/true" else if succeeded then exec "/bin/true"
11
+
12
+ <% Pvcglue.cloud.delayed_job_worker_count.times do |n| %>
13
+ check process <%= Pvcglue::Monit.safe_name(Pvcglue::Monit.delayed_job_queue_name(n)) %>
14
+ with pidfile <%= Pvcglue.cloud.deploy_to_app_shared_pids_dir %>/delayed_job.<%= n %>.pid
15
+ start program = "/home/deploy/.rvm/bin/rvm-shell -c 'cd <%= Pvcglue.cloud.deploy_to_app_current_dir %> && RAILS_ENV=<%= Pvcglue.cloud.stage_name %> <%= Pvcglue.cloud.deploy_to_app_current_bin_dir %>/delayed_job start -i <%= n %> --pid-dir=<%= Pvcglue.cloud.deploy_to_app_shared_pids_dir %>'" as uid deploy and gid deploy
16
+ stop program = "/home/deploy/.rvm/bin/rvm-shell -c 'cd <%= Pvcglue.cloud.deploy_to_app_current_dir %> && RAILS_ENV=<%= Pvcglue.cloud.stage_name %> <%= Pvcglue.cloud.deploy_to_app_current_bin_dir %>/delayed_job stop -i <%= n %> --pid-dir=<%= Pvcglue.cloud.deploy_to_app_shared_pids_dir %>'" as uid deploy and gid deploy
17
+ group <%= "#{Pvcglue.cloud.app_and_stage_name}_delayed_job" %>
18
+ group <%= "#{Pvcglue.cloud.app_and_stage_name}_workers" %>
19
+ depends on <%= Pvcglue::Monit.worker_control_name %>
20
+
21
+ <% end %>
22
+
23
+ <% Pvcglue.cloud.resque_worker_count.times do |n| %>
24
+ # Based on https://github.com/resque/resque/blob/master/examples/monit/resque.monit
25
+ check process <%= Pvcglue::Monit.safe_name(Pvcglue::Monit.resque_queue_name(n)) %>
26
+ with pidfile <%= Pvcglue::Monit.resque_pid_file_name(n) %>
27
+ start program = "/home/deploy/.rvm/bin/rvm-shell -c 'cd <%= Pvcglue.cloud.deploy_to_app_current_dir %> && nohup bundle exec rake environment resque:work RAILS_ENV=<%= Pvcglue.cloud.stage_name %> QUEUE=* VERBOSE=1 PIDFILE=<%= Pvcglue::Monit.resque_pid_file_name(n) %> >> log/resque_worker.log 2>&1'" as uid deploy and gid deploy
28
+ stop program = "/bin/sh -c 'kill -9 $(cat <%= Pvcglue::Monit.resque_pid_file_name(n) %>) && rm -f <%= Pvcglue::Monit.resque_pid_file_name(n) %>; exit 0;'" as uid deploy and gid deploy
29
+ group <%= "#{Pvcglue.cloud.app_and_stage_name}_resque" %>
30
+ group <%= "#{Pvcglue.cloud.app_and_stage_name}_workers" %>
31
+ depends on <%= Pvcglue::Monit.worker_control_name %>
32
+
33
+ <% end %>
@@ -0,0 +1,105 @@
1
+ #!/bin/sh
2
+
3
+ ### BEGIN INIT INFO
4
+ # Provides: monit
5
+ # Required-Start: $remote_fs
6
+ # Required-Stop: $remote_fs
7
+ # Should-Start: $all
8
+ # Should-Stop: $all
9
+ # Default-Start: 2 3 4 5
10
+ # Default-Stop: 0 1 6
11
+ # Short-Description: service and resource monitoring daemon
12
+ # Description: monit is a utility for managing and monitoring
13
+ # processes, programs, files, directories and filesystems
14
+ # on a Unix system. Monit conducts automatic maintenance
15
+ # and repair and can execute meaningful causal actions
16
+ # in error situations.
17
+ ### END INIT INFO
18
+
19
+ set -e
20
+
21
+ . /lib/lsb/init-functions
22
+
23
+ DAEMON=/usr/bin/monit
24
+ CONFIG=/etc/monit/monitrc
25
+ NAME=monit
26
+ DESC="daemon monitor"
27
+ MONIT_OPTS=
28
+ PID="/run/$NAME.pid"
29
+
30
+ # Check if DAEMON binary exist
31
+ [ -f $DAEMON ] || exit 0
32
+
33
+ [ -f "/etc/default/$NAME" ] && . /etc/default/$NAME
34
+
35
+ MONIT_OPTS="-c $CONFIG $MONIT_OPTS"
36
+
37
+ monit_not_configured () {
38
+ if [ "$1" != "stop" ]
39
+ then
40
+ printf "\tplease configure $NAME and then edit /etc/default/$NAME\n"
41
+ printf "\tand set the \"START\" variable to \"yes\" in order to allow\n"
42
+ printf "\t$NAME to start\n"
43
+ fi
44
+ exit 0
45
+ }
46
+
47
+ monit_checks () {
48
+ # Check if START variable is set to "yes", if not we exit.
49
+ if [ "$START" != "yes" ]
50
+ then
51
+ monit_not_configured $1
52
+ fi
53
+ }
54
+
55
+ case "$1" in
56
+ start)
57
+ log_daemon_msg "Starting $DESC" "$NAME"
58
+ monit_checks $1
59
+ if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $MONIT_OPTS 1>/dev/null
60
+ then
61
+ log_end_msg 0
62
+ else
63
+ log_end_msg 1
64
+ fi
65
+ ;;
66
+ stop)
67
+ log_daemon_msg "Stopping $DESC" "$NAME"
68
+ if start-stop-daemon --retry TERM/5/KILL/5 --oknodo --stop --quiet --pidfile $PID 1>/dev/null
69
+ then
70
+ log_end_msg 0
71
+ else
72
+ log_end_msg 1
73
+ fi
74
+ ;;
75
+ reload)
76
+ log_daemon_msg "Reloading $DESC configuration" "$NAME"
77
+ if start-stop-daemon --stop --signal HUP --quiet --oknodo --pidfile $PID --exec $DAEMON -- $MONIT_OPTS 1>/dev/null
78
+ then
79
+ log_end_msg 0
80
+ else
81
+ log_end_msg 1
82
+ fi
83
+ ;;
84
+ restart|force-reload)
85
+ log_daemon_msg "Restarting $DESC" "$NAME"
86
+ start-stop-daemon --retry TERM/5/KILL/5 --oknodo --stop --quiet --pidfile $PID 1>/dev/null
87
+ if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $MONIT_OPTS 1>/dev/null
88
+ then
89
+ log_end_msg 0
90
+ else
91
+ log_end_msg 1
92
+ fi
93
+ ;;
94
+ syntax)
95
+ $DAEMON $MONIT_OPTS -t
96
+ ;;
97
+ status)
98
+ status_of_proc -p $PID $DAEMON $NAME
99
+ ;;
100
+ *)
101
+ log_action_msg "Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload|syntax|status}"
102
+ ;;
103
+ esac
104
+
105
+ exit 0
@@ -0,0 +1,279 @@
1
+ ###############################################################################
2
+ ## Monit control file
3
+ ###############################################################################
4
+ ##
5
+ ## Comments begin with a '#' and extend through the end of the line. Keywords
6
+ ## are case insensitive. All path's MUST BE FULLY QUALIFIED, starting with '/'.
7
+ ##
8
+ ## Below you will find examples of some frequently used statements. For
9
+ ## information about the control file and a complete list of statements and
10
+ ## options, please have a look in the Monit manual.
11
+ ##
12
+ ##
13
+ ###############################################################################
14
+ ## Global section
15
+ ###############################################################################
16
+ ##
17
+ ## Start Monit in the background (run as a daemon):
18
+ #
19
+ set daemon 15 # check services at 2-minute intervals
20
+ # set daemon 60 # check services at 2-minute intervals
21
+ # with start delay 240 # optional: delay the first check by 4-minutes (by
22
+ # # default Monit check immediately after Monit start)
23
+ #
24
+ #
25
+ ## Set syslog logging with the 'daemon' facility. If the FACILITY option is
26
+ ## omitted, Monit will use 'user' facility by default. If you want to log to
27
+ ## a standalone log file instead, specify the full path to the log file
28
+ #
29
+ # set logfile syslog facility log_daemon
30
+ set logfile /var/log/monit.log
31
+ #
32
+ #
33
+ ## Set the location of the Monit id file which stores the unique id for the
34
+ ## Monit instance. The id is generated and stored on first Monit start. By
35
+ ## default the file is placed in $HOME/.monit.id.
36
+ #
37
+ # set idfile /var/.monit.id
38
+ set idfile /var/lib/monit/id
39
+ #
40
+ ## Set the location of the Monit state file which saves monitoring states
41
+ ## on each cycle. By default the file is placed in $HOME/.monit.state. If
42
+ ## the state file is stored on a persistent filesystem, Monit will recover
43
+ ## the monitoring state across reboots. If it is on temporary filesystem, the
44
+ ## state will be lost on reboot which may be convenient in some situations.
45
+ #
46
+ set statefile /var/lib/monit/state
47
+ #
48
+ ## Set the list of mail servers for alert delivery. Multiple servers may be
49
+ ## specified using a comma separator. If the first mail server fails, Monit
50
+ # will use the second mail server in the list and so on. By default Monit uses
51
+ # port 25 - it is possible to override this with the PORT option.
52
+ #
53
+ # set mailserver mail.bar.baz, # primary mailserver
54
+ # backup.bar.baz port 10025, # backup mailserver on port 10025
55
+ # localhost # fallback relay
56
+ #
57
+ #
58
+ ## By default Monit will drop alert events if no mail servers are available.
59
+ ## If you want to keep the alerts for later delivery retry, you can use the
60
+ ## EVENTQUEUE statement. The base directory where undelivered alerts will be
61
+ ## stored is specified by the BASEDIR option. You can limit the maximal queue
62
+ ## size using the SLOTS option (if omitted, the queue is limited by space
63
+ ## available in the back end filesystem).
64
+ #
65
+ set eventqueue
66
+ basedir /var/lib/monit/events # set the base directory where events will be stored
67
+ slots 100 # optionally limit the queue size
68
+ #
69
+ #
70
+ ## Send status and events to M/Monit (for more informations about M/Monit
71
+ ## see http://mmonit.com/). By default Monit registers credentials with
72
+ ## M/Monit so M/Monit can smoothly communicate back to Monit and you don't
73
+ ## have to register Monit credentials manually in M/Monit. It is possible to
74
+ ## disable credential registration using the commented out option below.
75
+ ## Though, if safety is a concern we recommend instead using https when
76
+ ## communicating with M/Monit and send credentials encrypted.
77
+ #
78
+ # set mmonit http://monit:monit@192.168.1.10:8080/collector
79
+ # # and register without credentials # Don't register credentials
80
+ #
81
+ #
82
+ ## Monit by default uses the following format for alerts if the the mail-format
83
+ ## statement is missing::
84
+ ## --8<--
85
+ ## set mail-format {
86
+ ## from: monit@$HOST
87
+ ## subject: monit alert -- $EVENT $SERVICE
88
+ ## message: $EVENT Service $SERVICE
89
+ ## Date: $DATE
90
+ ## Action: $ACTION
91
+ ## Host: $HOST
92
+ ## Description: $DESCRIPTION
93
+ ##
94
+ ## Your faithful employee,
95
+ ## Monit
96
+ ## }
97
+ ## --8<--
98
+ ##
99
+ ## You can override this message format or parts of it, such as subject
100
+ ## or sender using the MAIL-FORMAT statement. Macros such as $DATE, etc.
101
+ ## are expanded at runtime. For example, to override the sender, use:
102
+ #
103
+ # set mail-format { from: monit@foo.bar }
104
+ #
105
+ #
106
+ ## You can set alert recipients whom will receive alerts if/when a
107
+ ## service defined in this file has errors. Alerts may be restricted on
108
+ ## events by using a filter as in the second example below.
109
+ #
110
+ # set alert sysadm@foo.bar # receive all alerts
111
+ ## Do not alert when Monit start,stop or perform a user initiated action
112
+ # set alert manager@foo.bar not on { instance, action }
113
+ #
114
+ #
115
+ ## Monit has an embedded web server which can be used to view status of
116
+ ## services monitored and manage services from a web interface. See the
117
+ ## Monit Wiki if you want to enable SSL for the web server.
118
+ #
119
+ set httpd port 2812 and
120
+ use address localhost # only accept connection from localhost
121
+ allow localhost # allow localhost to connect to the server and
122
+ # allow admin:monit # require user 'admin' with password 'monit'
123
+ # allow @monit # allow users of group 'monit' to connect (rw)
124
+ # allow @users readonly # allow users of group 'users' to connect readonly
125
+ #
126
+ ###############################################################################
127
+ ## Services
128
+ ###############################################################################
129
+ ##
130
+ ## Check general system resources such as load average, cpu and memory
131
+ ## usage. Each test specifies a resource, conditions and the action to be
132
+ ## performed should a test fail.
133
+ #
134
+ # check system myhost.mydomain.tld
135
+ # if loadavg (1min) > 4 then alert
136
+ # if loadavg (5min) > 2 then alert
137
+ # if memory usage > 75% then alert
138
+ # if swap usage > 25% then alert
139
+ # if cpu usage (user) > 70% then alert
140
+ # if cpu usage (system) > 30% then alert
141
+ # if cpu usage (wait) > 20% then alert
142
+ #
143
+ #
144
+ ## Check if a file exists, checksum, permissions, uid and gid. In addition
145
+ ## to alert recipients in the global section, customized alert can be sent to
146
+ ## additional recipients by specifying a local alert handler. The service may
147
+ ## be grouped using the GROUP option. More than one group can be specified by
148
+ ## repeating the 'group name' statement.
149
+ #
150
+ # check file apache_bin with path /usr/local/apache/bin/httpd
151
+ # if failed checksum and
152
+ # expect the sum 8f7f419955cefa0b33a2ba316cba3659 then unmonitor
153
+ # if failed permission 755 then unmonitor
154
+ # if failed uid root then unmonitor
155
+ # if failed gid root then unmonitor
156
+ # alert security@foo.bar on {
157
+ # checksum, permission, uid, gid, unmonitor
158
+ # } with the mail-format { subject: Alarm! }
159
+ # group server
160
+ #
161
+ #
162
+ ## Check that a process is running, in this case Apache, and that it respond
163
+ ## to HTTP and HTTPS requests. Check its resource usage such as cpu and memory,
164
+ ## and number of children. If the process is not running, Monit will restart
165
+ ## it by default. In case the service is restarted very often and the
166
+ ## problem remains, it is possible to disable monitoring using the TIMEOUT
167
+ ## statement. This service depends on another service (apache_bin) which
168
+ ## is defined above.
169
+ #
170
+ # check process apache with pidfile /usr/local/apache/logs/httpd.pid
171
+ # start program = "/etc/init.d/httpd start" with timeout 60 seconds
172
+ # stop program = "/etc/init.d/httpd stop"
173
+ # if cpu > 60% for 2 cycles then alert
174
+ # if cpu > 80% for 5 cycles then restart
175
+ # if totalmem > 200.0 MB for 5 cycles then restart
176
+ # if children > 250 then restart
177
+ # if loadavg(5min) greater than 10 for 8 cycles then stop
178
+ # if failed host www.tildeslash.com port 80 protocol http
179
+ # and request "/somefile.html"
180
+ # then restart
181
+ # if failed port 443 type tcpssl protocol http
182
+ # with timeout 15 seconds
183
+ # then restart
184
+ # if 3 restarts within 5 cycles then timeout
185
+ # depends on apache_bin
186
+ # group server
187
+ #
188
+ #
189
+ ## Check filesystem permissions, uid, gid, space and inode usage. Other services,
190
+ ## such as databases, may depend on this resource and an automatically graceful
191
+ ## stop may be cascaded to them before the filesystem will become full and data
192
+ ## lost.
193
+ #
194
+ # check filesystem datafs with path /dev/sdb1
195
+ # start program = "/bin/mount /data"
196
+ # stop program = "/bin/umount /data"
197
+ # if failed permission 660 then unmonitor
198
+ # if failed uid root then unmonitor
199
+ # if failed gid disk then unmonitor
200
+ # if space usage > 80% for 5 times within 15 cycles then alert
201
+ # if space usage > 99% then stop
202
+ # if inode usage > 30000 then alert
203
+ # if inode usage > 99% then stop
204
+ # group server
205
+ #
206
+ #
207
+ ## Check a file's timestamp. In this example, we test if a file is older
208
+ ## than 15 minutes and assume something is wrong if its not updated. Also,
209
+ ## if the file size exceed a given limit, execute a script
210
+ #
211
+ # check file database with path /data/mydatabase.db
212
+ # if failed permission 700 then alert
213
+ # if failed uid data then alert
214
+ # if failed gid data then alert
215
+ # if timestamp > 15 minutes then alert
216
+ # if size > 100 MB then exec "/my/cleanup/script" as uid dba and gid dba
217
+ #
218
+ #
219
+ ## Check directory permission, uid and gid. An event is triggered if the
220
+ ## directory does not belong to the user with uid 0 and gid 0. In addition,
221
+ ## the permissions have to match the octal description of 755 (see chmod(1)).
222
+ #
223
+ # check directory bin with path /bin
224
+ # if failed permission 755 then unmonitor
225
+ # if failed uid 0 then unmonitor
226
+ # if failed gid 0 then unmonitor
227
+ #
228
+ #
229
+ ## Check a remote host availability by issuing a ping test and check the
230
+ ## content of a response from a web server. Up to three pings are sent and
231
+ ## connection to a port and an application level network check is performed.
232
+ #
233
+ # check host myserver with address 192.168.1.1
234
+ # if failed icmp type echo count 3 with timeout 3 seconds then alert
235
+ # if failed port 3306 protocol mysql with timeout 15 seconds then alert
236
+ # if failed url http://user:password@www.foo.bar:8080/?querystring
237
+ # and content == 'action="j_security_check"'
238
+ # then alert
239
+ #
240
+ #
241
+ ###############################################################################
242
+ ## Includes
243
+ ###############################################################################
244
+ ##
245
+ ## It is possible to include additional configuration parts from other files or
246
+ ## directories.
247
+ #
248
+ include /etc/monit/conf.d/*
249
+
250
+ ###############################################################################
251
+ ## Allow monit to be reloaded from the web interface, so that root is not
252
+ ## needed when deploying.
253
+ ##
254
+ ## Example
255
+ ## curl http://localhost:2812/monit_reload -d "action=restart"
256
+ ###############################################################################
257
+ check process monit_reload
258
+ with pidfile /var/run/monit.pid
259
+ restart program = "/bin/bash -c '/bin/sleep 1 && /usr/bin/monit reload &'"
260
+ #restart program = "/bin/bash -c '/usr/bin/monit reload &'"
261
+
262
+ #Nginx
263
+ #check process nginx with pidfile "/var/run/nginx.pid"
264
+ #if cpu > 80% for 2 cycles then alert
265
+
266
+ #System Monitoring
267
+ #check system PUT_YOUR_HOSTNAME_HERE
268
+ #if memory usage > 80% for 2 cycles then alert
269
+ #if cpu usage (user) > 70% for 2 cycles then alert
270
+ #if cpu usage (system) > 30% then alert
271
+ #if cpu usage (wait) > 20% then alert
272
+ #if loadavg (1min) > 6 for 2 cycles then alert
273
+ #if loadavg (5min) > 4 for 2 cycles then alert
274
+ #if swap usage > 5% then alert
275
+
276
+ #check filesystem rootfs with path /
277
+ #if space usage > 80% then alert
278
+ #set mailserver localhost
279
+ #set alert you@example.com
@@ -0,0 +1,34 @@
1
+ # Based on: https://mmonit.com/wiki/Monit/Upstart
2
+ #
3
+ # This is an upstart script to keep monit running.
4
+ # To install disable the old way of doing things:
5
+ #
6
+ # /etc/init.d/monit stop && update-rc.d -f monit remove
7
+ #
8
+ # then put this script here:
9
+ #
10
+ # /etc/init/monit.conf
11
+ #
12
+ # and reload upstart configuration:
13
+ #
14
+ # initctl reload-configuration
15
+ #
16
+ # You can manually start and stop monit like this:
17
+ #
18
+ # start monit
19
+ # stop monit
20
+ #
21
+
22
+ description "Monit service manager"
23
+
24
+ limit core unlimited unlimited
25
+
26
+ start on runlevel [2345]
27
+ stop on starting rc RUNLEVEL=[016]
28
+
29
+ expect daemon
30
+ respawn
31
+
32
+ exec /usr/bin/monit -c /etc/monitrc
33
+
34
+ pre-stop exec /usr/bin/monit -c /etc/monitrc quit
@@ -1,3 +1,3 @@
1
1
  module Pvcglue
2
- VERSION = "0.1.25"
2
+ VERSION = "0.1.26"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pvcglue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.25
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Lyric
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-24 00:00:00.000000000 Z
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -232,12 +232,15 @@ files:
232
232
  - lib/pvcglue/env.rb
233
233
  - lib/pvcglue/local.rb
234
234
  - lib/pvcglue/manager.rb
235
+ - lib/pvcglue/monit.rb
235
236
  - lib/pvcglue/nodes.rb
236
237
  - lib/pvcglue/packages.rb
237
238
  - lib/pvcglue/packages/bootstrap.rb
238
239
  - lib/pvcglue/packages/env.rb
239
240
  - lib/pvcglue/packages/firewall.rb
240
241
  - lib/pvcglue/packages/manager.rb
242
+ - lib/pvcglue/packages/monit-bootstrap.rb
243
+ - lib/pvcglue/packages/monit-web.rb
241
244
  - lib/pvcglue/packages/nginx.rb
242
245
  - lib/pvcglue/packages/nodejs.rb
243
246
  - lib/pvcglue/packages/passenger.rb
@@ -250,6 +253,7 @@ files:
250
253
  - lib/pvcglue/packages/rvm.rb
251
254
  - lib/pvcglue/packages/timezone.rb
252
255
  - lib/pvcglue/packages/ubuntu.rb
256
+ - lib/pvcglue/pvcify.rb
253
257
  - lib/pvcglue/railtie.rb
254
258
  - lib/pvcglue/ssl.rb
255
259
  - lib/pvcglue/templates/20auto-upgrades.erb
@@ -264,6 +268,11 @@ files:
264
268
  - lib/pvcglue/templates/lb.sites-enabled.erb
265
269
  - lib/pvcglue/templates/maintenance_mode.erb
266
270
  - lib/pvcglue/templates/memcached.conf.erb
271
+ - lib/pvcglue/templates/monit.app.monitrc.erb
272
+ - lib/pvcglue/templates/monit.etc-default.erb
273
+ - lib/pvcglue/templates/monit.init.d.erb
274
+ - lib/pvcglue/templates/monit.monitrc.erb
275
+ - lib/pvcglue/templates/monit.upstart-conf.erb
267
276
  - lib/pvcglue/templates/passenger.list.erb
268
277
  - lib/pvcglue/templates/pg_hba.conf.erb
269
278
  - lib/pvcglue/templates/postgresql.conf.erb