deprec 2.1.19 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/CHANGELOG +11 -1
  2. data/{README → README.md} +33 -68
  3. data/bin/hosts.rb +44 -0
  4. data/docs/nagios.txt +28 -0
  5. data/lib/deprec/capistrano_extensions.rb +21 -32
  6. data/lib/deprec/recipes/apache.rb +54 -73
  7. data/lib/deprec/recipes/deprec.rb +30 -48
  8. data/lib/deprec/recipes/git.rb +2 -85
  9. data/lib/deprec/recipes/haproxy.rb +3 -11
  10. data/lib/deprec/recipes/mri.rb +23 -40
  11. data/lib/deprec/recipes/mysql.rb +6 -23
  12. data/lib/deprec/recipes/nagios.rb +2 -17
  13. data/lib/deprec/recipes/nagios3.rb +180 -0
  14. data/lib/deprec/recipes/network.rb +60 -28
  15. data/lib/deprec/recipes/nrpe.rb +82 -0
  16. data/lib/deprec/recipes/passenger.rb +15 -12
  17. data/lib/deprec/recipes/postgresql.rb +2 -2
  18. data/lib/deprec/recipes/rack.rb +44 -0
  19. data/lib/deprec/recipes/rails.rb +10 -32
  20. data/lib/deprec/recipes/ree.rb +27 -18
  21. data/lib/deprec/recipes/rubygems.rb +29 -0
  22. data/lib/deprec/recipes/sqlite.rb +1 -1
  23. data/lib/deprec/recipes/ssh.rb +1 -0
  24. data/lib/deprec/recipes/svn.rb +1 -160
  25. data/lib/deprec/recipes/users.rb +19 -16
  26. data/lib/deprec/recipes_minus_rails.rb +39 -36
  27. data/lib/deprec/templates/apache/CHANGES.txt +11 -0
  28. data/lib/deprec/templates/mysql/my.cnf.erb +21 -31
  29. data/lib/deprec/templates/{nagios → nagios.old}/README +0 -0
  30. data/lib/deprec/templates/nagios.old/apache_vhost.erb +25 -0
  31. data/lib/deprec/templates/{nagios → nagios.old}/cgi.cfg.erb +0 -0
  32. data/lib/deprec/templates/nagios.old/check_linux_free_memory.pl +118 -0
  33. data/lib/deprec/templates/{nagios → nagios.old}/check_mongrel_cluster.rb +0 -0
  34. data/lib/deprec/templates/nagios.old/htpasswd.users +1 -0
  35. data/lib/deprec/templates/{nagios → nagios.old}/mrtg.cfg +0 -0
  36. data/lib/deprec/templates/{nagios → nagios.old}/nagios.cfg.erb +0 -0
  37. data/lib/deprec/templates/{nagios → nagios.old}/nrpe.cfg.erb +0 -0
  38. data/lib/deprec/templates/{nagios → nagios.old}/nrpe.xinetd.erb +0 -0
  39. data/lib/deprec/templates/{nagios → nagios.old}/objects/commands.cfg.erb +0 -0
  40. data/lib/deprec/templates/{nagios → nagios.old}/objects/contacts.cfg.erb +0 -0
  41. data/lib/deprec/templates/{nagios → nagios.old}/objects/hosts.cfg.erb +0 -0
  42. data/lib/deprec/templates/{nagios → nagios.old}/objects/localhost.cfg.erb +0 -0
  43. data/lib/deprec/templates/{nagios → nagios.old}/objects/services.cfg.erb +0 -0
  44. data/lib/deprec/templates/{nagios → nagios.old}/objects/timeperiods.cfg.erb +0 -0
  45. data/lib/deprec/templates/{nagios → nagios.old}/resource.cfg.erb +0 -0
  46. data/lib/deprec/templates/nagios/apache2.conf +55 -0
  47. data/lib/deprec/templates/nagios/cgi.cfg +25 -0
  48. data/lib/deprec/templates/nagios/commands.cfg +52 -0
  49. data/lib/deprec/templates/nagios/conf.d/contacts_nagios2.cfg +23 -0
  50. data/lib/deprec/templates/nagios/conf.d/extinfo_nagios2.cfg +13 -0
  51. data/lib/deprec/templates/nagios/conf.d/generic-host_nagios2.cfg +19 -0
  52. data/lib/deprec/templates/nagios/conf.d/generic-service_nagios2.cfg +26 -0
  53. data/lib/deprec/templates/nagios/conf.d/hostgroups_nagios2.cfg +48 -0
  54. data/lib/deprec/templates/nagios/conf.d/hosts/localhost_nagios2.cfg +59 -0
  55. data/lib/deprec/templates/nagios/conf.d/services_nagios2.cfg +45 -0
  56. data/lib/deprec/templates/nagios/conf.d/timeperiods_nagios2.cfg +50 -0
  57. data/lib/deprec/templates/nagios/host_template.erb +6 -0
  58. data/lib/deprec/templates/nagios/htpasswd.users +1 -1
  59. data/lib/deprec/templates/nagios/nagios.cfg +1326 -0
  60. data/lib/deprec/templates/nagios/nrpe.cfg +28 -0
  61. data/lib/deprec/templates/nagios/resource.cfg +31 -0
  62. data/lib/deprec/templates/passenger/apache_vhost.erb +2 -2
  63. data/lib/deprec/templates/passenger/logrotate.conf.erb +1 -1
  64. data/lib/deprec/templates/passenger/passenger.conf.erb +12 -11
  65. data/lib/deprec/templates/passenger/passenger.load.erb +1 -1
  66. metadata +43 -42
  67. data/lib/deprec/recipes/wordpress.rb +0 -96
@@ -1,6 +1,6 @@
1
1
  # Copyright 2006-2008 by Mike Bailey. All rights reserved.
2
2
  Capistrano::Configuration.instance(:must_exist).load do
3
-
3
+
4
4
  # Set the value if not already set
5
5
  # This method is accessible to all recipe files
6
6
  def self.default(name, *args, &block)
@@ -24,56 +24,38 @@ Capistrano::Configuration.instance(:must_exist).load do
24
24
  # For each service, the details of the file to download and options
25
25
  # to configure, build and install the service
26
26
  SRC_PACKAGES = {} unless defined?(SRC_PACKAGES)
27
-
28
- # Server options
27
+
28
+ # deprec defines some generic recipes for common services
29
+ # including ruby interpreter, web, app and database servers
30
+ #
31
+ # They default to my current favourites which you can over ride
32
+ #
33
+ # Service options
29
34
  CHOICES_RUBY_VM = [:mri, :ree]
30
- CHOICES_WEBSERVER = [:nginx, :apache, :none]
31
- CHOICES_APPSERVER = [:mongrel, :webrick, :passenger, :none]
35
+ CHOICES_WEBSERVER = [:apache, :none] # :nginx not recipes out of date
36
+ CHOICES_APPSERVER = [:passenger, :none] # any colour you like guys
32
37
  CHOICES_DATABASE = [:mysql, :postgresql, :sqlite, :none]
33
-
34
- # Service defaults
35
- #
36
- # The defaults below are legacy values to support older deployments.
37
- # Newly generated deploy.rb files have use apache, passenger and ree
38
- default :ruby_vm_type, :ree
39
- default :web_server_type, :apache
40
- default :app_server_type, :passenger
41
- default :db_server_type, :mysql
42
- #
43
- # default(:web_server_type) do
44
- # Capistrano::CLI.ui.choose do |menu|
45
- # CHOICES_WEBSERVER.each {|c| menu.choice(c)}
46
- # menu.header = "select webserver type"
47
- # end
48
- # end
49
38
  #
50
- # default(:app_server_type) do
51
- # Capistrano::CLI.ui.choose do |menu|
52
- # CHOICES_APPSERVER.each {|c| menu.choice(c)}
53
- # menu.header = "select application server type"
54
- # end
55
- # end
56
- #
57
- # default(:db_server_type) do
58
- # Capistrano::CLI.ui.choose do |menu|
59
- # CHOICES_DATABASE.each {|c| menu.choice(c)}
60
- # menu.header = "select database server type"
61
- # end
62
- # end
39
+ # Service defaults
40
+ set :ruby_vm_type, :mri
41
+ set :web_server_type, :apache
42
+ set :app_server_type, :passenger
43
+ set :db_server_type, :mysql
63
44
 
64
- default(:application) do
45
+ # Prompt user for missing values if not supplied
46
+ set(:application) do
65
47
  Capistrano::CLI.ui.ask "Enter name of project(no spaces)" do |q|
66
48
  q.validate = /^[0-9a-z_]*$/
67
49
  end
68
50
  end
69
51
 
70
- default(:domain) do
52
+ set(:domain) do
71
53
  Capistrano::CLI.ui.ask "Enter domain name for project" do |q|
72
54
  q.validate = /^[0-9a-z_\.]*$/
73
55
  end
74
56
  end
75
57
 
76
- default(:repository) do
58
+ set(:repository) do
77
59
  Capistrano::CLI.ui.ask "Enter repository URL for project" do |q|
78
60
  # q.validate = //
79
61
  end
@@ -84,23 +66,23 @@ Capistrano::Configuration.instance(:must_exist).load do
84
66
  # :invoke_command "command", :via => run_method
85
67
  # override this value if sudo is not an option
86
68
  # in that case, your use will need the correct privileges
87
- default :run_method, :sudo
69
+ set :run_method, :sudo
88
70
 
89
- default(:backup_dir) { '/var/backups'}
71
+ set(:backup_dir) { '/var/backups'}
90
72
 
91
73
  # XXX rails deploy stuff
92
- set :apps_root, File.join( %w(/ opt apps) ) # parent dir for apps
93
- default(:deploy_to) { File.join(apps_root, application) } # dir for current app
94
- default(:current_path) { File.join(deploy_to, "current") }
95
- default(:shared_path) { File.join(deploy_to, "shared") }
74
+ set :apps_root, '/srv' # parent dir for apps
75
+ set(:deploy_to) { File.join(apps_root, application) } # dir for current app
76
+ set(:current_path) { File.join(deploy_to, "current") }
77
+ set(:shared_path) { File.join(deploy_to, "shared") }
96
78
 
97
79
  # XXX more rails deploy stuff?
98
80
 
99
- default :user, ENV['USER'] # user who is deploying
100
- default :group, 'deploy' # deployment group
101
- default(:group_src) { group } # group ownership for src dir
102
- default :src_dir, '/usr/local/src' # 3rd party src on servers lives here
103
- default(:web_server_aliases) { domain.match(/^www/) ? [] : ["www.#{domain}"] }
81
+ set :user, ENV['USER'] # user who is deploying
82
+ set :group, 'deploy' # deployment group
83
+ set(:group_src) { group } # group ownership for src dir
84
+ set :src_dir, '/usr/local/src' # 3rd party src on servers lives here
85
+ set(:web_server_aliases) { domain.match(/^www/) ? [] : ["www.#{domain}"] }
104
86
 
105
87
  # XXX for some reason this is causing "before deprec:rails:install" to be executed twice
106
88
  on :load, 'deprec:connect_canonical_tasks'
@@ -3,94 +3,11 @@ Capistrano::Configuration.instance(:must_exist).load do
3
3
  namespace :deprec do
4
4
  namespace :git do
5
5
 
6
- set :git_user, 'git'
7
- set :git_group, 'git'
8
- set :git_port, '9418'
9
- set :git_keys_file, '/home/git/.ssh/authorized_keys'
10
- set :git_root, '/var/git'
11
-
12
- SRC_PACKAGES[:git] = {
13
- :url => "http://kernel.org/pub/software/scm/git/git-1.6.4.3.tar.gz",
14
- :md5sum => "95381cd27ad762c645c8e07f922879ce git-1.6.4.3.tar.gz"
15
- }
16
-
6
+ # Ubuntu lucid has a new enough version of git
17
7
  desc "Install git"
18
8
  task :install do
19
- install_deps
20
- deprec2.download_src(SRC_PACKAGES[:git], src_dir)
21
- deprec2.install_from_src(SRC_PACKAGES[:git], src_dir)
22
- # create_git_root
23
- # create_git_user
24
- end
25
-
26
- # install dependencies for nginx
27
- task :install_deps do
28
- apt.install( {:base => %w(zlib1g-dev gettext libcurl4-gnutls-dev)}, :stable )
29
- end
30
-
31
- # "Start git server in local directory"
32
- task :serve do
33
- cmd = "git-daemon --verbose --port=#{git_port} --base-path=#{Dir.pwd} --base-path-relaxed"
34
- puts cmd
35
- `#{cmd}`
36
- end
37
-
38
- desc "Create git repos for current dir"
39
- task :init do
40
- `git init`
41
- create_gitignore
42
- create_files_in_empty_dirs
43
- `git add . && git commit -m 'initial import'`
44
- end
45
-
46
- task :create_gitignore do
47
- system("echo '.DS_Store' >> .gitignore") # files sometimes created by OSX
48
- system("echo 'log/*' >> .gitignore") if File.directory?('log')
49
- system("echo 'tmp/**/*' >> .gitignore") if File.directory?('tmp')
9
+ apt.install( {:base => %w(git-core)}, :stable )
50
10
  end
51
-
52
- task :create_files_in_empty_dirs do
53
- %w(log tmp).each { |dir|
54
- system("touch #{dir}/.gitignore") if File.directory?(dir)
55
- }
56
- end
57
-
58
- desc "Create remote origin for current dir"
59
- task :create_remote_origin do
60
- File.directory?('.git') || init
61
-
62
- # Push to remote git repo
63
- hostname = capture "echo $CAPISTRANO:HOST$"
64
- system "git remote add origin git@#{hostname.chomp}:#{application}"
65
- system "git push origin master:refs/heads/master"
66
-
67
- puts
68
- puts "New remote Git repo: #{git_user}@#{hostname.chomp}:#{application}"
69
- puts
70
-
71
- # File.open('.git/config', 'w') do |c|
72
- # c.write 'Add the following to .git/config'
73
- # c.write '[branch "master"]'
74
- # c.write ' remote = origin'
75
- # c.write ' merge = refs/heads/master'
76
- # end
77
-
78
- end
79
-
80
- # Create root dir for git repositories
81
- task :create_git_root do
82
- deprec2.mkdir(git_root, :mode => 02775, :owner => git_user, :group => git_group, :via => :sudo)
83
- sudo "chmod -R g+w #{git_root}"
84
- end
85
-
86
- # regenerate git authorized keys file from users file in same dir
87
- task :regenerate_authorized_keys do
88
- sudo "echo '' > #{git_keys_file}"
89
- sudo "for file in `ls #{git_keys_file}-*`; do cat $file >> #{git_keys_file}; echo \"\n\" >> #{git_keys_file} ; done"
90
- sudo "chown #{git_user}.#{git_group} #{git_keys_file}"
91
- sudo "chmod 0600 #{git_keys_file}"
92
- end
93
-
94
11
 
95
12
  end
96
13
  end
@@ -4,20 +4,19 @@ Capistrano::Configuration.instance(:must_exist).load do
4
4
  namespace :haproxy do
5
5
 
6
6
  SRC_PACKAGES[:haproxy] = {
7
- :md5sum => "4f0638652d7800860838dc195da335d8 haproxy-1.4.11.tar.gz",
8
- :url => "http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.11.tar.gz",
7
+ :md5sum => "c1b4fc6028c6d8e23dde8c91ff47eabe haproxy-1.4.15.tar.gz",
8
+ :url => "http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.15.tar.gz",
9
9
  :configure => '',
10
10
  :make => "make TARGET=linux26"
11
11
  }
12
12
 
13
13
  desc "Install haproxy"
14
14
  task :install, :roles => :haproxy do
15
- install_deps
16
15
  deprec2.download_src(SRC_PACKAGES[:haproxy], src_dir)
17
16
  deprec2.install_from_src(SRC_PACKAGES[:haproxy], src_dir)
18
17
  config
19
18
  activate
20
- create_check_file
19
+ # create_check_file
21
20
  end
22
21
 
23
22
  # default config expects this file in web root
@@ -25,9 +24,6 @@ Capistrano::Configuration.instance(:must_exist).load do
25
24
  sudo "test -d /var/www && #{sudo} touch /var/www/check.txt"
26
25
  end
27
26
 
28
- task :install_deps, :roles => :haproxy do
29
- apt.install( {:base => %w(build-essential)}, :stable )
30
- end
31
27
 
32
28
  SYSTEM_CONFIG_FILES[:haproxy] = [
33
29
 
@@ -45,10 +41,6 @@ Capistrano::Configuration.instance(:must_exist).load do
45
41
 
46
42
  PROJECT_CONFIG_FILES[:haproxy] = [
47
43
 
48
- # {:template => "example.conf.erb",
49
- # :path => 'conf/example.conf',
50
- # :mode => 0755,
51
- # :owner => 'root:root'}
52
44
  ]
53
45
 
54
46
  desc "Generate configuration files for haproxy from template(s)"
@@ -4,53 +4,36 @@ Capistrano::Configuration.instance(:must_exist).load do
4
4
  namespace :deprec do
5
5
  namespace :mri do
6
6
 
7
- SRC_PACKAGES[:mri] = {
8
- :md5sum => "755aba44607c580fddc25e7c89260460 ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz",
9
- :url => "ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz",
7
+ SRC_PACKAGES['ruby-1.8.7-p330'] = {
8
+ :md5sum => "50a49edb787211598d08e756e733e42e ruby-1.8.7-p330.tar.gz",
9
+ :url => "ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p330.tar.gz",
10
+ :deps => %w(zlib1g-dev libssl-dev libncurses5-dev libreadline5-dev),
10
11
  :configure => "./configure --with-readline-dir=/usr/local;"
11
12
  }
12
-
13
- desc "Install Ruby"
14
- task :install do
15
- install_deps
16
- deprec2.download_src(SRC_PACKAGES[:mri], src_dir)
17
- deprec2.install_from_src(SRC_PACKAGES[:mri], src_dir)
18
- # Ruby versions from 1.9.1 install rubygems
19
- # top.deprec.rubygems.install
20
- end
21
-
22
- task :install_deps do
23
- apt.install( {:base => %w(zlib1g-dev libssl-dev libncurses5-dev libreadline5-dev)}, :stable )
24
- end
25
13
 
26
- end
27
- end
28
-
29
-
30
- namespace :deprec do
31
- namespace :rubygems do
32
-
33
- SRC_PACKAGES[:rubygems] = {
34
- :md5sum => "e85cfadd025ff6ab689375adbf344bbe rubygems-1.3.7.tgz",
35
- :url => "http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz",
36
- :configure => "",
37
- :make => "",
38
- :install => 'ruby setup.rb;'
14
+ SRC_PACKAGES['ruby-1.9.2-p180'] = {
15
+ :md5sum => "0d6953820c9918820dd916e79f4bfde8 ruby-1.9.2-p180.tar.gz",
16
+ :url => "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p180.tar.gz",
17
+ :deps => %w(zlib1g-dev libssl-dev libncurses5-dev libreadline5-dev),
18
+ :configure => "./configure",
19
+ :post_install => 'sudo gem update --system'
39
20
  }
40
-
41
- desc "Install Rubygems"
21
+
22
+ src_package_options = SRC_PACKAGES.keys.select{|k| k.match /^ruby-\d\.\d\.\d/ }
23
+ set(:mri_src_package) {
24
+ puts "Select mri_src_package from list:"
25
+ Capistrano::CLI.ui.choose do |menu|
26
+ menu.choices(*src_package_options)
27
+ end
28
+ }
29
+
30
+ desc "Install Ruby"
42
31
  task :install do
43
- install_deps
44
- deprec2.download_src(SRC_PACKAGES[:rubygems], src_dir)
45
- deprec2.install_from_src(SRC_PACKAGES[:rubygems], src_dir)
46
- # gem2.upgrade # you may not want to upgrade your gems right now
47
- end
48
-
49
- # install dependencies for rubygems
50
- task :install_deps do
32
+ deprec2.download_src(SRC_PACKAGES[mri_src_package])
33
+ deprec2.install_from_src(SRC_PACKAGES[mri_src_package])
51
34
  end
52
35
 
53
36
  end
54
-
55
37
  end
38
+
56
39
  end
@@ -10,15 +10,8 @@ Capistrano::Configuration.instance(:must_exist).load do
10
10
 
11
11
  desc "Install mysql"
12
12
  task :install, :roles => :db do
13
- install_deps
14
- config
15
- start
16
- # symlink_mysql_sockfile # XXX still needed?
17
- end
18
-
19
- # Install dependencies for Mysql
20
- task :install_deps, :roles => :db do
21
13
  apt.install( {:base => %w(mysql-server mysql-client libmysqlclient15-dev)}, :stable )
14
+ config
22
15
  end
23
16
 
24
17
  # Configuration
@@ -73,20 +66,10 @@ Capistrano::Configuration.instance(:must_exist).load do
73
66
  task :reload, :roles => :db do
74
67
  send(run_method, "/etc/init.d/mysql reload")
75
68
  end
76
-
77
-
78
- task :backup, :roles => :db do
79
- end
80
-
81
- task :restore, :roles => :db do
82
- end
83
-
84
- desc "Create a mysql user"
85
- task :create_user, :roles => :db do
86
- # TBA
87
- end
88
-
89
- desc "Create a database"
69
+
70
+
71
+ # Extras (not sure if they still work)
72
+ # Create a database
90
73
  task :create_database, :roles => :db do
91
74
  cmd = "CREATE DATABASE IF NOT EXISTS #{db_name}"
92
75
  run "mysql -u #{mysql_admin_user} -p -e '#{cmd}'" do |channel, stream, data|
@@ -96,7 +79,7 @@ Capistrano::Configuration.instance(:must_exist).load do
96
79
  end
97
80
  end
98
81
 
99
- desc "Grant user access to database"
82
+ # "Grant user access to database"
100
83
  task :grant_user_access_to_database, :roles => :db do
101
84
  cmd = "GRANT ALL PRIVILEGES ON #{db_name}.* TO '#{db_user}'@localhost IDENTIFIED BY '#{db_password}';"
102
85
  run "mysql -u #{mysql_admin_user} -p #{db_name} -e \"#{cmd}\"" do |channel, stream, data|
@@ -10,7 +10,6 @@ Capistrano::Configuration.instance(:must_exist).load do
10
10
  set(:nagios_admin_pass) { Capistrano::CLI.ui.ask "Enter password for nagiosadmin user" }
11
11
  set :nagios_cmd_group, 'nagcmd' # Submit external commands through the web interface
12
12
  set :nagios_htpasswd_file, '/usr/local/nagios/etc/htpasswd.users'
13
- # default :application, 'nagios'
14
13
 
15
14
  SRC_PACKAGES[:nagios] = {
16
15
  :url => "http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz",
@@ -139,7 +138,7 @@ Capistrano::Configuration.instance(:must_exist).load do
139
138
 
140
139
  desc "Push nagios config files to server"
141
140
  task :config, :roles => :nagios do
142
- default :application, 'nagios'
141
+ # default :application, 'nagios'
143
142
  deprec2.push_configs(:nagios, SYSTEM_CONFIG_FILES[:nagios])
144
143
  config_check
145
144
  restart
@@ -150,20 +149,6 @@ Capistrano::Configuration.instance(:must_exist).load do
150
149
  send(run_method, "/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg")
151
150
  end
152
151
 
153
- # desc "Set Nagios to start on boot"
154
- # task :activate, :roles => :nagios do
155
- # send(run_method, "update-rc.d nagios defaults")
156
- # sudo "a2ensite nagios"
157
- # top.deprec.apache.reload
158
- # end
159
- #
160
- # desc "Set Nagios to not start on boot"
161
- # task :deactivate, :roles => :nagios do
162
- # send(run_method, "update-rc.d -f nagios remove")
163
- # sudo "a2dissite nagios"
164
- # top.deprec.apache.reload
165
- # end
166
-
167
152
  # Control
168
153
 
169
154
  desc "Start Nagios"
@@ -232,7 +217,7 @@ Capistrano::Configuration.instance(:must_exist).load do
232
217
 
233
218
  namespace :nrpe do
234
219
 
235
- default :nrpe_enable_command_args, false # set to true to compile nrpe to accept arguments
220
+ set :nrpe_enable_command_args, false # set to true to compile nrpe to accept arguments
236
221
  # note that you'll need to set it before these recipes are loaded (e.g. in .caprc)
237
222
 
238
223
  SRC_PACKAGES[:nrpe] = {
@@ -0,0 +1,180 @@
1
+ # Copyright 2006-2008 by Mike Bailey. All rights reserved.
2
+ require 'socket'
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+ namespace :deprec do
5
+ namespace :nagios do
6
+
7
+ # Deprec generally ships with the upstream vendor defaults
8
+ #
9
+ # In this case we override the default settings Nagios ships with
10
+ # to enable external command checking. This is needed if you want
11
+ # to be able to control things via the web interface.
12
+ set :nagios_check_external_commands, 1
13
+ set :nagios_command_check_interval, '15s'
14
+
15
+ desc "Install Nagios"
16
+ task :install, :roles => :nagios do
17
+ apt.install(
18
+ {:base => %w(nagios3 nagios-plugins nagios-nrpe-plugin)}, :stable
19
+ )
20
+ cull_configs
21
+ config
22
+ fix_command_file
23
+ puts
24
+ puts "Nagios should be accessible at #{find_servers_for_task(current_task).collect{|u| "http://#{u}/nagios3"}.join(' ')}"
25
+ end
26
+
27
+ task :cull_configs, :roles => :nagios do
28
+ %w(/etc/nagios3/conf.d/localhost_nagios2.cfg
29
+ /etc/nagios3/conf.d/host-gateway_nagios3.cfg).each do |file|
30
+ run "if [ -f #{file} ]; then #{sudo} rm #{file}; fi"
31
+ end
32
+ end
33
+
34
+ task :fix_command_file, :roles => :nagios do
35
+ stop
36
+ sleep 5 # Give the stop command time to work. Race condition. GROSS!!
37
+ run "(dpkg-statoverride --list | grep 'nagios www-data 2710 /var/lib/nagios3/rw') || #{sudo} dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw"
38
+ run "(dpkg-statoverride --list | grep 'nagios nagios 751 /var/lib/nagios3') ||
39
+ #{sudo} dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3"
40
+ # sleep 5
41
+ start
42
+ end
43
+
44
+ desc "Grant a user access to the web interface"
45
+ task :htpass, :roles => :nagios do
46
+ target_user = Capistrano::CLI.ui.ask "Userid" do |q|
47
+ q.default = 'nagiosadmin'
48
+ end
49
+ htpasswd_file = 'config/nagios/usr/local/nagios/etc/htpasswd.users'
50
+ system "htpasswd #{htpasswd_file} #{target_user}"
51
+ config
52
+ end
53
+
54
+ # All of the config files have same owner/mode...
55
+ SYSTEM_CONFIG_FILES[:nagios] ||= []
56
+ %w(
57
+ apache2.conf
58
+ cgi.cfg
59
+ commands.cfg
60
+ htpasswd.users
61
+ nagios.cfg
62
+ conf.d/contacts_nagios2.cfg
63
+ conf.d/extinfo_nagios2.cfg
64
+ conf.d/generic-host_nagios2.cfg
65
+ conf.d/generic-service_nagios2.cfg
66
+ conf.d/hostgroups_nagios2.cfg
67
+ conf.d/services_nagios2.cfg
68
+ conf.d/timeperiods_nagios2.cfg
69
+ conf.d/hosts/localhost_nagios2.cfg
70
+ ).each do |filename|
71
+ SYSTEM_CONFIG_FILES[:nagios] << {
72
+ :path => "/etc/nagios3/#{filename}",
73
+ :template => "#{filename}",
74
+ :mode => 0644,
75
+ :owner => 'root:root'
76
+ }
77
+ end
78
+ # ..except this one.
79
+ SYSTEM_CONFIG_FILES[:nagios] << {
80
+ :path => "/etc/nagios3/resource.cfg",
81
+ :template => "resource.cfg",
82
+ :mode => 0640,
83
+ :owner => 'root:nagios'
84
+ }
85
+
86
+ desc "Generate configuration file(s) for nagios from template(s)"
87
+ task :config_gen do
88
+ SYSTEM_CONFIG_FILES[:nagios].each do |file|
89
+ deprec2.render_template(:nagios, file)
90
+ end
91
+ end
92
+
93
+ desc "Push nagios config files to server"
94
+ task :config, :roles => :nagios do
95
+ add_host_configs
96
+ deprec2.push_configs(:nagios, SYSTEM_CONFIG_FILES[:nagios])
97
+ config_check
98
+ reload
99
+ end
100
+
101
+ # Dynamically add host config files to SYSTEM_CONFIG_FILES[:nagios]
102
+ task :add_host_configs, :roles => :nagios do
103
+ host_conf_dir = 'config/nagios/etc/nagios3/conf.d/hosts'
104
+ if File.directory? host_conf_dir
105
+ Dir.foreach(host_conf_dir).reject{|f| f =~ /\.\.?$/}.each do |filename|
106
+ SYSTEM_CONFIG_FILES[:nagios] << {
107
+ :path => "/etc/nagios3/conf.d/hosts/#{filename}",
108
+ :mode => 0644,
109
+ :owner => 'root:root'
110
+ }
111
+ end
112
+ end
113
+ end
114
+
115
+ desc "Run Nagios config check"
116
+ task :config_check, :roles => :nagios do
117
+ run "#{sudo} /usr/sbin/nagios3 -v /etc/nagios3/nagios.cfg"
118
+ end
119
+
120
+ desc "Generate a nagios host config file"
121
+ task :gen_host do
122
+ set(:nagios_target_host_name) { Capistrano::CLI.ui.ask "hostname"}
123
+ set(:nagios_target_hostgroups) {
124
+ Capistrano::CLI.ui.ask "hostgroups" do |q|
125
+ q.default = 'linux-servers'
126
+ end
127
+ }
128
+ set(:nagios_target_address) {
129
+ Capistrano::CLI.ui.ask "ip address" do |q|
130
+ q.default = IPSocket.getaddress(nagios_target_host_name)
131
+ end
132
+ }
133
+ file = {
134
+ :path => "/etc/nagios3/conf.d/hosts/#{nagios_target_host_name}.cfg",
135
+ :template => "host_template.erb",
136
+ :mode => 0644,
137
+ :owner => 'root:root'
138
+ }
139
+ deprec2.render_template(:nagios, file)
140
+ puts
141
+ puts "You can push it to the server with:"
142
+ puts
143
+ puts " cap deprec:nagios:config"
144
+ puts
145
+ end
146
+
147
+ # Control
148
+
149
+ desc "Start Nagios"
150
+ task :start, :roles => :nagios do
151
+ run "#{sudo} /etc/init.d/nagios3 start"
152
+ end
153
+
154
+ desc "Stop Nagios"
155
+ task :stop, :roles => :nagios do
156
+ run "#{sudo} /etc/init.d/nagios3 stop"
157
+ end
158
+
159
+ desc "Restart Nagios"
160
+ task :restart, :roles => :nagios do
161
+ run "#{sudo} /etc/init.d/nagios3 restart"
162
+ end
163
+
164
+ desc "Reload Nagios"
165
+ task :reload, :roles => :nagios do
166
+ run "#{sudo} /etc/init.d/nagios3 reload"
167
+ end
168
+
169
+ task :backup, :roles => :web do
170
+ # not yet implemented
171
+ end
172
+
173
+ task :restore, :roles => :web do
174
+ # not yet implemented
175
+ end
176
+
177
+ end
178
+
179
+ end
180
+ end