From ed23fce595a2967b8c41c4e9c1102ede474beb88 Mon Sep 17 00:00:00 2001 From: saulius Date: Sun, 6 Apr 2008 15:10:37 +0300 Subject: [PATCH] initial --- CHANGELOG | 138 ++ COPYING | 19 + LICENSE | 339 +++++ README | 136 ++ THANKS | 5 + bin/centify | 137 ++ docs/ANNOUNCE.deprec2 | 47 + docs/README.install | 88 ++ docs/README.nagios | 28 + docs/README.rails | 20 + docs/README.svn | 31 + docs/ROADMAP.txt | 74 + docs/deprec-1.x/deprec-1.x.quickstart | 50 + docs/deprec-1.x/notes.txt | 12 + docs/deprec_banner.gif | Bin 0 -> 3952 bytes lib/centostrano.rb | 8 + lib/deprec/capistrano_extensions.rb | 378 +++++ lib/deprec/recipes.rb | 28 + lib/deprec/recipes/aoe.rb | 117 ++ lib/deprec/recipes/apache.rb | 180 +++ lib/deprec/recipes/canonical.rb | 57 + lib/deprec/recipes/deprec.rb | 155 ++ lib/deprec/recipes/deprecated.rb | 71 + lib/deprec/recipes/example.rb | 115 ++ lib/deprec/recipes/git.rb | 151 ++ lib/deprec/recipes/heartbeat.rb | 138 ++ lib/deprec/recipes/memcache.rb | 49 + lib/deprec/recipes/mongrel.rb | 186 +++ lib/deprec/recipes/monit.rb | 131 ++ lib/deprec/recipes/mysql.rb | 115 ++ lib/deprec/recipes/nagios.rb | 296 ++++ lib/deprec/recipes/network.rb | 57 + lib/deprec/recipes/nginx.rb | 166 +++ lib/deprec/recipes/ntp.rb | 96 ++ lib/deprec/recipes/php.rb | 100 ++ lib/deprec/recipes/postfix.rb | 105 ++ lib/deprec/recipes/postgresql.rb | 116 ++ lib/deprec/recipes/rails.rb | 316 ++++ lib/deprec/recipes/ruby.rb | 66 + lib/deprec/recipes/ssh.rb | 93 ++ lib/deprec/recipes/subversion.rb | 166 +++ lib/deprec/recipes/trac.rb | 254 ++++ lib/deprec/recipes/users.rb | 90 ++ lib/deprec/recipes/xen.rb | 92 ++ lib/deprec/templates/aoe/aoe-init | 55 + lib/deprec/templates/aoe/fence_aoemask | 351 +++++ .../templates/apache/httpd-vhost-app.conf.erb | 144 ++ lib/deprec/templates/apache/httpd.conf | 465 ++++++ lib/deprec/templates/apache/index.html.erb | 37 + lib/deprec/templates/apache/master.css | 72 + lib/deprec/templates/centos/repository.erb | 6 + lib/deprec/templates/coraid/aoe-init | 55 + lib/deprec/templates/deprec/caprc.erb | 14 + lib/deprec/templates/heartbeat/authkeys.erb | 2 + lib/deprec/templates/heartbeat/ha.cf.erb | 15 + .../templates/heartbeat/haresources.erb | 1 + .../mongrel/mongrel_cluster-init-script | 54 + .../mongrel/mongrel_cluster.logrotate.d | 14 + .../templates/mongrel/mongrel_cluster.yml.erb | 10 + lib/deprec/templates/monit/monit-init-script | 104 ++ lib/deprec/templates/monit/monit_mongrel.erb | 17 + lib/deprec/templates/monit/monitrc.erb | 227 +++ lib/deprec/templates/monit/nothing | 0 .../templates/mysql/create_databases.sql | 20 + lib/deprec/templates/mysql/database.yml.prod | 6 + lib/deprec/templates/mysql/database.yml.stage | 6 + lib/deprec/templates/mysql/my.cnf.erb | 140 ++ lib/deprec/templates/mysql/sphinx.conf.prod | 542 +++++++ lib/deprec/templates/mysql/sphinx.conf.stage | 542 +++++++ lib/deprec/templates/nagios/cgi.cfg.erb | 321 +++++ lib/deprec/templates/nagios/commands.cfg.erb | 240 ++++ lib/deprec/templates/nagios/contacts.cfg.erb | 75 + lib/deprec/templates/nagios/hosts.cfg.erb | 70 + lib/deprec/templates/nagios/htpasswd.users | 1 + lib/deprec/templates/nagios/localhost.cfg.erb | 157 ++ lib/deprec/templates/nagios/nagios.cfg.erb | 1274 +++++++++++++++++ .../nagios/nagios_apache_vhost.conf.erb | 45 + lib/deprec/templates/nagios/nrpe.cfg.erb | 208 +++ lib/deprec/templates/nagios/nrpe.xinetd.erb | 16 + lib/deprec/templates/nagios/resource.cfg.erb | 34 + lib/deprec/templates/nagios/services.cfg.erb | 7 + lib/deprec/templates/nagios/templates.cfg.erb | 190 +++ .../templates/nagios/timeperiods.cfg.erb | 94 ++ lib/deprec/templates/network/hostname.erb | 1 + lib/deprec/templates/network/hosts.erb | 2 + lib/deprec/templates/network/interfaces.erb | 22 + lib/deprec/templates/nginx/mime.types.erb | 70 + lib/deprec/templates/nginx/nginx-init-script | 62 + lib/deprec/templates/nginx/nginx.conf.erb | 118 ++ lib/deprec/templates/nginx/nginx.logrotate.d | 12 + lib/deprec/templates/nginx/nothing.conf | 1 + .../nginx/rails_nginx_vhost.conf.erb | 41 + lib/deprec/templates/ntp/ntp.conf.erb | 42 + lib/deprec/templates/postfix/aliases.erb | 3 + .../templates/postfix/dynamicmaps.cf.erb | 8 + lib/deprec/templates/postfix/main.cf.erb | 41 + lib/deprec/templates/postfix/master.cf.erb | 77 + lib/deprec/templates/ssh/ssh_config.erb | 50 + lib/deprec/templates/ssh/sshd_config.erb | 78 + .../templates/subversion/svn.apache.vhost.erb | 43 + .../templates/trac/apache_vhost.conf.erb | 24 + lib/deprec/templates/trac/trac.ini.erb | 106 ++ lib/deprec/templates/trac/trac_deprec.png | Bin 0 -> 9743 bytes lib/deprec/templates/trac/tracd-init.erb | 43 + lib/deprec/templates/xen/15-disable-hwclock | 40 + .../templates/xen/network-bridge-wrapper | 3 + lib/deprec/templates/xen/xen-tools.conf.erb | 220 +++ lib/deprec/templates/xen/xend-config.sxp.erb | 195 +++ lib/deprec/templates/xen/xend-init.erb | 69 + lib/deprec/templates/xen/xendomains.erb | 137 ++ lib/deprec/templates/xen/xm.tmpl.erb | 85 ++ lib/vmbuilder_plugins/all.rb | 20 + lib/vmbuilder_plugins/apt.rb | 93 ++ lib/vmbuilder_plugins/emerge.rb | 76 + lib/vmbuilder_plugins/gem.rb | 90 ++ lib/vmbuilder_plugins/std.rb | 203 +++ 116 files changed, 12722 insertions(+) create mode 100644 CHANGELOG create mode 100644 COPYING create mode 100644 LICENSE create mode 100644 README create mode 100644 THANKS create mode 100755 bin/centify create mode 100644 docs/ANNOUNCE.deprec2 create mode 100644 docs/README.install create mode 100644 docs/README.nagios create mode 100644 docs/README.rails create mode 100644 docs/README.svn create mode 100644 docs/ROADMAP.txt create mode 100644 docs/deprec-1.x/deprec-1.x.quickstart create mode 100644 docs/deprec-1.x/notes.txt create mode 100644 docs/deprec_banner.gif create mode 100644 lib/centostrano.rb create mode 100644 lib/deprec/capistrano_extensions.rb create mode 100644 lib/deprec/recipes.rb create mode 100644 lib/deprec/recipes/aoe.rb create mode 100644 lib/deprec/recipes/apache.rb create mode 100644 lib/deprec/recipes/canonical.rb create mode 100644 lib/deprec/recipes/deprec.rb create mode 100644 lib/deprec/recipes/deprecated.rb create mode 100644 lib/deprec/recipes/example.rb create mode 100644 lib/deprec/recipes/git.rb create mode 100644 lib/deprec/recipes/heartbeat.rb create mode 100644 lib/deprec/recipes/memcache.rb create mode 100644 lib/deprec/recipes/mongrel.rb create mode 100644 lib/deprec/recipes/monit.rb create mode 100644 lib/deprec/recipes/mysql.rb create mode 100644 lib/deprec/recipes/nagios.rb create mode 100644 lib/deprec/recipes/network.rb create mode 100644 lib/deprec/recipes/nginx.rb create mode 100644 lib/deprec/recipes/ntp.rb create mode 100644 lib/deprec/recipes/php.rb create mode 100644 lib/deprec/recipes/postfix.rb create mode 100644 lib/deprec/recipes/postgresql.rb create mode 100644 lib/deprec/recipes/rails.rb create mode 100644 lib/deprec/recipes/ruby.rb create mode 100644 lib/deprec/recipes/ssh.rb create mode 100644 lib/deprec/recipes/subversion.rb create mode 100644 lib/deprec/recipes/trac.rb create mode 100644 lib/deprec/recipes/users.rb create mode 100644 lib/deprec/recipes/xen.rb create mode 100644 lib/deprec/templates/aoe/aoe-init create mode 100644 lib/deprec/templates/aoe/fence_aoemask create mode 100644 lib/deprec/templates/apache/httpd-vhost-app.conf.erb create mode 100644 lib/deprec/templates/apache/httpd.conf create mode 100644 lib/deprec/templates/apache/index.html.erb create mode 100644 lib/deprec/templates/apache/master.css create mode 100644 lib/deprec/templates/centos/repository.erb create mode 100644 lib/deprec/templates/coraid/aoe-init create mode 100644 lib/deprec/templates/deprec/caprc.erb create mode 100644 lib/deprec/templates/heartbeat/authkeys.erb create mode 100644 lib/deprec/templates/heartbeat/ha.cf.erb create mode 100644 lib/deprec/templates/heartbeat/haresources.erb create mode 100644 lib/deprec/templates/mongrel/mongrel_cluster-init-script create mode 100644 lib/deprec/templates/mongrel/mongrel_cluster.logrotate.d create mode 100644 lib/deprec/templates/mongrel/mongrel_cluster.yml.erb create mode 100644 lib/deprec/templates/monit/monit-init-script create mode 100644 lib/deprec/templates/monit/monit_mongrel.erb create mode 100644 lib/deprec/templates/monit/monitrc.erb create mode 100644 lib/deprec/templates/monit/nothing create mode 100644 lib/deprec/templates/mysql/create_databases.sql create mode 100644 lib/deprec/templates/mysql/database.yml.prod create mode 100644 lib/deprec/templates/mysql/database.yml.stage create mode 100644 lib/deprec/templates/mysql/my.cnf.erb create mode 100644 lib/deprec/templates/mysql/sphinx.conf.prod create mode 100644 lib/deprec/templates/mysql/sphinx.conf.stage create mode 100644 lib/deprec/templates/nagios/cgi.cfg.erb create mode 100644 lib/deprec/templates/nagios/commands.cfg.erb create mode 100644 lib/deprec/templates/nagios/contacts.cfg.erb create mode 100644 lib/deprec/templates/nagios/hosts.cfg.erb create mode 100644 lib/deprec/templates/nagios/htpasswd.users create mode 100644 lib/deprec/templates/nagios/localhost.cfg.erb create mode 100644 lib/deprec/templates/nagios/nagios.cfg.erb create mode 100644 lib/deprec/templates/nagios/nagios_apache_vhost.conf.erb create mode 100644 lib/deprec/templates/nagios/nrpe.cfg.erb create mode 100644 lib/deprec/templates/nagios/nrpe.xinetd.erb create mode 100644 lib/deprec/templates/nagios/resource.cfg.erb create mode 100644 lib/deprec/templates/nagios/services.cfg.erb create mode 100644 lib/deprec/templates/nagios/templates.cfg.erb create mode 100644 lib/deprec/templates/nagios/timeperiods.cfg.erb create mode 100644 lib/deprec/templates/network/hostname.erb create mode 100644 lib/deprec/templates/network/hosts.erb create mode 100644 lib/deprec/templates/network/interfaces.erb create mode 100644 lib/deprec/templates/nginx/mime.types.erb create mode 100644 lib/deprec/templates/nginx/nginx-init-script create mode 100644 lib/deprec/templates/nginx/nginx.conf.erb create mode 100644 lib/deprec/templates/nginx/nginx.logrotate.d create mode 100644 lib/deprec/templates/nginx/nothing.conf create mode 100644 lib/deprec/templates/nginx/rails_nginx_vhost.conf.erb create mode 100644 lib/deprec/templates/ntp/ntp.conf.erb create mode 100644 lib/deprec/templates/postfix/aliases.erb create mode 100644 lib/deprec/templates/postfix/dynamicmaps.cf.erb create mode 100644 lib/deprec/templates/postfix/main.cf.erb create mode 100644 lib/deprec/templates/postfix/master.cf.erb create mode 100644 lib/deprec/templates/ssh/ssh_config.erb create mode 100644 lib/deprec/templates/ssh/sshd_config.erb create mode 100644 lib/deprec/templates/subversion/svn.apache.vhost.erb create mode 100644 lib/deprec/templates/trac/apache_vhost.conf.erb create mode 100644 lib/deprec/templates/trac/trac.ini.erb create mode 100644 lib/deprec/templates/trac/trac_deprec.png create mode 100644 lib/deprec/templates/trac/tracd-init.erb create mode 100644 lib/deprec/templates/xen/15-disable-hwclock create mode 100644 lib/deprec/templates/xen/network-bridge-wrapper create mode 100644 lib/deprec/templates/xen/xen-tools.conf.erb create mode 100644 lib/deprec/templates/xen/xend-config.sxp.erb create mode 100644 lib/deprec/templates/xen/xend-init.erb create mode 100644 lib/deprec/templates/xen/xendomains.erb create mode 100644 lib/deprec/templates/xen/xm.tmpl.erb create mode 100644 lib/vmbuilder_plugins/all.rb create mode 100644 lib/vmbuilder_plugins/apt.rb create mode 100644 lib/vmbuilder_plugins/emerge.rb create mode 100644 lib/vmbuilder_plugins/gem.rb create mode 100644 lib/vmbuilder_plugins/std.rb diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..037a653 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,138 @@ +== SVN + +== 1.99.15 (Mar 27, 2008) + +* moved vmbuilder_plugins out of deprec dir + +== 1.99.14 (Feb 21, 2008) + +* monit template now uses :mongrel_port instead of 8000 + +== 1.99.11 (Feb 21, 2008) + +* enabled evented mongrel +* enhancement: updated how allowed hosts are generated +* bugfix: remove nginx index.html + +== 1.99.8 (Feb 18, 2008) + +* enhancement: added nginx_client_max_body_size setting for nginx rails vhost +* bugfix: monit config was broken + +== 1.99.7 (Feb 18, 2008) + +* enhancement: nginx vhost config now serves up assetX.hostname.com +* enhancement: deprec:db:schema_load is nicer than running migration initially + +== 1.99.6 (Feb 15, 2008) + +* bugfix: fixed monit support [Mike Bailey] + +* bugfix: Mongrel wasn't starting when server rebooted. [Mike Bailey] + +* bugfix: Fixed .caprc content [Mike Bailey] + +== 1.99.5 (Feb 12, 2008) + +* feature: installs and configures monit to manage your mongrel processes [Mike Bailey] + +* feature: When running config_gen, if deprec discovers a file exists, checks + whether the new file differs from the existing one. If they're + identical, it skips it. + + If they differ, the user is presented with the options to overwrite + or not but now there's an extra option to view a diff of the changes + that would occur. [Mike Bailey] + +* change: handle_command_with_input now accepts an optional response parameter. + This is useful if you need to change a password on many servers and + don't want to have to keep entering the password at the prompt for + each box. [Mike Bailey] + +== 1.99.4 (Feb 11, 2008) + +* Bugfix: set correct path to templates [Mike Bailey] + +deprec changelog (check the timeline at http://trac.deprecated.org/trac.cgi/timeline) + +== 1.10.0 +Massive changes in preparation for 2.0 + +== 1.8.0 + +* fixed scm_setup. it parses :repository if set and prompts user for values if not [Mike Bailey] +* added "role :scm, domain" to generated deploy.rb [Mike Bailey] +* added :trac_install, :trac_setup, :trac_start, :trac_stop [Mike Bailey] +* added :change_root_password and :change_root_password_as_root [Mike Bailey] +* moved templates dir [Mike Bailey] +* bugfix :db_setup now re-runnable + +== 1.7.1 + +* bugfix: setup_ssh_keys() - print message and exit if ssh_options[:keys] not set [Mike Bailey] + +== 1.7.0 + +* new tasks :install_memcached, :memcached_start, :memcached_stop, :memcached_restart [Mike Bailey] +* set default shell to '/bin/bash' for new users [Mike Bailey] +* bugfix: set default values for mongrel_user and mongrel_group [Mike Bailey] + +== 1.6.0 + +* new task :install_php installs php-5.2.2 [Mike Bailey] + +== 1.5.1 + +* bugfix: fixed bug in su_put that was causing Windows [Mike Bailey] + +== 1.5.0 + +* bugfix: :set_perms_for_mongrel_dirs [Mike Bailey] + - now don't fail if log files do not exist (e.g initial deployment) + - is called by :after_symlink task instead of :after_update + this is because some tasks call :update_code without calling the + :update task but in all of these cases :symlink is called + +* updated version from 1.4.x to 1.5.x due to pretty big change made + in previous version (mongrel no longer running as root) [Mike Bailey] + +== 1.4.2 + +* change: mongrel no longer runs as root for security reasons [Mike Bailey] +* bugfix: install apache version 2.2.4 as previous version is no longer on their webserver [Mike Bailey] +* bugfix: fixed install_rubygems so install_rails_stack no longer fails when first run [Mike Bailey] + +== 1.4.0 + +* renamed svn commands and made svn_create_repos re-runable [Mike Bailey] +* bugfix: Wildcard Apache NameVirtualHosts directive used be used just once [Mike Bailey] + +== 1.3.1 + +* bugfix + +== 1.3.0 + +* added md5sum checking to deprec.download_src [Mike Bailey] +* new function: deprec.mkdir(path, mode=0755, group=nil, user=nil) [Mike Bailey] +* start apache and mongrel on server boot [Mike Bailey] +* removed deprec_dotfiles script as the Cap code it patches is now in Capistrano source. [Mike Bailey] +* changed from LGPG to GPL licence. [Mike Bailey] + +== 1.2.2 + +* Added enable_multiverse(), disable_multiverse() tasks for ubuntu package management [Mike Bailey] +* Removed termios as a gem requirement as it doesn't work on Windows [Mike Bailey] + +== 1.2.1 + +* Updated railsmachine code to include SSL fix from new release [Mike Bailey] + +== 1.2.0 + +* Added run_with_input and sudo_with_input for interactive tasks. [topfunky] +* Added sudo_stream for piping the output of a privileged command like the built-in stream() [topfunky] +* svn_cache_credentials task does an interactive svn list to make http-based repository deployments easier. [topfunky] +* Alternate deprec/recipes/cache_svn task overrides the built-in update_code task with a more efficient version. [topfunky] + + diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..e7f0d48 --- /dev/null +++ b/COPYING @@ -0,0 +1,19 @@ +Copyright (c) 2006-2008 Mike Bailey + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d511905 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/README b/README new file mode 100644 index 0000000..5090c26 --- /dev/null +++ b/README @@ -0,0 +1,136 @@ +------------------------------------------ +deprec - Deployment Recipes for Capistrano +------------------------------------------ + +== Introduction + +The deprec [1] gem is a set of tasks for Capistrano [2]. These tasks provide +for the installation, configuration and control of system services. Deprec +was created in 2006 by Mike Bailey to setup an environment for running Ruby +on Rails web applications on Ubuntu dapper servers. Since then its uses have +grown to installing mail, monitoring, high availability IP failover and other +services. + +The tasks are run at the command line on your workstation and connect to +remote servers via ssh to run commands and copy out files. + +Deprec-2.x is a complete rewrite of the project that achieves the following: + +- support for Capistrano 2 +- support for more services (heartbeat, nagios, nginx, ntp, postfix, etc) +- creation of a standard base set of task names +- tasks are cleanly separated into namespaced units (one file per service) +- service config files are stored locally to enable edits and version control +- interactive prompting for missing config values + +One idea that is in the trash can is supporting other distros/OS's. While I got +caught up in the excitement of The Big Rewrite I've decided I don't need it. If +you want to deploy to something other than Ubuntu I suggest you look for other +alternatives. + +Deprec and Capistrano are written in the Ruby programming language [3] however +no knowledge of Ruby is required to use it. Users should be able to write +new tasks and modify existing options without prior knowledge of Ruby. + + +== Installation + +Deprec can be obtained from rubyforge[4] and installed using rubygems[5]. + + sudo gem install deprec # installs deprec and dependancies + cap depify . # creates ~/.caprc which you may edit + cap -T # should list lots of deprec tasks + +The .caprc file is loaded every time you use Capistrano. It in turn loads +the deprec tasks so you always have them available. Editing the .caprc file +in your home directory allows you to specify the location of your ssh key +and enable some other useful options (documented in the comments). You can +also put tasks here that you want to always have access to. + + +== Getting a Ruby on Rails app running on a fresh Ubuntu server + +This is still what brings people to deprec. You can install a full Rails stack +and get multiple apps running on it in much less time than it would take to +do it manually. Think an hour vs. a weekend. (The irony is I'm up writing this +on a Saturday night.) + + export HOSTS= + + # Install Rails stack + cap deprec:rails:install_rails_stack + + # Install mysql (if it's running on the same box) + cap deprec:mysql:install + cap deprec:mysql:config_gen + cap deprec:mysql:config + + # Install your Rails app + cap deploy:setup + cap deploy + cap deprec:db:create + cap deprec:db:migrate + cap deprec:nginx:restart + cap deprec:mongrel:restart + +You can find documentation on the deprec site. http://www.deprec.org/ + + +== Installing other things + +I plan to document other things I use deprec for on http://www.deprec.org/. +Feel free to poke around and see what's there. I use deprec to provision and +manage servers so you might find some things in there I haven't documented. Lucky you. + + +== Disclaimer + +The tasks run commands that may make changes to your workstation and remote server. +You are advised to read the source and use at your own risk. + + +== Credits + +Deprec is written and maintained by Mike Bailey . +More about me here: [http://mike.bailey.net.au/] + +Deprec was inspired and uses the brilliantly executed Capistrano. Thanks Jamis! +This gem includes a modified copy of Neil Wilson's very useful vmbuilder_plugins gem. + + +== Thanks + +Eric Harris-Braun: great testing, bug reports and suggestions +Gus Gollings: helped restore www.deprec.org +Craig Ambrose: testing, documentation and beer + + +== License + +Deprec is licenced under the GPL. This means that you can use it in commercial +or open source applications. More details found here: +http://www.gnu.org/licenses/gpl.html + +deprec - deployment recipes for capistrano +Copyright (C) 2006-2008 Mike Bailey + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + +[1] http://www.deprec.org +[2] http://www.capify.org +[3] http://www.ruby-lang.org/en/ +[4] http://rubyforge.org/ +[5] http://rubygems.org/ \ No newline at end of file diff --git a/THANKS b/THANKS new file mode 100644 index 0000000..54e1839 --- /dev/null +++ b/THANKS @@ -0,0 +1,5 @@ +Big thanks go to the following people. Apologies to any I have missed! - Mike + +20080226 Chris Turner for an excellent HOWTO http://crackthenut.cracklabs.com/deprec2-your-slice-from-windows/ +20080206 Eric Harris-Braun for some great testing, bug reports and suggestions. +20071004 Gus Gollings for helping restore www.deprec.org diff --git a/bin/centify b/bin/centify new file mode 100755 index 0000000..f9f0557 --- /dev/null +++ b/bin/centify @@ -0,0 +1,137 @@ +#!/usr/bin/env ruby + +require 'optparse' + +OptionParser.new do |opts| + opts.banner = "Usage: #{File.basename($0)} [path]" + + opts.on("-h", "--help", "Displays this help info") do + puts opts + exit 0 + end + + begin + opts.parse!(ARGV) + rescue OptionParser::ParseError => e + warn e.message + puts opts + exit 1 + end +end + +if ARGV.empty? + abort "Please specify the directory to centify, e.g. `#{File.basename($0)} .'" +elsif !File.exists?(ARGV.first) + abort "`#{ARGV.first}' does not exist." +elsif !File.directory?(ARGV.first) + abort "`#{ARGV.first}' is not a directory." +elsif ARGV.length > 1 + abort "Too many arguments; please specify only the directory to centify." +end + +def unindent(string) + indentation = string[/\A\s*/] + string.strip.gsub(/^#{indentation}/, "") +end + + +caprc = unindent(<<-FILE) + # .caprc - Capistrano configs (added by deprec gem [www.deprec.org]) + # + # Include settings that you want active whenever you use Capistrano + # You can over ride these for particular projects by putting entries + # into Capfile or deploy.rb for those projects + # + # Uncomment any of the following entries to enable them. + # + # Include deprec - deployment recipes for Capistrano (www.deprec.org) + # + # require 'deprec' + # + # Include centostrano - CentOS deployment recipes for Capistrano (www.rubyonrails.lt/centostrano) + # + require 'centostrano' + # + # SSH options + # + # Use ssh keys instead of typing password every time + # Replace with the path to your ssh public key + # ssh_options[:keys] = %w(/path/to/your_home_dir/.ssh/id_rsa) + # + # Allow ssh keys to be forwarded (to scm server, through :gateway, etc) + # ssh_options[:forward_agent] = true + # + # Stop some annoying warnings + # ssh_options[:paranoid] = false +FILE + +files = { + "Capfile" => unindent(<<-FILE), + load 'deploy' if respond_to?(:namespace) # cap2 differentiator + Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } + Dir['config/*/recipes.rb'].each { |plugin| load(plugin) } + load 'config/deploy' + FILE + + "config/deploy.rb" => unindent(<<-FILE), + require 'centostrano' + + set :application, "set your application name here" + set :domain, "set domain name project will be served on here" + set :repository, "svn+ssh://\#{domain}/var/www/apps/\#{application}/repos" + # set :gems_for_project, %w(dr_nic_magic_models swiftiply) # list of gems to be installed + + # Update these if you're not running everything on one host. + role :app, domain + role :web, domain + role :db, domain, :primary => true + role :scm, domain # used by deprec if you want to install subversion + + # If you aren't deploying to /var/www/apps/\#{application} on the target + # servers (which is the deprec default), you can specify the actual location + # via the :deploy_to variable: + # set :deploy_to, "/var/www/\#{application}" + + # If you aren't using Subversion to manage your source code, specify + # your SCM below: + # set :scm, :subversion + + namespace :deploy do + task :restart, :roles => :app, :except => { :no_release => true } do + top.deprec.mongrel.restart + end + end + + FILE +} + +def create_file(file, content) + if !File.exists?(File.dirname(file)) + puts "[add] creating directory `#{File.dirname(file)}'" + Dir.mkdir(File.dirname(file)) + end + if File.exists?(file) + warn "[skip] `#{file}' already exists" + elsif File.exists?(file.downcase) + warn "[skip] `#{file.downcase}' exists, which could conflict with `#{file}'" + else + puts "[add] writing `#{file}'" + File.open(file, "w") { |f| f.write(content) } + end +end + +create_file(File.join(ENV['HOME'], '.caprc'), caprc) + +base = ARGV.shift +config_dir = File.join(base,'config') +if File.directory?(config_dir) + files.each do |file, content| + create_file(File.join(base, file), content) + end +else + warn "[warn] directory `#{config_dir}' does not exist" + warn "[skip] '#{base}/Capfile'" + warn "[skip] '#{base}/config/deploy.rb'" +end + +puts "[done] centified!" diff --git a/docs/ANNOUNCE.deprec2 b/docs/ANNOUNCE.deprec2 new file mode 100644 index 0000000..859b85d --- /dev/null +++ b/docs/ANNOUNCE.deprec2 @@ -0,0 +1,47 @@ +== Configuration + +deprec2 has a two stage process for generating/deploying configuration files. +Configuration files for web, app, db servers (and more) are generated from +templates and put under the config/ tree in your Rails apps source tree. +Alternatively you could create a non-rails-app tree to hold them. The second +stage is pushing the files out to the destination servers. This used to be a +one stage process in deprec1 however the change has been made so that: + +- all config files for a project can be kept under source control +- you can make changes to config files that are not available through deprec + +Many of the settings in these config files are based on values in the projects +deploy.rb file. Others reflect defaults in deprec that you can override by adding +fields to deploy.rb. This means you may never need to edit the generated config +files directly. You can generate a set of config files with the following: + + cap deprec:nginx:config_gen # generates config files for trac from templates + +config_gen is re-runnable and will prompt you before overwriting a file. It will +also show you what changes overwriting would make (in diff format) to help you +decide whether you want it to do so. + +Changes to service configuration should never be made on the server. Deprec +acknowledges this by offering no assistance to people who want to copy config +files back from servers. But pushing the files out couldn't be simpler! + + cap deprec:nginx:config # pushes out all config files for trac + +deprec2 takes into consideration the fact that that some services are used to +host more than one application. For example, a webserver will often have one +main configuration and a number of virtual host configurations. Monit has a +single config file (/etc/monitrc) but will also load other configs it finds in +a certain directory (/etc/monit.d). + +When you deploy a Ruby on Rails app with deprec it drops configs for your project +into the config/ directory for your project and symlinks them into a shared path +on the server. This means you can install multiple apps on a remote server and +they shouldn't stop on each other. + +== Extra services + +- nginx +- monit +- postfix +- nagios +- more... \ No newline at end of file diff --git a/docs/README.install b/docs/README.install new file mode 100644 index 0000000..f8199a9 --- /dev/null +++ b/docs/README.install @@ -0,0 +1,88 @@ +== Installation and initial setup for deprec2 + +Install deprec with the following command (requires ruby and rubygems installed) + + sudo gem install deprec + +Let's create a directory to manage all our host config details +This supports as many hosts as you need to manage and will be the dir +you run your deprec commands from when managing the servers. Note that +you don't need to do this if you just want to deploy a single Ruby on +Rails application. In this case the config/ dir in your project can +serve the same purpose. For those who aren't interested in Ruby on Rails +or want to use deprec for more than just deploying one rails app, the +following may come in handy. + + mkdir -p sys/config # change 'sys' to whatever you want + cd sys # + depify . # create Capfile and config/deploy.rb + cap deprec:ssh:config_gen # generates ssh server configs + +If you have an authorized_keys file, copy it to a location where deprec +can find it. Deprec will then offer to copy it out to remote hosts when +you setup new accounts for yourself. If you don't have authorized_keys, +copy out your id_rsa.pub or id_dsa.pub. + +You can also put the authorized_keys of colleagues in this dir and deprec +will offer to copy them out when creating accounts for them too. + +We name these files using the username of their owner. + + cp ~/.ssh/authorized_keys config/ssh/authorized_keys/${USER} + +Define an environment variable for the server we'll be working on + + export HOSTS= + +Change the root password you received for your new slice. + + cap deprec:users:passwd USER=root + + Enter user to change password for |root| + Password: + Enter new UNIX password: + Retype new UNIX password: + + +Create an account with sudo access for mysql^H^Hself + + cap deprec:users:add USER=root + + Enter userid for new user |root| + mbailey + Should this be an admin account? |no| + yes + I've found an authorized_keys file for mbailey. Should I copy it out? |yes| + Password: + Setting pasword for new account + Enter new UNIX password: + Retype new UNIX password: + + +Create another account without sudo access for a colleague. +Notice how I longer need to specify USER=root? That's because I'm using the +account I just created. + + cap deprec:users:add + + Enter userid for new user |mbailey| + ben + Should this be an admin account? |no| + Password: + Setting pasword for new account + Enter new UNIX password: + Retype new UNIX password: + +I prefer to disallow ssh password based login for security reasons. I also +turn off DNS lookups by sshd as they are often responsible for a 2 second +lag on login. Be warned that turning off ssh passwords will prevent someone +without an ssh key setup from logging in so use this with caution. Deprec +makes it painless to upload their key when you create their account though +so you've got no excuse to leave passwords turned on. + +You can upload the ssh configs currently residing in config/ssh/etc/ssh by +running this: + + cap deprec:ssh:config + +You can now continue to the other READMEs diff --git a/docs/README.nagios b/docs/README.nagios new file mode 100644 index 0000000..619b439 --- /dev/null +++ b/docs/README.nagios @@ -0,0 +1,28 @@ +deprec: Install and configure Nagios on Ubuntu 7.10 (gutsy) +=========================================================== + by Mike Bailey +* Quickstart + + # You need the following items defined (in config/deploy.rb) + set :application, 'nagios' + set :domain, 'nagios.host.name' + role :nagios, domain + role :app, 'nagios' + role :web, nil # must be defined but content not important + + # Run the following on your workstation + export HOSTS=nagios.domain.name # replace with desired domain + cap deprec:apache:install + cap deprec:apache:activate + cap deprec:nagios:install + cap deprec:nagios:activate + cap deprec:nagios_plugins:install + cap deprec:nagios:config_gen + cap deprec:nagios:htpass # create web logins + cap deprec:nagios:config + cap deprec:apache:restart + + +* The detail + +TBC \ No newline at end of file diff --git a/docs/README.rails b/docs/README.rails new file mode 100644 index 0000000..446dbed --- /dev/null +++ b/docs/README.rails @@ -0,0 +1,20 @@ +deprec: Install Ruby on Rails app on fresh Ubuntu 7.10 (gutsy) +============================================================== + by Mike Bailey + +* Quickstart + +cd /rails/project/root +depify . +# edit config/deploy.rb +cap deprec:rails:install_rails_stack HOSTS=target.host.name +cap deploy:setup +cap deploy +cap deprec:db:create +cap deprec:db:migrate +cap deprec:nginx:restart + + +* The detail + +TBC \ No newline at end of file diff --git a/docs/README.svn b/docs/README.svn new file mode 100644 index 0000000..86178d7 --- /dev/null +++ b/docs/README.svn @@ -0,0 +1,31 @@ +== svn + +# Add the following to your deploy.rb (or ~/.caprc if always the same) + set :scm, 'your.svn.server' + +# The run the following from the root the project you wish to import +cap deprec:svn:install +cap deprec:svn:setup + + +# XXX Not tested on deprec2 +# +# +# Installs subversion and trac software on server. +# Creates subversion repository on server and imports project. +# Sets up trac installation for project. +# +# role :scm, 'deptest.deprecated.org' +# +# # install packages +# cap apache_install svn_install trac_install +# +# # import project +# cap svn_import_project +# cap trac_init +# cap trac_start +# +# # your project will be viewable at http://yourdomain:8000/ +# # you can add other users with 'cap trac_user_add' + + diff --git a/docs/ROADMAP.txt b/docs/ROADMAP.txt new file mode 100644 index 0000000..0e0d50d --- /dev/null +++ b/docs/ROADMAP.txt @@ -0,0 +1,74 @@ +deprec 2.0 roadmap + +# expectations/constraints + +- all tasks should be re-runnable +- all install_ tasks should install required dependancies +- users should expect that standard cap commands will work + + +# interactive tools + +deprec should make it easy to perform commonly use sysadmin tasks. +While automation brings great power it's still often quicker to +run 'semi automated' tasks that require some interactive input. + +For example, adding a user account to a number of servers could be +made easier with a general purpose interactive recipe: + +cap add_user +> username for new user? : fred +> password for new user? : ****** +> retype password : ****** +> user type for new user? +1. default +2. admin +?: 2 +creating... +server01 - created user 'fred' of type 'admin' +server02 - created user 'fred' of type 'admin' +server03 - created user 'fred' of type 'admin' +server04 - user 'fred' exists. Set type to 'admin' + +* Note that the servers above were all servers mentioned in deploy.rb + for a project however there are many ways to get this list. + + +Plugin support for different distro's was too ambitious. I've tried other +distros and didn't like them much. I'm happy with Ubuntu at the moment and +# # plugin based support different distros, versions (and possibly OS's) +# +# While deprec was built to work with Ubuntu 6.06, some people have shown interest +# in using it with other distro's. I plan to move all of the Ubuntu specific code +# into a separate gem 'deprec_ubuntu' which deprec will load by default. This will +# mean anyone else can create and maintain plugins that allow the use of other linux +# distros (and perhaps other OS's). +# +# All platform dependent functions will be: +# +# - cap extensions, not tasks +# - plugins, not part of the deprec itself +# - loaded using gemplugins http://mongrel.rubyforge.org/gem_plugin_rdoc/index.html +# +# I'd like 'cap -T' to show the distros supported for each command when not arch independant. + + +# add lots more useful tasks + +I'd like to extend deprec beyond just getting your rails app up and running. +Anything I need that takes some time to do right will go in. If you've got +something you want added then write it and let me know. + +install and configure the following package groups: +- source control (svn, trac) +- mail (postfix, imap, mutt, mailx) + + +# don't rely on third party servers to be available when installing software + +As I write, www.apache.org is serving at a crawling pace. I'd like to make it easy for +users to download and cache all required third party apps, gems, etc and have deprec +use these. + +Currently you can drop the tarballs into /usr/local/src on the target server and +they'll get picked up automatically. I haven't looked at a simple way to cache the gems yet. diff --git a/docs/deprec-1.x/deprec-1.x.quickstart b/docs/deprec-1.x/deprec-1.x.quickstart new file mode 100644 index 0000000..612c952 --- /dev/null +++ b/docs/deprec-1.x/deprec-1.x.quickstart @@ -0,0 +1,50 @@ +# +# Old notes - YMMV +# + +== deprec quickstart (with svn, trac and deployment to apache/mongrel/mysql) + +Here are instructions that will take a fresh install of Ubuntu Dapper (6.06.1 server), create a working rails app, create an SVN repository and trac installation for it and deploy it using apache, mongrel and mysql. + +All commands below are run on your local host. You will *never* be requested +to log into the remote server manually. Capistrano does all the work. + +- Mike + +# Install deprec on workstation +sudo gem install deprec --include-dependencies +echo 'require "deprec/recipes"' >> ~/.caprc +echo "ssh_options[:keys] = %w(${HOME}/.ssh/id_dsa)" >> ~/.caprc +echo 'ssh_options[:paranoid] = false' >> ~/.caprc +echo 'ssh_options[:forward_agent] = true' >> ~/.caprc + +# Create rails project on workstation and configure for deprec +# (alternatively use an existing project) +rails example +cd example +./script/generate scaffold_resource person name:string age:integer +deprec --apply-to . --name example --domain www.example.com + +# NOTE! Use following two commands if you only have 'root' account on server +# Some VPS services provide you with this when you sign up +cap change_root_password_as_root # '_as_root' means run this as 'root' user +cap setup_admin_account_as_root + +# Copy your ssh keys to remote server to avoid having to type passwords +cap setup_ssh_keys + +# Install all required software on remote server +cap install_rails_stack svn_install trac_install + +# Import application into subversion respository and setup trac +cap svn_setup +cap trac_setup +cap trac_user_add # this command allows you to create other trac users +cap trac_start # trac is now available on http://www.example.com:9000/ +cap trac_stop # if you had the need + +# Deploy application +cap setup +cap deploy_with_migrations +cap apache_restart +# application is now running on http://www.example.com/people diff --git a/docs/deprec-1.x/notes.txt b/docs/deprec-1.x/notes.txt new file mode 100644 index 0000000..67f22a5 --- /dev/null +++ b/docs/deprec-1.x/notes.txt @@ -0,0 +1,12 @@ +# update timezone on gutsy +# dpkg-reconfigure tzdata + + +# Building Edge Capistrano +You can build an edge gem by cd'ing to that directory and doing: + +1. svn info. Find the line that says "Revision:" and mark the revision number. +2. rake PKG_BUILD= gem. Replace with the revision number. +3. Look in the pkg subdirectory. Install that gem file via "gem install pkg/" + +- Jamis \ No newline at end of file diff --git a/docs/deprec_banner.gif b/docs/deprec_banner.gif new file mode 100644 index 0000000000000000000000000000000000000000..b729bd949d803b26d035928aee947cbd2998a9dd GIT binary patch literal 3952 zcmd^;XT#V0cgHkw8CNnuQCu=|ugon{ znykpIoS7E1RJ5GXEUC=UP+PQIP;uowp6748*N5}_c^v2E?&)T?FL)C01Qvn+POVli zFR!nxtgo%9*VomPQ)@G`Yh^XF)s1s^A1t(Wsd`>4y&PN~kSz~=Sotuz^7-rPoN|43 zZcRDAZnRrrMH%0FaKg@e!o~NqyZ>ie$d@CbUyet7{WW&-x46mB#L1}CsoztlVlt-U zS>KX4-;%Sxr{#XnESx@5IL$dXomVzfP%%?P}558NL4K2SNUKt%*{W!k* zWpZ`$+uFk7`uCZ&Mb)}$X?<>fePva>x~5)QTUuFPSzcRSSFf+FuT84HPA`2Qntd}q zub5q)p;X!)tac1;KjM4UE4niBb3-G_Vfozqk-6coi=UM%a|^5U^DD}^rP&;5 z+Kmr_yQ4Smf4ud0y!Gj)hxcW-yFRx)`S57q+lv=t&)(0zc{eHhsFY94j(t;2eqI=# zUi!AQrc$jg&MnWZtSzstug=cSj*X2C4i5J8^gMj{P$Ux7*VmVomGOAIjEs!f*jPH9 ze)Q;3H#avsJ3DJ@>;FaZ{{{cE{qGk5j2eJr3_V1(ZCRL2RzVU`-IH9%%&W@dc6~H8O5cE{og!VY()rUVb+LicasC!ee_ay>j!O*Kk z*j=-StN&|H%QhFm-pgK>y^fQPo%gyP{r>N{XxdHslXm6B<4tew=y%uu`s`l)+k1?U z`tjOMStz_+)dpq(p9RMo*w8T}?NoLSTF2nfsHqL=0fK0HF~}xg-!@;K7x$anEhk;nKuUWA0L_>Gl-m5;L~4)l`luonRvH?+8h$m8usiugv!fVMDfPpqb0 z{ubrYh6Q@b%r7^7S<)kNuza- zdNtFH5H6XzwGc&1SLF+8^lO`Y{GmXy+%f_m*mh8k3aPChKXNp2f`GJhF&>>1ACcuK&)68R;E$b;s(11l`t+MWGFvY2 zFi;T1$MwxqKW;!xeHzZmz#vSEJsZ#`cwq_dITsG<3f`4k>tw^LOh@Q^UxqP_UlDe~ zl)vTo@{}%W1|p!E5W8diHSL@o?Ksr_qo;1z2%dDpq9KsiVcD;kdqM(?xnrisW zn_<0hCfjW*jPQ0?{}NWvbzPz9MKi`{nn);|!a-w`yoLYNXrt!!t9+1%y&UR3X)@T{ zwnUd=+Tu4)~y?{LSy!wFrUI9sEj?66W22JfBU+|g&cXIOX+{`MaXtHUW zS~ja&D~7N$-tW3?<7{o8f3+AeHVi6>+~ahF1Y4vS$WGHMKY0hn~wbH=({)Kj}ys=F2M*AjAX+zeF9m}Kn_kDA>lx#icLCO^V zlMdj$*7rNNU1mxH(bCOTNhkc{q%SF0L(22QEr|R&Q?D&+$^mo@wD9(yEqiIhdM(Z$ z&L-ymP36@-u2Za?Jg1aZ@V{WcCxVg_t1$`9-?k|-DKqa>Z|^+jAf#u;K>0GpkFxaZ zkH6r8b#iI4Yk*C|W>_`#|)sxY(#weXS=tWVghO0l4pv$ z&Vz7ZpGkvRh?5o@t$6dNw1y~e2j^E;9`w(0agHN^F zsL3K>-t?I5$x@O-aszer+4U^W260OAuCRmq>5z%k0{L$XR%4x@uKLl`r^v0IPYfUc zRxOdo5P4=P%QU_ftH3^*WzZkx48vkv&|5S@fmuwcR#hQppoxVn1s*IX$w8Pl%z>@r zZDq03BnA2eIF2}cOQPnSmeDo~<=DeEqjf{UVV!IgM{~`A24Qo#w-*#-P-UPtH!m(ulHf518ysu|jHx5mXbn;p zzlahCMzw2^BmvoY08_FyfQZ4A8k_5(Hs26q22$U>dTwIstBT1Or66-@CYq)`PYJDL z$Wjg2YQdD-&6gsWk?jmdPuHkx5WaG3)7Qr49u3WG=t=h=9Ld!<4M_; zt2)@Ds&@AoQqJB7+8T+fC&U>Wp1Xs#c8Th#maT2R@AD5v&8iNcB-_HsL(SXziPo<2 zUMChUyIADXWzdG$y5AJ%QwXyVK*+!V8k?6?`y zA#;bRmtzfBdQuiCC9{Q+ES=D`p0G39+(J>1u=W&FZIG31NTTvxJUB05)I>m9h}|ax zH^Du#jTCe&hZmqFvfyp=8^IkT@549PxRMd3xMPJd!c{Vld}wBz%^SrFr|(jRpHGGz zHu$%WwXm%;2Is5%TPC1zx50qPsQde5BjxuftcO!YEQ(tx*5q)-GIf8b=EqVvp2Q2VaIS@dS>x-RgSVO{i>{Al(fRp#m6Vo)j;#l zr|Pbl;$3`aFCMPbw%EAeJb8Zoon@dyY z^mOdSVfaQ+8J0$j8$5sG11qFFoL7 zMC?C{5icX5TcYF+J>1AbhIDUay*T{%#7W0S+*O;HkB#Bu?vQ|i`;(ve5v}3kcUmOQ zR9Iwgo;d|KiCBCM1_-&yjUXIMJDhyr$7!xI>A-FZjL6^D)WHQA2P*Gz12Bm4F0Kw4 z@@Hh&?nR{wbIWUUkuz+6AbM*g*5ZC{CJ!6KPw=Niw>E~KRKJe+WSPbI5A?I}q~ADh zzuzAeOGs3UJ3s`kFqn?$$aj&aVYWCA->jRp;qSWgitV7EWSN9%mbb2sGy#4tq5#%+ zCc`}qS3zM}LflADW$t#;<8UmGb%zX5reSECTy0qxGCmhJg1V&#l+)39P$E1SMNCci zhd4L&0L#4)pM-5joh)W>&hnB)Hm5*FcmpY^!~=41k7=Ug{2Rh-{r+%8=O0mJb?k|` z3Kd+%Fkx*cODe-%?I2of-dd%0+#u)*FuWI1%=w`Yh&tOCQ3QU0d3*|m&k7}`5p1G% z1gA(o=;$+9^K9 zH4kf#MIrk*jxt=^Vv=hP9~sYVAmI)Yar@kvhta3MlX3off9$Np4KL!Vg?uF$x;~Ao zmuGBvlV9^GF))oe&(qe;JJVmuy4x3O!~z3$rm|2a&%&Yza&ELAYx@!bW@%_=TN39B z7DnXW*8^Th#Ru7hnRUenNYhxt_?_tJcd79aKy-2~FF*?j^z(!sRpftc zVET2Qq`M{gEfn4S#CiAz=iZqp&MgxFm#(XDnoF02vP;tv?FZ*WFE((|EPKrDAS5-d zcpU2QhF|_zs7b@)hm^b~xu)$$&6&3Kh z8cl7ceOu0u=NVm~`VckY_>sIxvsx_^pE6GZ#*2VU55))6>895a-|hfG!2bUL2(QM_ literal 0 HcmV?d00001 diff --git a/lib/centostrano.rb b/lib/centostrano.rb new file mode 100644 index 0000000..6a80da9 --- /dev/null +++ b/lib/centostrano.rb @@ -0,0 +1,8 @@ +unless Capistrano::Configuration.respond_to?(:instance) + abort "deprec2 requires Capistrano 2" +end + +require "#{File.dirname(__FILE__)}/deprec/capistrano_extensions" +require "#{File.dirname(__FILE__)}/vmbuilder_plugins/all" +require "#{File.dirname(__FILE__)}/deprec/recipes" + diff --git a/lib/deprec/capistrano_extensions.rb b/lib/deprec/capistrano_extensions.rb new file mode 100644 index 0000000..a7946e5 --- /dev/null +++ b/lib/deprec/capistrano_extensions.rb @@ -0,0 +1,378 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +require 'capistrano' +require 'fileutils' + +module Deprec2 + DEPREC_TEMPLATES_BASE = File.join(File.dirname(__FILE__), 'templates') + + # Render template (usually a config file) + # + # Usually we render it to a file on the local filesystem. + # This way, we keep a copy of the config file under source control. + # We can make manual changes if required and push to new hosts. + # + # If the options hash contains :path then it's written to that path. + # If it contains :remote => true, the file will instead be written to remote targets + # If options[:path] and options[:remote] are missing, it just returns the rendered + # template as a string (good for debugging). + # + # XXX I would like to get rid of :render_template_to_file + # XXX Perhaps pass an option to this function to write to remote + # + def render_template(app, options={}) + template = options[:template] + path = options[:path] || nil + remote = options[:remote] || false + mode = options[:mode] || 0755 + owner = options[:owner] || nil + + # replace this with a check for the file + if ! template + puts "render_template() requires a value for the template!" + return false + end + + # If local copies of deprec templates exist they will be used + # If you don't specify the location with the local_template_dir option + # it defaults to config/templates. + # e.g. config/templates/nginx/nginx.conf.erb + local_template = File.join(local_template_dir, app.to_s, template) + if File.exists?(local_template) + puts + puts "Using local template (#{local_template})" + template = ERB.new(IO.read(local_template), nil, '-') + else + template = ERB.new(IO.read(File.join(DEPREC_TEMPLATES_BASE, app.to_s, template)), nil, '-') + end + rendered_template = template.result(binding) + + if remote + # render to remote machine + puts 'You need to specify a path to render the template to!' unless path + exit unless path + sudo "test -d #{File.dirname(path)} || sudo mkdir -p #{File.dirname(path)}" + std.su_put rendered_template, path, '/tmp/', :mode => mode + sudo "chown #{owner} #{path}" if defined?(owner) + elsif path + # render to local file + full_path = File.join('config', app.to_s, path) + path_dir = File.dirname(full_path) + if File.exists?(full_path) + if IO.read(full_path) == rendered_template + puts "[skip] File exists and is identical (#{full_path})." + return false + elsif overwrite?(full_path, rendered_template) + File.delete(full_path) + else + puts "[skip] Not overwriting #{full_path}" + return false + end + end + FileUtils.mkdir_p "#{path_dir}" if ! File.directory?(path_dir) + # added line above to make windows compatible + # system "mkdir -p #{path_dir}" if ! File.directory?(path_dir) + File.open(full_path, 'w'){|f| f.write rendered_template } + puts "[done] #{full_path} written" + else + # render to string + return rendered_template + end + end + + def overwrite?(full_path, rendered_template) + if defined?(overwrite_all) + if overwrite_all == true + return true + else + return false + end + end + + # XXX add :always and :never later - not sure how to set persistent value from here + # response = Capistrano::CLI.ui.ask "File exists. Overwrite? ([y]es, [n]o, [a]lways, n[e]ver)" do |q| + puts + response = Capistrano::CLI.ui.ask "File exists (#{full_path}). + Overwrite? ([y]es, [n]o, [d]iff)" do |q| + q.default = 'n' + end + + case response + when 'y' + return true + when 'n' + return false + when 'd' + require 'tempfile' + tf = Tempfile.new("deprec_diff") + tf.puts(rendered_template) + tf.close + puts + puts "Running diff -u current_file new_file_if_you_overwrite" + puts + system "diff -u #{full_path} #{tf.path} | less" + puts + overwrite?(full_path, rendered_template) + # XXX add :always and :never later - not sure how to set persistent value from here + # when 'a' + # set :overwrite_all, true + # when 'e' + # set :overwrite_all, false + end + + end + + def render_template_to_file(template_name, destination_file_name, templates_dir = DEPREC_TEMPLATES_BASE) + template_name += '.conf' if File.extname(template_name) == '' # XXX this to be removed + + file = File.join(templates_dir, template_name) + buffer = render :template => File.read(file) + + temporary_location = "/tmp/#{template_name}" + put buffer, temporary_location + sudo "cp #{temporary_location} #{destination_file_name}" + delete temporary_location + end + + # Copy configs to server(s). Note there is no :pull task. No changes should + # be made to configs on the servers so why would you need to pull them back? + def push_configs(app, files) + app = app.to_s + files.each do |file| + # If the file path is relative we will prepend a path to this projects + # own config directory for this service. + if file[:path][0,1] != '/' + full_remote_path = File.join(deploy_to, app, file[:path]) + else + full_remote_path = file[:path] + end + full_local_path = File.join('config', app, file[:path]) + sudo "test -d #{File.dirname(full_remote_path)} || sudo mkdir -p #{File.dirname(full_remote_path)}" + # + # XXX work this in to check for per-host variants of config files + # + # if any variants of this file exist for this host (they have -hostname at end) + # servers = find_servers_for_task(current_task) + # servers.each do |server| + # puts server(..., :hosts => server) # XXX find a way to restrict su_put to one host + # end + # else + # # just send them the normal way, it's quicker in parallel + std.su_put File.read(full_local_path), full_remote_path, '/tmp/', :mode=>file[:mode] + # end + # + sudo "chown #{file[:owner]} #{full_remote_path}" + end + end + + def teardown_connections + sessions.keys.each do |server| + sessions[server].close + sessions.delete(server) + end + end + + + def append_to_file_if_missing(filename, value, options={}) + # XXX sort out single quotes in 'value' - they'l break command! + # XXX if options[:requires_sudo] and :use_sudo then use sudo + sudo <<-END + sh -c ' + grep -F "#{value}" #{filename} > /dev/null 2>&1 || + test ! -f #{filename} || + echo "#{value}" >> #{filename} + ' + END + end + + # create new user account on target system + def useradd(user, options={}) + options[:shell] ||= '/bin/bash' # new accounts on ubuntu 6.06.1 have been getting /bin/sh + switches = '' + switches += " -s #{options[:shell]} " if options[:shell] + switches += ' -M ' if options[:homedir] == false + switches += " -g #{options[:group]} " unless options[:group].nil? + invoke_command "grep '^#{user}:' /etc/passwd || sudo /usr/sbin/useradd #{switches} #{user}", + :via => run_method + end + + # create a new group on target system + def groupadd(group, options={}) + via = options.delete(:via) || run_method + # XXX I don't like specifying the path to groupadd - need to sort out paths before long + invoke_command "grep '#{group}:' /etc/group || sudo /usr/sbin/groupadd #{group}", :via => via + end + + # add group to the list of groups this user belongs to + def add_user_to_group(user, group) + invoke_command "groups #{user} | grep ' #{group} ' || sudo /usr/sbin/usermod -G #{group} -a #{user}", + :via => run_method + end + + # create directory if it doesn't already exist + # set permissions and ownership + # XXX move mode, path and + def mkdir(path, options={}) + via = options.delete(:via) || :run + # XXX need to make sudo commands wrap the whole command (sh -c ?) + # XXX removed the extra 'sudo' from after the '||' - need something else + invoke_command "sh -c 'test -d #{path} || mkdir -p #{path}'", :via => via + invoke_command "chmod #{sprintf("%3o",options[:mode]||0755)} #{path}", :via => via if options[:mode] + invoke_command "chown -R #{options[:owner]} #{path}", :via => via if options[:owner] + groupadd(options[:group], :via => via) if options[:group] + invoke_command "chgrp -R #{options[:group]} #{path}", :via => via if options[:group] + end + + def create_src_dir + mkdir(src_dir, :mode => 0775, :group => group_src, :via => :sudo) + end + + # download source package if we don't already have it + def download_src(src_package, src_dir) + create_src_dir + # check if file exists and if we have an MD5 hash or bytecount to compare + # against if so, compare and decide if we need to download again + if defined?(src_package[:md5sum]) + md5_clause = " && echo '#{src_package[:md5sum]}' | md5sum -c - " + end + apt.install( {:base => %w(wget)}, :stable ) + # XXX replace with invoke_command + sudo <<-SUDO + sh -c "cd #{src_dir} && test -f #{src_package[:filename]} #{md5_clause} || wget --quiet --timestamping #{src_package[:url]}" + SUDO + end + + # unpack src and make it writable by the group + def unpack_src(src_package, src_dir) + package_dir = File.join(src_dir, src_package[:dir]) + # XXX replace with invoke_command + sudo <<-SUDO + sh -c ' + cd #{src_dir}; + test -d #{package_dir}.old && rm -fr #{package_dir}.old; + test -d #{package_dir} && mv #{package_dir} #{package_dir}.old; + #{src_package[:unpack]} + chgrp -R #{group} #{package_dir}; + chmod -R g+w #{package_dir}; + ' + SUDO + end + + # install package from source + def install_from_src(src_package, src_dir) + package_dir = File.join(src_dir, src_package[:dir]) + unpack_src(src_package, src_dir) + apt.install( {:base => %w(gcc gcc-c++ make)}, :stable ) + # XXX replace with invoke_command + sudo <<-SUDO + sh -c ' + cd #{package_dir}; + #{src_package[:configure]} + #{src_package[:make]} + #{src_package[:install]} + #{src_package[:post_install]} + ' + SUDO + end + + + ## + # Run a command and ask for input when input_query is seen. + # Sends the response back to the server. + # + # +input_query+ is a regular expression that defaults to /^Password/. + # + # Can be used where +run+ would otherwise be used. + # + # run_with_input 'ssh-keygen ...', /^Are you sure you want to overwrite\?/ + + def run_with_input(shell_command, input_query=/^Password/, response=nil) + handle_command_with_input(:run, shell_command, input_query, response) + end + + ## + # Run a command using sudo and ask for input when a regular expression is seen. + # Sends the response back to the server. + # + # See also +run_with_input+ + # + # +input_query+ is a regular expression + + def sudo_with_input(shell_command, input_query=/^Password/, response=nil) + handle_command_with_input(:sudo, shell_command, input_query, response) + end + + def invoke_with_input(shell_command, input_query=/^Password/, response=nil) + handle_command_with_input(run_method, shell_command, input_query, response) + end + + ## + # Run a command using sudo and continuously pipe the results back to the console. + # + # Similar to the built-in +stream+, but for privileged users. + + def sudo_stream(command) + sudo(command) do |ch, stream, out| + puts out if stream == :out + if stream == :err + puts "[err : #{ch[:host]}] #{out}" + break + end + end + end + + # We don't need this. Put 'USER=root' on the command line instead. + # + # XXX Not working in deprec2 + # ## + # # Run a command using the root account. + # # + # # Some linux distros/VPS providers only give you a root login when you install. + # + # def run_as_root(shell_command) + # std.connect_as_root do |tempuser| + # run shell_command + # end + # end + # + # ## + # # Run a task using root account. + # # + # # Some linux distros/VPS providers only give you a root login when you install. + # # + # # tempuser: contains the value replaced by 'root' for the duration of this call + # + # def as_root() + # std.connect_as_root do |tempuser| + # yield tempuser + # end + # end + + + + private + + ## + # Does the actual capturing of the input and streaming of the output. + # + # local_run_method: run or sudo + # shell_command: The command to run + # input_query: A regular expression matching a request for input: /^Please enter your password/ + + def handle_command_with_input(local_run_method, shell_command, input_query, response=nil) + send(local_run_method, shell_command) do |channel, stream, data| + logger.info data, channel[:host] + if data =~ input_query + if response + channel.send_data "#{response}\n" + else + response = ::Capistrano::CLI.password_prompt "#{data}" + channel.send_data "#{response}\n" + end + end + end + end + + +end + +Capistrano.plugin :deprec2, Deprec2 diff --git a/lib/deprec/recipes.rb b/lib/deprec/recipes.rb new file mode 100644 index 0000000..1edd79a --- /dev/null +++ b/lib/deprec/recipes.rb @@ -0,0 +1,28 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +unless Capistrano::Configuration.respond_to?(:instance) + abort "deprec2 requires Capistrano 2" +end +require "#{File.dirname(__FILE__)}/recipes/deprec" +require "#{File.dirname(__FILE__)}/recipes/deprecated" +# require "#{File.dirname(__FILE__)}/recipes/canonical" +require "#{File.dirname(__FILE__)}/recipes/users" +require "#{File.dirname(__FILE__)}/recipes/ssh" +require "#{File.dirname(__FILE__)}/recipes/nginx" +require "#{File.dirname(__FILE__)}/recipes/apache" +require "#{File.dirname(__FILE__)}/recipes/php" +require "#{File.dirname(__FILE__)}/recipes/subversion" +require "#{File.dirname(__FILE__)}/recipes/trac" +require "#{File.dirname(__FILE__)}/recipes/ruby" +require "#{File.dirname(__FILE__)}/recipes/rails" +require "#{File.dirname(__FILE__)}/recipes/mongrel" +require "#{File.dirname(__FILE__)}/recipes/mysql" +require "#{File.dirname(__FILE__)}/recipes/postfix" +require "#{File.dirname(__FILE__)}/recipes/memcache" +require "#{File.dirname(__FILE__)}/recipes/monit" +require "#{File.dirname(__FILE__)}/recipes/network" +require "#{File.dirname(__FILE__)}/recipes/aoe" +require "#{File.dirname(__FILE__)}/recipes/ntp" +require "#{File.dirname(__FILE__)}/recipes/nagios" +require "#{File.dirname(__FILE__)}/recipes/heartbeat" +require "#{File.dirname(__FILE__)}/recipes/xen" +require "#{File.dirname(__FILE__)}/recipes/git" diff --git a/lib/deprec/recipes/aoe.rb b/lib/deprec/recipes/aoe.rb new file mode 100644 index 0000000..047f5ff --- /dev/null +++ b/lib/deprec/recipes/aoe.rb @@ -0,0 +1,117 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + + namespace :deprec do + + SRC_PACKAGES[:aoe] = { + :filename => 'aoe6-56.tar.gz', + :md5sum => "93689aaad32f647a788c15c82bd0158e aoe6-56.tar.gz", + :dir => 'aoe6-56', + :url => "http://www.coraid.com/support/linux/aoe6-56.tar.gz", + :unpack => "tar zxf aoe6-56.tar.gz;", + :make => 'make;', + :install => 'make install;' + } + + namespace :aoe do + + desc "Install aoe drivers required to mount Coraid block devices" + task :install do + install_deps + deprec2.download_src(SRC_PACKAGES[:aoe], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:aoe], src_dir) + end + + task :install_deps do + apt.install( {:base => %w(build-essential linux-headers-$(uname -r) vblade aoetools)}, :stable ) + end + + SYSTEM_CONFIG_FILES[:aoe] = [ + + {:template => "aoetools.erb", + :path => '/etc/default/aoetools', + :mode => 0644, + :owner => 'root:root'} + + ] + + desc "Generate configuration file(s) for XXX from template(s)" + task :config_gen do + SYSTEM_CONFIG_FILES[:aoe].each do |file| + deprec2.render_template(:aoe, file) + end + end + + desc 'Deploy configuration files(s) for XXX' + task :config do + deprec2.push_configs(:aoe, SYSTEM_CONFIG_FILES[:aoe]) + end + + end + + + SRC_PACKAGES[:cec] = { + :filename => 'cec-8.tgz', + :md5sum => "7899dc549f9a368e532f9c39ed819f71 cec-8.tgz", + :dir => 'cec-8', + :url => "http://easynews.dl.sourceforge.net/sourceforge/aoetools/cec-8.tgz", + :unpack => "tar zxf cec-8.tgz;", + :make => 'make;', + :install => 'make install;' + } + + namespace :cec do + + desc "install CEC (Coraid Ethernet Console)" + task :install do + deprec2.download_src(SRC_PACKAGES[:cec], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:cec], src_dir) + end + + end + + SRC_PACKAGES[:ddt] = { + :filename => 'ddt-6.tgz', + :md5sum => "5e1e8a58a8621b93440be605113f7bc0 ddt-6.tgz", + :dir => 'ddt-6', + :url => "http://www.coraid.com/support/sr/ddt-6.tgz", + :unpack => "tar zxf ddt-6.tgz;", + :make => 'make;', + :install => 'make install;' + } + + namespace :ddt do + + desc "install DDT (tool for testing performance)" + task :install do + deprec2.download_src(SRC_PACKAGES[:ddt], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:ddt], src_dir) + end + + end + + SRC_PACKAGES[:aoemask] = { + :filename => 'aoemask-1.tgz', + :md5sum => "379461a28d511e269f4593b846bd1288 aoemask-1.tgz", + :dir => 'aoemask-1', + :url => "http://www.coraid.com/support/sr/aoemask-1.tgz", + :unpack => "tar zxf aoemask-1.tgz;", + :make => 'make;', + :install => 'make install;' + } + + namespace :aoemask do + + desc "install aoemask" + task :install do + deprec2.download_src(SRC_PACKAGES[:aoemask], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:aoemask], src_dir) + end + + end + + end + +end + + diff --git a/lib/deprec/recipes/apache.rb b/lib/deprec/recipes/apache.rb new file mode 100644 index 0000000..e67ffa3 --- /dev/null +++ b/lib/deprec/recipes/apache.rb @@ -0,0 +1,180 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :centos do + namespace :apache do + + # put apache config for site in shared/config/apache2 dir + # link it into apps to enable, unlink to disable? + # http://times.usefulinc.com/2006/09/15-rails-debian-apache + + # XXX Check this over after a nice sleep + # + # def set_apache_conf + # if apache_default_vhost + # set :apache_conf, "/usr/local/apache2/conf/default.conf" unless apache_default_vhost_conf + # else + # set :apache_conf, "/usr/local/apache2/conf/apps/#{application}.conf" unless apache_conf + # end + # end + + set(:apache_server_name) { domain } + set :apache_user, 'daemon' # XXX this is not yet being inserted into httpd.conf! + # I've added it for deprec:nagios:install + set :apache_conf, nil + set :apache_default_vhost, false + set :apache_default_vhost_conf, nil + set :apache_ctl, "/usr/local/apache2/bin/apachectl" + set(:apache_server_aliases) { web_server_aliases } + set :apache_proxy_port, 8000 + set :apache_proxy_servers, 2 + set :apache_proxy_address, "127.0.0.1" + set :apache_ssl_enabled, false + set :apache_ssl_ip, nil + set :apache_ssl_forward_all, false + set :apache_ssl_chainfile, false + set :apache_docroot, '/usr/local/apache2/htdocs' + set :apache_vhost_dir, '/usr/local/apache2/conf/apps' + set :apache_config_file, '/usr/local/apache2/conf/httpd.conf' + + SRC_PACKAGES[:apache] = { + :filename => 'httpd-2.2.6.tar.gz', + :md5sum => "d050a49bd7532ec21c6bb593b3473a5d httpd-2.2.6.tar.gz", + :dir => 'httpd-2.2.6', + :url => "http://www.apache.org/dist/httpd/httpd-2.2.6.tar.gz", + :unpack => "tar zxf httpd-2.2.6.tar.gz;", + :configure => %w( + ./configure + --enable-mods-shared=all + --enable-proxy + --enable-proxy-balancer + --enable-proxy-http + --enable-rewrite + --enable-cache + --enable-headers + --enable-ssl + --enable-deflate + --with-included-apr #_so_this_recipe_doesn't_break_when_rerun + --enable-dav #_for_subversion_ + --enable-so #_for_subversion_ + ; + ).reject{|arg| arg.match '#'}.join(' '), + :make => 'make;', + :install => 'make install;', + :post_install => 'install -b support/apachectl /etc/init.d/httpd;' + } + + desc "Install apache" + task :install do + install_deps + deprec2.download_src(SRC_PACKAGES[:apache], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:apache], src_dir) + setup_vhost_dir + install_index_page + end + + # install dependencies for apache + task :install_deps do + apt.install( {:base => %w(zlib1g-dev zlib1g openssl openssl-devel)}, :stable ) + end + + # Create dir for vhost config files + task :setup_vhost_dir do + deprec2.mkdir(apache_vhost_dir, :owner => 'root', :group => group, :mode => 0775, :via => :sudo) + deprec2.append_to_file_if_missing(apache_config_file, 'Include conf/apps/') + end + + SYSTEM_CONFIG_FILES[:apache] = [ + # They're generated and put in place during install + # I may put them in here at some point + ] + + PROJECT_CONFIG_FILES[:apache] = [ + + {:template => "httpd-vhost-app.conf.erb", + :path => 'conf/httpd-vhost-app.conf', + :mode => 0755, + :owner => 'root:root'} + ] + + desc "Generate configuration file(s) for apache from template(s)" + task :config_gen do + config_gen_system + config_gen_project + end + + task :config_gen_system do + SYSTEM_CONFIG_FILES[:apache].each do |file| + deprec2.render_template(:apache, file) + end + end + + task :config_gen_project do + PROJECT_CONFIG_FILES[:apache].each do |file| + deprec2.render_template(:apache, file) + end + end + + desc "Push apache config files to server" + task :config, :roles => :web do + config_system + config_project + end + + task :config_system, :roles => :web do + deprec2.push_configs(:apache, SYSTEM_CONFIG_FILES[:apache]) + end + + task :config_project, :roles => :web do + deprec2.push_configs(:apache, PROJECT_CONFIG_FILES[:apache]) + sudo "ln -sf #{deploy_to}/apache/conf/httpd-vhost-app.conf /usr/local/apache2/conf/apps/#{application}.conf" + end + + desc "Start Apache" + task :start, :roles => :web do + send(run_method, "#{apache_ctl} start") + end + + desc "Stop Apache" + task :stop, :roles => :web do + send(run_method, "#{apache_ctl} stop") + end + + desc "Restart Apache" + task :restart, :roles => :web do + send(run_method, "#{apache_ctl} restart") + end + + desc "Reload Apache" + task :reload, :roles => :web do + send(run_method, "#{apache_ctl} reload") + end + + desc "Set apache to start on boot" + task :activate, :roles => :web do + send(run_method, "/sbin/chkconfig --add httpd") + send(run_method, "/sbin/chkconfig --level 345 httpd on") + end + + desc "Set apache to not start on boot" + task :deactivate, :roles => :web do + send(run_method, "/sbin/chkconfig --del httpd") + end + + task :backup, :roles => :web do + # not yet implemented + end + + task :restore, :roles => :web do + # not yet implemented + end + + # Generate an index.html page + task :install_index_page, :roles => :web do + deprec2.mkdir(apache_docroot, :owner => :root, :group => :deploy, :mode => 0775, :via => :sudo) + std.su_put deprec2.render_template(:apache, :template => 'index.html.erb'), File.join(apache_docroot, 'index.html') + std.su_put deprec2.render_template(:apache, :template => 'master.css'), File.join(apache_docroot, 'master.css') + end + + end + end +end diff --git a/lib/deprec/recipes/canonical.rb b/lib/deprec/recipes/canonical.rb new file mode 100644 index 0000000..997b35f --- /dev/null +++ b/lib/deprec/recipes/canonical.rb @@ -0,0 +1,57 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +# canonical.rb +# +# Running deprec:web:stop will be the same as running deprec:apache:stop or +# deprec:nginx:stop depending what you have chosen. +# +# generic namespaces are linked up to chosen applications at runtime but these +# stubs are so they'll be included in the output of "cap -T" +# +Capistrano::Configuration.instance(:must_exist).load do + + %w(web app db).each do |server| + namespace "deprec:#{server}" do + + desc "Install #{server} server" + task :install, :roles => server do + end + + desc "Generate config file(s) for #{server} server from template(s)" + task :config_gen do + end + + desc "Deploy configuration files(s) for #{server} server" + task :config, :roles => server do + end + + desc "Start #{server} server" + task :start, :roles => server do + end + + desc "Stop #{server} server" + task :stop, :roles => server do + end + + desc "Stop #{server} server" + task :restart, :roles => server do + end + + desc "Enable startup script for #{server} server" + task :activate, :roles => server do + end + + desc "Disable startup script for #{server} server" + task :deactivate, :roles => server do + end + + desc "Backup data for #{server} server" + task :backup, :roles => server do + end + + desc "Restore data for #{server} server from backup" + task :restore, :roles => server do + end + + end + end +end \ No newline at end of file diff --git a/lib/deprec/recipes/deprec.rb b/lib/deprec/recipes/deprec.rb new file mode 100644 index 0000000..667c2af --- /dev/null +++ b/lib/deprec/recipes/deprec.rb @@ -0,0 +1,155 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + + # Set the value if not already set + # This method is accessible to all recipe files + def self.default(name, *args, &block) + unless exists?(name) + set(name, *args, &block) + end + end + + # Deprec checks here for local versions of config templates before it's own + set :local_template_dir, File.join('config','templates') + + # The following two Constants contain details of the configuration + # files used by each service. They're used when generating config + # files from templates and when configs files are pushed out to servers. + # + # They are populated by the recipe file for each service + # + SYSTEM_CONFIG_FILES = {} # e.g. httpd.conf + PROJECT_CONFIG_FILES = {} # e.g. projectname-httpd-vhost.conf + + # For each service, the details of the file to download and options + # to configure, build and install the service + SRC_PACKAGES = {} + + # Server options + CHOICES_WEBSERVER = [:nginx, :apache, :none] + CHOICES_APPSERVER = [:mongrel, :webrick, :none] + CHOICES_DATABASE = [:mysql, :postgres, :none] + + + # Server defaults + default :web_server_type, :apache + default :app_server_type, :mongrel + default :db_server_type, :mysql + + default(:web_server_type) do + Capistrano::CLI.ui.choose do |menu| + CHOICES_WEBSERVER.each {|c| menu.choice(c)} + menu.header = "select webserver type" + end + end + + default(:app_server_type) do + Capistrano::CLI.ui.choose do |menu| + CHOICES_APPSERVER.each {|c| menu.choice(c)} + menu.header = "select application server type" + end + end + + default(:db_server_type) do + Capistrano::CLI.ui.choose do |menu| + CHOICES_DATABASE.each {|c| menu.choice(c)} + menu.header = "select database server type" + end + end + + default(:application) do + Capistrano::CLI.ui.ask "enter name of project(no spaces)" do |q| + q.validate = /^[0-9a-z_]*$/ + end + end + + default(:domain) do + Capistrano::CLI.ui.ask "enter domain name for project" do |q| + q.validate = /^[0-9a-z_\.]*$/ + end + end + + default(:repository) do + Capistrano::CLI.ui.ask "enter repository URL for project" do |q| + # q.validate = // + end + end + + # some tasks run commands requiring special user privileges on remote servers + # these tasks will run the commands with: + # :invoke_command "command", :via => run_method + # override this value if sudo is not an option + # in that case, your use will need the correct privileges + default :run_method, 'sudo' + + default(:backup_dir) { Capistrano::CLI.ui.ask 'directory to store backups'} + + # XXX rails deploy stuff + default(:deploy_to) { File.join( %w(/ var www apps) << application ) } + default(:current_path) { File.join(deploy_to, "current") } + default(:shared_path) { File.join(deploy_to, "shared") } + + # XXX more rails deploy stuff? + + default :user, ENV['USER'] # user who is deploying + default :group, 'deploy' # deployment group + default(:group_src) { group } # group ownership for src dir + default :src_dir, '/usr/local/src' # 3rd party src on servers lives here + default(:web_server_aliases) { domain.match(/^www/) ? [] : ["www.#{domain}"] } + + # XXX for some reason this is causing "before deprec:rails:install" to be executed twice + # on :load, 'deprec:connect_canonical_tasks' + + namespace :centos do + + task :connect_canonical_tasks, :hosts => 'localhost' do + # link application specific recipes into canonical task names + # e.g. deprec:web:restart => deprec:nginx:restart + metaclass = class << self; self; end + [:web, :app, :db].each do |server| + server_type = send("#{server}_server_type") + if server_type != :none + metaclass.send(:define_method, server) { namespaces[server] } + self.namespaces[server] = deprec.send(server_type) + end + end + end + + task :dump do + require 'yaml' + y variables + end + + task :setup_src_dir do + deprec2.groupadd(group_src) + deprec2.add_user_to_group(user, group_src) + deprec2.create_src_dir + end + + # Download all packages used by deprec to your local host. + # You can then push them to /usr/local/src on target hosts + # to save time and bandwidth rather than repeatedly downloading + # from the distribution sites. + task :update_src do + SRC_PACKAGES.each{|key, src_package| + current_dir = Dir.pwd + system "cd src/ && test -f #{src_package[:filename]} || wget --quiet --timestamping #{src_package[:url]}" + system "cd #{current_dir}" + } + end + + # todo + # + # Copy files from src/ to /usr/local/src/ on remote hosts + task :push_src do + SRC_PACKAGES.each do |key, src_package| + file = File.join('src', src_package[:filename]) + if File.exists?(file) + std.su_put(File.read(file), "#{src_dir}/#{src_package[:filename]}", '/tmp/') + end + end + end + + end + +end diff --git a/lib/deprec/recipes/deprecated.rb b/lib/deprec/recipes/deprecated.rb new file mode 100644 index 0000000..8d76437 --- /dev/null +++ b/lib/deprec/recipes/deprecated.rb @@ -0,0 +1,71 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + + # deprecated tasks from deprec1 + # we're now using namespaces and some different naming conventions + + # XXX use deprecated function to generate these dynamically + + deprec2_isnt_backwards_compatible = <<-EOF + +You've installed deprec2 but seem to be using a deprec1 command. + +You have two options: + +- install deprec-1.9.x and continue using deprec1 + + Instructions are available at http://www.deprec.org/ + +- use deprec2 + +EOF + + cap2_warning = <<-EOF + +You're using Capistrano 2 but using a deprecated cap1 command. + +EOF + + task :setup_admin_account do + puts deprec2_isnt_backwards_compatible + puts " Replace 'cap setup_admin_account' with 'cap deprec:users:add'" + puts + end + + task :change_root_password do + puts deprec2_isnt_backwards_compatible + puts " Replace 'cap change_root_password' with 'cap deprec:users:passwd'" + puts + end + + task :setup_ssh_keys do + puts deprec2_isnt_backwards_compatible + puts " Replace 'cap setup_ssh_keys' with 'cap deprec:ssh:setup_keys'" + puts + end + + task :install_rails_stack do + puts deprec2_isnt_backwards_compatible + puts " Replace 'cap install_rails_stack' with 'cap deprec:rails:install_rails_stack'" + puts + end + + task :setup do + puts deprec2_isnt_backwards_compatible + puts " Replace 'cap setup' with 'cap deploy:setup'" + puts + end + + task :restart_apache do + puts deprec2_isnt_backwards_compatible + puts " Replace 'cap restart_apache' with 'cap deprec:apache:restart'" + puts + end + + task :show_tasks do + puts deprec2_isnt_backwards_compatible + puts " Replace 'cap show-tasks' with 'cap -T'" + puts + end + +end \ No newline at end of file diff --git a/lib/deprec/recipes/example.rb b/lib/deprec/recipes/example.rb new file mode 100644 index 0000000..58ee485 --- /dev/null +++ b/lib/deprec/recipes/example.rb @@ -0,0 +1,115 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :deprec do + namespace :example do + + SRC_PACKAGES[:example] = { + :filename => 'example-1.2.3.tar.gz', + :md5sum => "d050a49bd72222ec21c6bb593b3473a5d example-1.2.3.tar.gz", + :dir => 'example-1.2.3', + :url => "http://www.example.org/dist/example/example-1.2.3.tar.gz", + :unpack => "tar zxf example-1.2.3.tar.gz;", + :configure => %w( + ./configure + --enable-mods-shared=all + --enable-proxy + ; + ).reject{|arg| arg.match '#'}.join(' '), + :make => 'make;', + :install => 'make install;', + :post_install => 'install -b support/apachectl /etc/init.d/httpd;' + } + + desc "Install example" + task :install, :roles => :web do + install_deps + deprec2.download_src(SRC_PACKAGES[:example], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:example], src_dir) + end + + task :install_deps do + apt.install( {:base => %w(build-essential zlib1g-dev)}, :stable ) + end + + SYSTEM_CONFIG_FILES[:example] = [ + + {:template => "example.conf.erb", + :path => '/etc/example/example.conf', + :mode => 0755, + :owner => 'root:root'} + + ] + + PROJECT_CONFIG_FILES[:example] = [ + + {:template => "example.conf.erb", + :path => 'conf/example.conf', + :mode => 0755, + :owner => 'root:root'} + ] + + + desc "Generate configuration file(s) for XXX from template(s)" + task :config_gen do + config_gen_system + config_gen_project + end + + task :config_gen_system do + SYSTEM_CONFIG_FILES[:example].each do |file| + deprec2.render_template(:example, file) + end + end + + task :config_gen_project do + PROJECT_CONFIG_FILES[:example].each do |file| + deprec2.render_template(:example, file) + end + end + + desc 'Deploy configuration files(s) for XXX' + task :config, :roles => :web do + config_system + config_project + end + + task :config_system, :roles => :web do + deprec2.push_configs(:example, SYSTEM_CONFIG_FILES[:example]) + end + + task :config_project, :roles => :web do + deprec2.push_configs(:example, PROJECT_CONFIG_FILES[:example]) + end + + + task :start, :roles => :web do + send(run_method, "/etc/init.d/example reload") + end + + task :stop, :roles => :web do + send(run_method, "/etc/init.d/example reload") + end + + task :restart, :roles => :web do + send(run_method, "/etc/init.d/example restart") + end + + task :reload, :roles => :web do + send(run_method, "/etc/init.d/example reload") + end + + task :activate, :roles => :web do + end + + task :deactivate, :roles => :web do + end + + task :backup, :roles => :web do + end + + task :restore, :roles => :web do + end + + end + end +end \ No newline at end of file diff --git a/lib/deprec/recipes/git.rb b/lib/deprec/recipes/git.rb new file mode 100644 index 0000000..d7f9d83 --- /dev/null +++ b/lib/deprec/recipes/git.rb @@ -0,0 +1,151 @@ +# Copyright 2006-2008 by Saulius Grigaitis. All rights reserved. +require 'fileutils' +require 'uri' +require 'optparse' + + +Capistrano::Configuration.instance(:must_exist).load do + namespace :centos do namespace :git do + + set :scm_group, 'scm' + # Extract git attributes from :repository URL + # + # Two examples of :repository entries are: + # + # set :repository, 'ssh://www.rubyonrails.lt/var/git/centostrano.git' + # + # This has only been tested with ssh (haven't tested with git or http) + # + set (:git_scheme) { URI.parse(repository).scheme } + set (:git_host) { URI.parse(repository).host } + set (:git_path) { URI.parse(repository).path } + + # account name to perform actions on (such as granting access to an account) + # this is a hack to allow us to optionally pass a variable to tasks + set (:git_account) do + Capistrano::CLI.ui.ask 'account name' + end + + set(:git_backup_dir) { File.join(backup_dir, 'git') } + + + desc "Install Git" + task :install, :roles => :scm do + install_deps + end + + desc "install dependencies for Subversion" + task :install_deps do + enable_atrpms_dag_repositories + apt.install( {:base => %w(git)}, :stable , {:repositories => [:atrpms, :dag]}) + end + + desc "enable atrmps and dag repositories" + task :enable_atrpms_dag_repositories do + repository_configs = [ + { + :template => 'repository.erb', + :path => '/etc/yum.repos.d/atrpms.repo', + :mode => 0644, + :owner => 'root:root', + :remote => true, + :repository => { + :code => "atrpms", + :name => "ATrpms for Enterprise Linux $releasever - $basearch", + :baseurl => "http://dl.atrpms.net/el$releasever-$basearch/atrpms/stable", + :enabled => "0", + :gpgcheck => "1", + :gpgkey => "http://ATrpms.net/RPM-GPG-KEY.atrpms" + } + }, + { + :template => 'repository.erb', + :path => '/etc/yum.repos.d/dag.repo', + :mode => 0644, + :owner => 'root:root', + :remote => true, + :repository => { + :code => "dag", + :name => "Dag", + :baseurl => "http://dag.freshrpms.net/redhat/el4/en/$basearch/dag\nhttp://ftp.heanet.ie/pub/freshrpms/pub/dag/redhat/el4/en/i386/dag/", + :enabled => "0", + :gpgcheck => "1", + :gpgkey => "http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt" + } + } + ] + repository_configs.each { |rc| deprec2.render_template(:centos, rc) } + end + + desc "grant a user access to svn repos" + task :grant_user_access, :roles => :scm do + # creates account, scm_group and adds account to group + deprec2.useradd(git_account) + deprec2.groupadd(scm_group) + deprec2.add_user_to_group(git_account, scm_group) + end + + desc "Create git repository and import project into it" + task :setup, :roles => :scm do + create_repos + create_local_repos + push + end + + desc "Create a git repository" + task :create_repos, :roles => :scm do + set :git_account, top.user + grant_user_access + deprec2.mkdir(repos_path, :mode => 02775, :group => scm_group, :via => :sudo) + sudo "sh -c 'cd #{repos_path} && git --bare init'" + sudo "chmod -R g+w #{repos_path}" + end + + desc "Create git repository in local project" + task :create_local_repos do + unless File.exists?(".git") + system("git init") + system("git add .") + system("git commit -a -m 'Initial import'") + end + end + + # Adapted from code in Bradley Taylors RailsMachine gem + desc "Import project into git repository." + task :push, :roles => :scm do + ignore_log_and_tmp + new_path = "../#{application}" + puts "Importing application." + system "git push #{repository} master" + puts "Your repository is: #{repository}" + end + + # Lifted from Bradley Taylors RailsMachine gem + desc "ignore log files and tmp" + task :ignore_log_and_tmp, :roles => :scm do + puts "removing log directory contents from git" + system "rm log/*" + puts "removing contents of tmp sub-directorys from git" + system "rm tmp/cache/*" + system "rm tmp/pids/*" + system "rm tmp/sessions/*" + system "rm tmp/sockets/*" + + ignore = <<-FILE + .DS_Store + log/*.log + tmp/**/* + db/*.sqlite3 + coverage + doc/app/* + doc/api/* + FILE + + File.open(".gitignore", "w") { |f| f.write(ignore.strip.gsub(/^#{ignore[/\A\s*/]}/, "")) } + system "find . -type d -empty | xargs -I {} touch {}/.gitignore" + system "git add ." + system "git commit -a -m 'Touched .gitignore to emtpy folders and ignored log files and tmp'" + end + + end end +end diff --git a/lib/deprec/recipes/heartbeat.rb b/lib/deprec/recipes/heartbeat.rb new file mode 100644 index 0000000..c2cb1ff --- /dev/null +++ b/lib/deprec/recipes/heartbeat.rb @@ -0,0 +1,138 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :deprec do + namespace :heartbeat do + set(:heartbeat_nodes) { find_servers_for_task(current_task) } + set(:heartbeat_preferred_node) { + Capistrano::CLI.ui.choose do |menu| + heartbeat_nodes.each {|c| menu.choice(c)} + menu.header = "select preferred node" + end + } + set(:heartbeat_resources) {Capistrano::CLI.ui.ask 'Enter resource to share. e.g. an ip address'} + set(:heartbeat_auth_key) { Capistrano::CLI.ui.ask 'Enter auth key for heartbeat to use' } + set(:heartbeat_ping) { Capistrano::CLI.ui.ask 'Enter IP address nodes will ping to test connectivity. e.g. gateway address' } + set(:heartbeat_bcast) { + Capistrano::CLI.ui.ask 'Enter ethernet interface(s) Heartbeat sends UDP broadcast traffic on. e.g. eth0' do |q| + q.default = 'eth0' + end + } + set(:heartbeat_auto_failback) { + Capistrano::CLI.ui.ask 'Should resource(s) automatically fail back to its "primary" node ' do |q| + q.default = 'yes' + end + } + + desc "Install Heartbeat" + task :install do + install_deps + end + + # Install dependencies for heartbeat + task :install_deps do + apt.install( {:base => %w(heartbeat-2)}, :stable ) + end + + SYSTEM_CONFIG_FILES[:heartbeat] = [ + + {:template => 'ha.cf.erb', + :path => '/etc/ha.d/ha.cf', + :mode => 0644, + :owner => 'root:root'}, + + {:template => 'haresources.erb', + :path => '/etc/ha.d/haresources', + :mode => 0644, + :owner => 'root:root'}, + + {:template => 'authkeys.erb', + :path => '/etc/ha.d/authkeys', + :mode => 0600, + :owner => 'root:root'} + + ] + + desc "Generate configuration file(s) for heartbeat from template(s)" + task :config_gen do + if ENV['ROLES'] + SYSTEM_CONFIG_FILES[:heartbeat].each do |file| + file.merge!({:path => "#{file[:path]}-#{ENV['ROLES']}"}) + deprec2.render_template(:heartbeat, file) + end + else + puts + puts "Whoops!" + puts + puts "You need to specify the cluster to work on by defining ROLES env variable." + puts "e.g. cap deprec:heartbeat:config ROLES=cluster_web" + puts + end + end + + desc "Push heartbeat config files to server" + task :config do + if ENV['ROLES'] + config_files = SYSTEM_CONFIG_FILES[:heartbeat].collect{|file| file.merge({:path => "#{file[:path]}-#{ENV['ROLES']}"})} + deprec2.push_configs(:heartbeat, config_files) + SYSTEM_CONFIG_FILES[:heartbeat].each {|file| + sudo "mv #{file[:path]}-#{ENV['ROLES']} #{file[:path]}" + } + # puts config_files + else + puts + puts "Whoops!" + puts + puts "You need to specify the cluster to work on by defining ROLES env variable." + puts "e.g. cap deprec:heartbeat:config ROLES=cluster_web" + puts + end + end + + desc "Set Heartbeat to start on boot" + task :activate, :roles => :heartbeat do + send(run_method, "update-rc.d heartbeat defaults") + end + + desc "Set Heartbeat to not start on boot" + task :deactivate, :roles => :heartbeat do + send(run_method, "update-rc.d -f heartbeat remove") + end + + + # Control + + # XXX perhaps define a cluster to work with + # XXX e.g. set :cluster, 'rolename' + # XXX and then target that rolename with these tasks + + desc "Start Heartbeat" + task :start, :roles => :heartbeat do + send(run_method, "/etc/init.d/heartbeat start") + end + + desc "Stop Heartbeat" + task :stop, :roles => :heartbeat do + send(run_method, "/etc/init.d/heartbeat stop") + end + + desc "Restart Heartbeat" + task :restart, :roles => :heartbeat do + send(run_method, "/etc/init.d/heartbeat restart") + end + + desc "Reload Heartbeat" + task :reload, :roles => :heartbeat do + send(run_method, "/etc/init.d/heartbeat reload") + end + + task :backup, :roles => :web do + # not yet implemented + end + + task :restore, :roles => :web do + # not yet implemented + end + + end + end +end \ No newline at end of file diff --git a/lib/deprec/recipes/memcache.rb b/lib/deprec/recipes/memcache.rb new file mode 100644 index 0000000..74cb8ba --- /dev/null +++ b/lib/deprec/recipes/memcache.rb @@ -0,0 +1,49 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :deprec do + namespace :memcache do + + set :memcache_ip, '127.0.0.1' + set :memcache_port, 11211 + set :memcache_memory, 256 + + # XXX needs thought/work + task :memcached_start do + run "memcached -d -m #{memcache_memory} -l #{memcache_ip} -p #{memcache_port}" + end + + # XXX needs thought/work + task :memcached_stop do + run "killall memcached" + end + + # XXX needs thought/work + task :memcached_restart do + memcached_stop + memcached_start + end + + task :install_memcached do + version = 'memcached-1.2.2' + set :src_package, { + :file => version + '.tar.gz', + :md5sum => 'a08851f7fa7b15e92ee6320b7a79c321 memcached-1.2.2.tar.gz', + :dir => version, + :url => "http://www.danga.com/memcached/dist/#{version}.tar.gz", + :unpack => "tar zxf #{version}.tar.gz;", + :configure => %w{ + ./configure + --prefix=/usr/local + ; + }.reject{|arg| arg.match '#'}.join(' '), + :make => 'make;', + :install => 'make install;', + :post_install => 'install -b scripts/memcached-init /etc/init.d/memcached;' + } + apt.install( {:base => %w(libevent-dev)}, :stable ) + deprec.download_src(src_package, src_dir) + deprec.install_from_src(src_package, src_dir) + end +end end + +end \ No newline at end of file diff --git a/lib/deprec/recipes/mongrel.rb b/lib/deprec/recipes/mongrel.rb new file mode 100644 index 0000000..4aa0813 --- /dev/null +++ b/lib/deprec/recipes/mongrel.rb @@ -0,0 +1,186 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + + namespace :centos do + namespace :mongrel do + + set :mongrel_servers, 2 + set :mongrel_port, 8000 + set :mongrel_address, "127.0.0.1" + set(:mongrel_environment) { rails_env } + set(:mongrel_log_dir) { "#{deploy_to}/shared/log" } + set(:mongrel_pid_dir) { "#{deploy_to}/shared/pids" } + set :mongrel_conf_dir, '/etc/mongrel_cluster' + set(:mongrel_conf) { "/etc/mongrel_cluster/#{application}.yml" } + set :mongrel_user_prefix, 'mongrel_' + set(:mongrel_user) { mongrel_user_prefix + application } + set :mongrel_group_prefix, 'app_' + set(:mongrel_group) { mongrel_group_prefix + application } + + + # Install + + desc "Install mongrel" + task :install, :roles => :app do + gem2.select 'mongrel' # mongrel requires we select a version + gem2.install 'mongrel_cluster' + gem2.install 'swiftiply' + end + + + # Configure + + SYSTEM_CONFIG_FILES[:mongrel] = [ + + {:template => 'mongrel_cluster-init-script', + :path => '/etc/init.d/mongrel_cluster', + :mode => 0755, + :owner => 'root:root'} + + ] + + PROJECT_CONFIG_FILES[:mongrel] = [ + + {:template => 'mongrel_cluster.yml.erb', + :path => 'cluster.yml', + :mode => 0644, + :owner => 'root:root'} + + ] + + desc "Generate configuration file(s) for mongrel from template(s)" + task :config_gen do + config_gen_system + config_gen_project + end + + task :config_gen_system do + SYSTEM_CONFIG_FILES[:mongrel].each do |file| + deprec2.render_template(:mongrel, file) + end + end + + task :config_gen_project do + PROJECT_CONFIG_FILES[:mongrel].each do |file| + deprec2.render_template(:mongrel, file) + end + end + + desc 'Deploy configuration files(s) for mongrel' + task :config, :roles => :app do + config_system + config_project + end + + task :config_system, :roles => :app do + deprec2.push_configs(:mongrel, SYSTEM_CONFIG_FILES[:mongrel]) + end + + task :config_project, :roles => :app do + create_mongrel_user_and_group + deprec2.push_configs(:mongrel, PROJECT_CONFIG_FILES[:mongrel]) + symlink_mongrel_cluster + end + + task :symlink_mongrel_cluster, :roles => :app do + deprec2.mkdir(mongrel_conf_dir, :via => :sudo) + sudo "ln -sf #{deploy_to}/mongrel/cluster.yml #{mongrel_conf}" + end + + task :unlink_mongrel_cluster, :roles => :app do + deprec2.mkdir(mongrel_conf_dir, :via => :sudo) + sudo "test -L #{mongrel_conf} && unlink #{mongrel_conf}" + end + + + # Control + + desc "Start application server." + task :start, :roles => :app do + send(run_method, "mongrel_rails cluster::start -C #{mongrel_conf}") + end + + desc "Stop application server." + task :stop, :roles => :app do + send(run_method, "mongrel_rails cluster::stop -C #{mongrel_conf}") + end + + desc "Restart application server." + task :restart, :roles => :app do + send(run_method, "mongrel_rails cluster::restart -C #{mongrel_conf}") + end + + task :activate, :roles => :app do + activate_system + activate_project + end + + task :activate_system, :roles => :app do + send(run_method, "/sbin/chkconfig --add mongrel_cluster") + send(run_method, "/sbin/chkconfig --level 345 mongrel_cluster on") + end + + task :activate_project, :roles => :app do + symlink_mongrel_cluster + end + + task :deactivate, :roles => :app do + puts + puts "******************************************************************" + puts + puts "Danger!" + puts + puts "Do you want to deactivate just this project or all mongrel" + puts "clusters on this server? Try a more granular command:" + puts + puts "cap deprec:mongrel:deactivate_system # disable all clusters" + puts "cap deprec:mongrel:deactivate_project # disable only this project" + puts + puts "******************************************************************" + puts + end + + task :deactivate_system, :roles => :app do + send(run_method, "/sbin/chkconfig --del mongrel_cluster") + end + + task :deactivate_project, :roles => :app do + unlink_mongrel_cluster + restart + end + + task :backup, :roles => :app do + end + + task :restore, :roles => :app do + end + + desc "create user and group for mongel to run as" + task :create_mongrel_user_and_group, :roles => :app do + deprec2.groupadd(mongrel_group) + deprec2.useradd(mongrel_user, :group => mongrel_group, :homedir => false) + # Set the primary group for the mongrel user (in case user already existed + # when previous command was run) + sudo "/usr/sbin/usermod -g #{mongrel_group} #{mongrel_user}" + end + + desc "set group ownership and permissions on dirs mongrel needs to write to" + task :set_perms_for_mongrel_dirs, :roles => :app do + tmp_dir = "#{deploy_to}/current/tmp" + shared_dir = "#{deploy_to}/shared" + files = ["#{mongrel_log_dir}/mongrel.log", "#{mongrel_log_dir}/#{rails_env}.log"] + + sudo "chgrp -R #{mongrel_group} #{tmp_dir} #{shared_dir}" + sudo "chmod -R g+w #{tmp_dir} #{shared_dir}" + # set owner and group of log files + files.each { |file| + sudo "touch #{file}" + sudo "chown #{mongrel_user} #{file}" + sudo "chgrp #{mongrel_group} #{file}" + sudo "chmod g+w #{file}" + } + end + + end + end +end diff --git a/lib/deprec/recipes/monit.rb b/lib/deprec/recipes/monit.rb new file mode 100644 index 0000000..c24fe60 --- /dev/null +++ b/lib/deprec/recipes/monit.rb @@ -0,0 +1,131 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :centos do namespace :monit do + + set :monit_user, 'monit' + set :monit_group, 'monit' + set :monit_confd_dir, '/etc/monit.d' + + set :monit_check_interval, 60 + set :monit_log, 'syslog facility log_daemon' + set :monit_mailserver, nil + set :monit_mail_from, 'monit@deprec.enabled.slice' + set :monit_alert_recipients, %w(root@localhost) + set :monit_timeout_recipients, %w(root@localhost) + set :monit_webserver_enabled, true + set :monit_webserver_port, 2812 + set :monit_webserver_address, 'localhost' + set :monit_webserver_allowed_hosts_and_networks, %w(localhost) + set :monit_webserver_auth_user, 'admin' + set :monit_webserver_auth_pass, 'monit' + + # Upstream changes: http://www.tildeslash.com/monit/dist/CHANGES.txt + # Ubuntu package version = monit-4.8.1 + SRC_PACKAGES[:monit] = { + :filename => 'monit-4.10.1.tar.gz', + :md5sum => "d3143b0bbd79b53f1b019d2fc1dae656 monit-4.10.1.tar.gz", + :dir => 'monit-4.10.1', + :url => "http://www.tildeslash.com/monit/dist/monit-4.10.1.tar.gz", + :unpack => "tar zxf monit-4.10.1.tar.gz;", + :configure => %w( + ./configure + ; + ).reject{|arg| arg.match '#'}.join(' '), + :make => 'make;', + :install => 'make install;' + } + + desc "Install monit" + task :install do + install_deps + deprec2.download_src(SRC_PACKAGES[:monit], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:monit], src_dir) + end + + # install dependencies for monit + task :install_deps do + apt.install( {:base => %w(flex bison openssl openssl-devel)}, :stable ) + end + + SYSTEM_CONFIG_FILES[:monit] = [ + + {:template => 'monit-init-script', + :path => '/etc/init.d/monit', + :mode => 0755, + :owner => 'root:root'}, + + {:template => 'monitrc.erb', + :path => "/etc/monitrc", + :mode => 0700, + :owner => 'root:root'}, + + {:template => 'nothing', + :path => "/etc/monit.d/nothing", + :mode => 0700, + :owner => 'root:root'} + ] + + desc <<-DESC + Generate nginx config from template. Note that this does not + push the config to the server, it merely generates required + configuration files. These should be kept under source control. + The can be pushed to the server with the :config task. + DESC + task :config_gen do + SYSTEM_CONFIG_FILES[:monit].each do |file| + deprec2.render_template(:monit, file) + end + end + + desc "Push monit config files to server" + task :config do + deprec2.push_configs(:monit, SYSTEM_CONFIG_FILES[:monit]) + end + + desc "Start Monit" + task :start, :roles => :app do + send(run_method, "/etc/init.d/monit start") + end + + desc "Stop Monit" + task :stop, :roles => :app do + send(run_method, "/etc/init.d/monit stop") + end + + desc "Restart Monit" + task :restart, :roles => :app do + send(run_method, "/etc/init.d/monit restart") + end + + desc "Reload Monit" + task :reload, :roles => :app do + send(run_method, "/etc/init.d/monit reload") + end + + desc <<-DESC + Activate monit start scripts on server. + Setup server to start monit on boot. + DESC + task :activate do + send(run_method, "/sbin/chkconfig --add monit") + send(run_method, "/sbin/chkconfig --level 345 monit on") + end + + desc <<-DESC + Dectivate monit start scripts on server. + Setup server to start monit on boot. + DESC + task :deactivate do + send(run_method, "/sbin/chkconfig --del monit") + end + + task :backup do + # there's nothing to backup for monit + end + + task :restore do + # there's nothing to restore for monit + end + + end end +end diff --git a/lib/deprec/recipes/mysql.rb b/lib/deprec/recipes/mysql.rb new file mode 100644 index 0000000..1b1f78a --- /dev/null +++ b/lib/deprec/recipes/mysql.rb @@ -0,0 +1,115 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :centos do + namespace :mysql do + + # Installation + + desc "Install mysql" + task :install, :roles => :db do + install_deps + symlink_mysql_sockfile # XXX still needed? + end + + # Install dependencies for Mysql + task :install_deps, :roles => :db do + apt.install( {:base => %w(mysql mysql-server mysql-devel)}, :stable, :repositories => [:centosplus] ) + end + + task :symlink_mysql_sockfile, :roles => :db do + # rails puts "socket: /tmp/mysql.sock" into config/database.yml + # this is not the location for our ubuntu's mysql socket file + # so we create this link to make deployment using rails defaults simpler + sudo "ln -sf /var/run/mysqld/mysqld.sock /tmp/mysql.sock" + end + + # Configuration + + SYSTEM_CONFIG_FILES[:mysql] = [ + + {:template => "my.cnf.erb", + :path => '/etc/mysql/my.cnf', + :mode => 0644, + :owner => 'root:root'} + ] + + desc "Generate configuration file(s) for mysql from template(s)" + task :config_gen do + SYSTEM_CONFIG_FILES[:mysql].each do |file| + deprec2.render_template(:mysql, file) + end + end + + desc "Push trac config files to server" + task :config, :roles => :db do + deprec2.push_configs(:mysql, SYSTEM_CONFIG_FILES[:mysql]) + end + + task :activate, :roles => :db do + send(run_method, "/sbin/chkconfig --add mysql") + end + + task :deactivate, :roles => :db do + send(run_method, "/sbin/chkconfig --del mysql") + end + + # Control + + desc "Start Mysql" + task :start, :roles => :db do + send(run_method, "/etc/init.d/mysqld start") + end + + desc "Stop Mysql" + task :stop, :roles => :db do + send(run_method, "/etc/init.d/mysqld stop") + end + + desc "Restart Mysql" + task :restart, :roles => :db do + send(run_method, "/etc/init.d/mysqld restart") + end + + desc "Reload Mysql" + task :reload, :roles => :db do + send(run_method, "/etc/init.d/mysqld reload") + end + + + task :backup, :roles => :db do + end + + task :restore, :roles => :db do + end + + end + end +end + +# +# Setup replication +# + +# setup user for repl +# GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.yourdomain.com' IDENTIFIED BY 'slavepass'; + +# get current position of binlog +# mysql> FLUSH TABLES WITH READ LOCK; +# Query OK, 0 rows affected (0.00 sec) +# +# mysql> SHOW MASTER STATUS; +# +------------------+----------+--------------+------------------+ +# | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +# +------------------+----------+--------------+------------------+ +# | mysql-bin.000012 | 296 | | | +# +------------------+----------+--------------+------------------+ +# 1 row in set (0.00 sec) +# +# # get current data +# mysqldump --all-databases --master-data >dbdump.db +# +# UNLOCK TABLES; + + +# Replication Features and Issues +# http://dev.mysql.com/doc/refman/5.0/en/replication-features.html diff --git a/lib/deprec/recipes/nagios.rb b/lib/deprec/recipes/nagios.rb new file mode 100644 index 0000000..276386f --- /dev/null +++ b/lib/deprec/recipes/nagios.rb @@ -0,0 +1,296 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :deprec do + namespace :nagios do + + set :nagios_user, 'nagios' + set :nagios_group, 'nagios' + set :nagios_cmd_group, 'nagcmd' # Allow external commands to be submitted through the web interface + + SRC_PACKAGES[:nagios] = { + :filename => 'nagios-3.0rc1.tar.gz', + :md5sum => "d8b4fbf1c2527ddcc18a39372a41dba3 nagios-3.0rc1.tar.gz", + :dir => 'nagios-3.0rc1', + :url => "http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.0rc1.tar.gz", + :unpack => "tar zxfv nagios-3.0rc1.tar.gz;", + :configure => %w( + ./configure + --with-command-group=nagcmd + ; + ).reject{|arg| arg.match '#'}.join(' '), + :make => 'make all;', + :install => 'make install install-init install-commandmode' + } + + desc "Install nagios" + task :install do + install_deps + create_nagios_user + deprec2.add_user_to_group(nagios_user, apache_user) + deprec2.mkdir('/usr/local/nagios/etc', :owner => "#{nagios_user}.#{nagios_group}", :via => :sudo) + deprec2.mkdir('/usr/local/nagios/objects', :owner => "#{nagios_user}.#{nagios_group}", :via => :sudo) + deprec2.download_src(SRC_PACKAGES[:nagios], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:nagios], src_dir) + end + + task :create_nagios_user do + deprec2.groupadd(nagios_group) + deprec2.useradd(nagios_user, :group => nagios_group, :homedir => false) + deprec2.groupadd(nagios_cmd_group) + deprec2.add_user_to_group(nagios_user, nagios_cmd_group) + end + + # Install dependencies for nagios + task :install_deps do + apt.install( {:base => %w(mailx)}, :stable ) + end + + SYSTEM_CONFIG_FILES[:nagios] = [ + + {:template => 'nagios.cfg.erb', + :path => '/usr/local/nagios/etc/nagios.cfg', + :mode => 0664, + :owner => 'nagios:nagios'}, + + {:template => 'resource.cfg.erb', + :path => '/usr/local/nagios/etc/resource.cfg', + :mode => 0660, + :owner => 'nagios:nagios'}, + + {:template => 'cgi.cfg.erb', + :path => '/usr/local/nagios/etc/cgi.cfg', + :mode => 0664, + :owner => 'nagios:nagios'}, + + {:template => 'htpasswd.users', + :path => '/usr/local/nagios/etc/htpasswd.users', + :mode => 0664, + :owner => 'nagios:nagios'}, + + {:template => 'templates.cfg.erb', + :path => '/usr/local/nagios/etc/objects/templates.cfg', + :mode => 0664, + :owner => 'nagios:nagios'}, + + {:template => 'commands.cfg.erb', + :path => '/usr/local/nagios/etc/objects/commands.cfg', + :mode => 0664, + :owner => 'nagios:nagios'}, + + {:template => 'timeperiods.cfg.erb', + :path => '/usr/local/nagios/etc/objects/timeperiods.cfg', + :mode => 0664, + :owner => 'nagios:nagios'}, + + {:template => 'localhost.cfg.erb', + :path => '/usr/local/nagios/etc/objects/localhost.cfg', + :mode => 0664, + :owner => 'nagios:nagios'}, + + {:template => 'contacts.cfg.erb', + :path => '/usr/local/nagios/etc/objects/contacts.cfg', + :mode => 0664, + :owner => 'nagios:nagios'}, + + {:template => 'hosts.cfg.erb', + :path => '/usr/local/nagios/etc/objects/hosts.cfg', + :mode => 0664, + :owner => 'nagios:nagios'}, + + {:template => 'services.cfg.erb', + :path => '/usr/local/nagios/etc/objects/services.cfg', + :mode => 0664, + :owner => 'nagios:nagios'}, + + {:template => 'localhost.cfg.erb', + :path => '/usr/local/nagios/etc/objects/localhost.cfg', + :mode => 0664, + :owner => 'nagios:nagios'}, + + {:template => 'nagios_apache_vhost.conf.erb', + :path => "conf/nagios_apache_vhost.conf", + :mode => 0644, + :owner => 'root:root'} + + ] + + desc "Generate configuration file(s) for nagios from template(s)" + task :config_gen do + SYSTEM_CONFIG_FILES[:nagios].each do |file| + deprec2.render_template(:nagios, file) + end + end + + desc "Push nagios config files to server" + task :config, :roles => :nagios do + deprec2.push_configs(:nagios, SYSTEM_CONFIG_FILES[:nagios]) + sudo "ln -sf #{deploy_to}/nagios/conf/nagios_apache_vhost.conf /usr/local/apache2/conf/apps" + config_check + restart + end + + desc "Run Nagios config check" + task :config_check, :roles => :nagios do + send(run_method, "/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg") + end + + desc "Set Nagios to start on boot" + task :activate, :roles => :nagios do + send(run_method, "update-rc.d nagios defaults") + sudo "ln -sf #{deploy_to}/nagios/conf/nagios_apache_vhost.conf #{apache_vhost_dir}/nagios_#{application}.conf" + end + + desc "Set Nagios to not start on boot" + task :deactivate, :roles => :nagios do + send(run_method, "update-rc.d -f nagios remove") + link = "#{apache_vhost_dir}/nagios_#{application}.conf" + sudo "test -h #{link} && sudo unlink #{link} || true" + end + + + # Control + + desc "Start Nagios" + task :start, :roles => :nagios do + send(run_method, "/etc/init.d/nagios start") + end + + desc "Stop Nagios" + task :stop, :roles => :nagios do + send(run_method, "/etc/init.d/nagios stop") + end + + desc "Restart Nagios" + task :restart, :roles => :nagios do + send(run_method, "/etc/init.d/nagios restart") + end + + desc "Reload Nagios" + task :reload, :roles => :nagios do + send(run_method, "/etc/init.d/nagios reload") + end + + task :backup, :roles => :web do + # not yet implemented + end + + task :restore, :roles => :web do + # not yet implemented + end + + # + # Service specific tasks + # + + # XXX quick and dirty - clean up later + desc "Grant a user access to the web interface" + task :htpass, :roles => :nagios do + target_user = Capistrano::CLI.ui.ask "Userid" do |q| + q.default = 'nagiosadmin' + end + system "htpasswd config/nagios/usr/local/nagios/etc/htpasswd.users #{target_user}" + end + + end + + + SRC_PACKAGES[:nagios_plugins] = { + :filename => 'nagios-plugins-1.4.11.tar.gz', + :md5sum => "042783a2180a6987e0b403870b3d01f7 nagios-plugins-1.4.11.tar.gz", + :dir => 'nagios-plugins-1.4.11', + :url => "http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz", + :unpack => "tar zxfv nagios-plugins-1.4.11.tar.gz;", + :configure => "./configure --with-nagios-user=#{nagios_user} --with-nagios-group=#{nagios_group};", + :make => 'make;', + :install => 'make install;' + } + + namespace :nagios_plugins do + + task :install do + install_deps + top.deprec.nagios.create_nagios_user + deprec2.download_src(SRC_PACKAGES[:nagios_plugins], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:nagios_plugins], src_dir) + end + + # Install dependencies for nagios plugins + task :install_deps do + apt.install( {:base => %w(libmysqlclient15-dev)}, :stable ) + end + + + end + + SRC_PACKAGES[:nrpe] = { + :filename => 'nrpe-2.11.tar.gz', + :md5sum => "dcf3b7c5b7c94c0ba6cbb4999c1161f0 nrpe-2.11.tar.gz", + :dir => 'nrpe-2.11', + :url => "http://easynews.dl.sourceforge.net/sourceforge/nagios/nrpe-2.11.tar.gz", + :unpack => "tar zxfv nrpe-2.11.tar.gz;", + :configure => "./configure --with-nagios-user=#{nagios_user} --with-nagios-group=#{nagios_group};", + :make => 'make all;', + :install => 'make install-plugin; make install-daemon; make install-daemon-config;' + } + + namespace :nrpe do + + task :install do + install_deps + top.deprec.nagios.create_nagios_user + deprec2.download_src(SRC_PACKAGES[:nrpe], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:nrpe], src_dir) + # XXX this should only be run on the nrpe clients + # XXX currently it's run on the nagios server too + # XXX shouldn't do any harm but we should split them up later + deprec2.append_to_file_if_missing('/etc/services', 'nrpe 5666/tcp # NRPE') + end + + task :install_deps do + apt.install( {:base => %w(xinetd openssl openssl-devel)}, :stable ) + end + + SYSTEM_CONFIG_FILES[:nrpe] = [ + + {:template => 'nrpe.xinetd.erb', + :path => "/etc/xinetd.d/nrpe", + :mode => 0644, + :owner => 'root:root'}, + + {:template => 'nrpe.cfg.erb', + :path => "/usr/local/nagios/etc/nrpe.cfg", + :mode => 0644, + :owner => 'nagios:nagios'} # XXX hard coded file owner is bad... + # It's done here because we aren't using + # lazy eval in hash constant. + + ] + + desc "Generate configuration file(s) for nrpe from template(s)" + task :config_gen do + SYSTEM_CONFIG_FILES[:nrpe].each do |file| + deprec2.render_template(:nagios, file) + end + end + + desc "Push nrpe config files to server" + task :config do + deprec2.push_configs(:nagios, SYSTEM_CONFIG_FILES[:nrpe]) + # XXX should really only do this on targets + sudo "/etc/init.d/xinetd restart" + end + + task :test_local do + run "/usr/local/nagios/libexec/check_nrpe -H localhost" + end + + task :test_remote, :roles => :nagios do + target_host = Capistrano::CLI.ui.ask "target hostname" + run "/usr/local/nagios/libexec/check_nrpe -H #{target_host}" + end + + end + + + end +end diff --git a/lib/deprec/recipes/network.rb b/lib/deprec/recipes/network.rb new file mode 100644 index 0000000..dbc8cd1 --- /dev/null +++ b/lib/deprec/recipes/network.rb @@ -0,0 +1,57 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :deprec do + namespace :network do + + set(:hostname) { + Capistrano::CLI.ui.ask "hostname" do |q| + # q.validate = /add hostname validation here/ + end + } + set(:eth0_ip) { + Capistrano::CLI.ui.ask "eth0 ip address" do |q| + # q.validate = /add ip addr validation here/ + end + } + set(:eth1_ip) { + Capistrano::CLI.ui.ask "eth1 ip address" do |q| + # q.validate = /add ip addr validation here/ + end + } + + SYSTEM_CONFIG_FILES[:network] = [ + + {:template => "interfaces.erb", + :path => '/etc/network/interfaces', + :mode => 0644, + :owner => 'root:root'}, + + {:template => "hosts.erb", + :path => '/etc/hosts', + :mode => 0644, + :owner => 'root:root'}, + + {:template => "hostname.erb", + :path => '/etc/hostname', + :mode => 0644, + :owner => 'root:root'} + + ] + + desc "Update system networking configuration" + task :config, :roles => :vmgz do + SYSTEM_CONFIG_FILES[:network].each do |file| + deprec2.render_template(:network, file.merge(:remote=>true)) + end + end + + desc "Restart network interface" + task :restart, :roles => :vmgz do + sudo '/etc/init.d/networking restart' + end + + + end + end + +end \ No newline at end of file diff --git a/lib/deprec/recipes/nginx.rb b/lib/deprec/recipes/nginx.rb new file mode 100644 index 0000000..2413a11 --- /dev/null +++ b/lib/deprec/recipes/nginx.rb @@ -0,0 +1,166 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :centos do + namespace :nginx do + + set :nginx_server_name, nil + set :nginx_user, 'nginx' + set :nginx_group, 'nginx' + set :nginx_vhost_dir, '/usr/local/nginx/conf/vhosts' + set :nginx_client_max_body_size, '50M' + + SRC_PACKAGES[:nginx] = { + :filename => 'nginx-0.5.34.tar.gz', + :md5sum => "8f7d3efcd7caaf1f06e4d95dfaeac238 nginx-0.5.34.tar.gz", + :dir => 'nginx-0.5.34', + :url => "http://sysoev.ru/nginx/nginx-0.5.34.tar.gz", + :unpack => "tar zxf nginx-0.5.34.tar.gz;", + :configure => %w( + ./configure + --sbin-path=/usr/local/sbin + --with-http_ssl_module + ; + ).reject{|arg| arg.match '#'}.join(' '), + :make => 'make;', + :install => 'make install;' + } + + desc "Install nginx" + task :install do + install_deps + install_start_stop_daemon + deprec2.download_src(SRC_PACKAGES[:nginx], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:nginx], src_dir) + create_nginx_user + # setup_vhost_dir # XXX not done yet + # install_index_page # XXX not done yet + end + + # install dependencies for nginx + task :install_deps do + #apt.install( {:base => %w(libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev)}, :stable ) + apt.install( {:base => %w(pcre* gcc make openssl openssl-devel zlib-devel)}, :stable ) + # do we need libgcrypt11-dev? + end + + task :create_nginx_user do + deprec2.groupadd(nginx_group) + deprec2.useradd(nginx_user, :group => nginx_group, :homedir => false) + end + + task :rename_index_page, :roles => :web do + index_file = '/usr/local/nginx/html/index.html' + sudo "test -f #{index_file} && sudo mv #{index_file} #{index_file}.orig || exit 0" + end + + SYSTEM_CONFIG_FILES[:nginx] = [ + + {:template => 'nginx-init-script', + :path => '/etc/init.d/nginx', + :mode => 0755, + :owner => 'root:root'}, + + {:template => 'nginx.conf.erb', + :path => "/usr/local/nginx/conf/nginx.conf", + :mode => 0644, + :owner => 'root:root'}, + + {:template => 'mime.types.erb', + :path => "/usr/local/nginx/conf/mime.types", + :mode => 0644, + :owner => 'root:root'}, + + {:template => 'nothing.conf', + :path => "/usr/local/nginx/conf/vhosts/nothing.conf", + :mode => 0644, + :owner => 'root:root'} + ] + + desc <<-DESC + Generate nginx config from template. Note that this does not + push the config to the server, it merely generates required + configuration files. These should be kept under source control. + The can be pushed to the server with the :config task. + DESC + task :config_gen do + SYSTEM_CONFIG_FILES[:nginx].each do |file| + deprec2.render_template(:nginx, file) + end + end + + desc "Push nginx config files to server" + task :config, :roles => :web do + deprec2.push_configs(:nginx, SYSTEM_CONFIG_FILES[:nginx]) + end + + desc "install start_stop_daemon" + task :install_start_stop_daemon, :roles => :web do + commands = <<-DESC + sh -c 'cd /usr/local/src; + wget http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-1.tar.gz; + tar zxvf apps-sys-utils-start-stop-daemon-IR1_9_18-1.tar.gz; + cd /usr/local/src/apps/sys-utils/start-stop-daemon-IR1_9_18-1/; + gcc start-stop-daemon.c -o start-stop-daemon; + cp start-stop-daemon /usr/sbin;' + DESC + send(run_method, commands) + end + + desc <<-DESC + Activate nginx start scripts on server. + Setup server to start nginx on boot. + DESC + task :activate, :roles => :web do + activate_system + end + + task :activate_system, :roles => :web do + send(run_method, "/sbin/chkconfig --add nginx") + send(run_method, "/sbin/chkconfig --level 345 nginx on") + end + + desc <<-DESC + Dectivate nginx start scripts on server. + Setup server to start nginx on boot. + DESC + task :deactivate, :roles => :web do + send(run_method, "/sbin/chkconfig --del nginx") + end + + + # Control + + desc "Start Nginx" + task :start, :roles => :web do + send(run_method, "/etc/init.d/nginx start") + end + + desc "Stop Nginx" + task :stop, :roles => :web do + send(run_method, "/etc/init.d/nginx stop") + end + + desc "Restart Nginx" + task :restart, :roles => :web do + # So that restart will work even if nginx is not running + # we call stop and ignore the return code. We then start it. + send(run_method, "/etc/init.d/nginx stop; exit 0") + send(run_method, "/etc/init.d/nginx start") + end + + desc "Reload Nginx" + task :reload, :roles => :web do + send(run_method, "/etc/init.d/nginx reload") + end + + task :backup, :roles => :web do + # there's nothing to backup for nginx + end + + task :restore, :roles => :web do + # there's nothing to store for nginx + end + + end + end +end diff --git a/lib/deprec/recipes/ntp.rb b/lib/deprec/recipes/ntp.rb new file mode 100644 index 0000000..68ec69e --- /dev/null +++ b/lib/deprec/recipes/ntp.rb @@ -0,0 +1,96 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :deprec do + namespace :ntp do + + + # Install + + desc "Install ntp" + task :install do + install_deps + end + + # install dependencies for nginx + task :install_deps do + apt.install( {:base => %w(ntp)}, :stable ) + end + + + # Configure + + SYSTEM_CONFIG_FILES[:ntp] = [ + + {:template => 'ntp.conf.erb', + :path => '/etc/ntp.conf', + :mode => 0755, + :owner => 'root:root'} + ] + + desc "Generate ntp config from template." + task :config_gen do + SYSTEM_CONFIG_FILES[:ntp].each do |file| + deprec2.render_template(:ntp, file) + end + end + + desc "Push ntp config files to server" + task :config do + deprec2.push_configs(:ntp, SYSTEM_CONFIG_FILES[:ntp]) + end + + desc 'Enable ntp start scripts on server.' + task :activate, :roles => :web do + send(run_method, "update-rc.d ntp defaults") + end + + desc 'Disable ntp start scripts on server.' + task :deactivate, :roles => :web do + send(run_method, "update-rc.d -f ntp remove") + end + + + # Control + + desc "Start ntp" + task :start do + send(run_method, "/etc/init.d/ntp start") + end + + desc "Stop ntp" + task :stop do + send(run_method, "/etc/init.d/ntp stop") + end + + desc "Restart ntp" + task :restart do + send(run_method, "/etc/init.d/ntp restart") + end + + desc "Reload ntp" + task :reload do + puts "use 'restart' instead" + exit 1 + end + + task :backup, :roles => :web do + # there's nothing to backup for ntp + end + + task :restore, :roles => :web do + # there's nothing to store for ntp + end + + end + end +end + + +# Some nice nagios checks +# +# Check important hosts have expected DNS +# +# root@sm02:/usr/local/nagios/libexec# ./check_dns --hostname=astro.blocksglobal.com --expected-address=116.240.200.167 +# DNS OK: 0.009 seconds response time. astro.blocksglobal.com returns 116.240.200.167|time=0.008744s;;;0.000000 +# +# diff --git a/lib/deprec/recipes/php.rb b/lib/deprec/recipes/php.rb new file mode 100644 index 0000000..1a8dfa6 --- /dev/null +++ b/lib/deprec/recipes/php.rb @@ -0,0 +1,100 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :deprec do + namespace :php do + + desc "Install PHP from source" + task :install do + version = 'php-5.2.4' + set :src_package, { + :file => version + '.tar.gz', + :md5sum => '0826e231c3148b29fd039d7a8c893ad3 php-5.2.4.tar.gz', + :dir => version, + :url => "http://www.php.net/distributions/#{version}.tar.gz", + :unpack => "tar zxf #{version}.tar.gz;", + :configure => %w( + ./configure + --prefix=/usr/local/php + --with-apxs2=/usr/local/apache2/bin/apxs + --disable-ipv6 + --enable-sockets + --enable-soap + --with-pcre-regex + --with-mysql + --with-zlib + --with-gettext + --with-sqlite + --enable-sqlite-utf8 + --with-openssl + --with-mcrypt + --with-ncurses + --with-jpeg-dir=/usr + --with-gd + --with-ctype + --enable-mbstring + --with-curl==/usr/lib + ; + ).reject{|arg| arg.match '#'}.join(' '), + :make => 'make;', + :install => 'make install;', + :post_install => "" + } + enable_universe + install_deps + run "export CFLAGS=-O2;" + deprec2.download_src(src_package, src_dir) + deprec2.install_from_src(src_package, src_dir) + deprec2.append_to_file_if_missing('/usr/local/apache2/conf/httpd.conf', 'AddType application/x-httpd-php .php') + end + + # install dependencies for php + task :install_deps do + puts "This function should be overridden by your OS plugin!" + apt.install( {:base => %w(zlib1g-dev zlib1g openssl openssl-devel + flex libcurl3 libcurl3-dev libmcrypt-dev libmysqlclient15-dev libncurses5-dev + libxml2-dev libjpeg62-dev libpng12-dev)}, :stable ) + end + + desc "generate config file for php" + task :config_gen do + # not yet implemented + end + + desc "deploy config file for php" + task :config, :roles => :web do + # not yet implemented + end + + task :start, :roles => :web do + # not applicable + end + + task :stop, :roles => :web do + # not applicable + end + + task :restart, :roles => :web do + # not applicable + end + + desc "enable php in webserver" + task :activate, :roles => :web do + # not yet implemented + end + + desc "disable php in webserver" + task :deactivate, :roles => :web do + # not yet implemented + end + + task :backup, :roles => :web do + # not applicable + end + + task :restore, :roles => :web do + # not applicable + end + + end + end +end diff --git a/lib/deprec/recipes/postfix.rb b/lib/deprec/recipes/postfix.rb new file mode 100644 index 0000000..6b39e34 --- /dev/null +++ b/lib/deprec/recipes/postfix.rb @@ -0,0 +1,105 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + # XXX not complete + namespace :deprec do + namespace :postfix do + + desc "Install Postfix" + task :install, :roles => :web do + install_deps + end + + # Install dependencies for Postfix + task :install_deps do + apt.install( {:base => %w(postfix)}, :stable ) + end + + SYSTEM_CONFIG_FILES[:postfix] = [ + + {:template => "main.cf.erb", + :path => '/etc/postfix/main.cf', + :mode => 0644, + :owner => 'root:root'}, + + {:template => "master.cf.erb", + :path => '/etc/postfix/master.cf', + :mode => 0644, + :owner => 'root:root'}, + + {:template => "dynamicmaps.cf.erb", + :path => '/etc/postfix/dynamicmaps.cf', + :mode => 0644, + :owner => 'root:root'}, + + {:template => "aliases.erb", + :path => '/etc/aliases', + :mode => 0644, + :owner => 'root:root'} + + ] + + desc "Generate configuration file(s) for XXX from template(s)" + task :config_gen do + SYSTEM_CONFIG_FILES[:postfix].each do |file| + deprec2.render_template(:postfix, file) + end + end + + desc 'Deploy configuration files(s) for XXX' + task :config, :roles => :mail do + deprec2.push_configs(:postfix, SYSTEM_CONFIG_FILES[:postfix]) + send(run_method, "/usr/bin/newaliases") + end + + desc "Start Postfix" + task :start, :roles => :mail do + send(run_method, "/etc/init.d/postfix start") + end + + desc "Stop Postfix" + task :stop, :roles => :mail do + send(run_method, "/etc/init.d/postfix stop") + end + + desc "Restart Postfix" + task :restart, :roles => :mail do + send(run_method, "/etc/init.d/postfix restart") + end + + desc "Reload Postfix" + task :reload, :roles => :mail do + send(run_method, "/etc/init.d/postfix reload") + end + + task :activate, :roles => :web do + end + + task :deactivate, :roles => :web do + end + + task :backup, :roles => :web do + end + + task :restore, :roles => :web do + end + + end + end +end + + + # Capistrano::Configuration.instance(:must_exist).load do +# +# namespace :deprec do namespace :nginx do +# +# #Craig: I've kept this generic rather than calling the task setup postfix. +# # if people want other smtp servers, it could be configurable +# desc "install and configure postfix" +# task :setup_smtp_server do +# install_postfix +# set :postfix_destination_domains, [domain] + apache_server_aliases +# deprec.render_template_to_file('postfix_main', '/etc/postfix/main.cf') +# end +# +# end end +# end \ No newline at end of file diff --git a/lib/deprec/recipes/postgresql.rb b/lib/deprec/recipes/postgresql.rb new file mode 100644 index 0000000..49efd37 --- /dev/null +++ b/lib/deprec/recipes/postgresql.rb @@ -0,0 +1,116 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :centos do + namespace :postgresql do + + # Installation + + desc "Install postgresql" + task :install, :roles => :db do + install_deps + #symlink_mysql_sockfile # XXX still needed? + end + + # Install dependencies for PostgreSQL + task :install_deps, :roles => :db do + apt.install( {:base => %w(postgresql postgresql-server postgresql-devel)}, :stable, :repositories => [:centosplus] ) + gem2.install "ruby-pg" + end + + task :symlink_mysql_sockfile, :roles => :db do + # rails puts "socket: /tmp/mysql.sock" into config/database.yml + # this is not the location for our ubuntu's mysql socket file + # so we create this link to make deployment using rails defaults simpler + sudo "ln -sf /var/run/mysqld/mysqld.sock /tmp/mysql.sock" + end + + # Configuration + + SYSTEM_CONFIG_FILES[:mysql] = [ + + {:template => "my.cnf.erb", + :path => '/etc/mysql/my.cnf', + :mode => 0644, + :owner => 'root:root'} + ] + + desc "Generate configuration file(s) for mysql from template(s)" + task :config_gen do + SYSTEM_CONFIG_FILES[:mysql].each do |file| + deprec2.render_template(:mysql, file) + end + end + + desc "Push trac config files to server" + task :config, :roles => :db do + deprec2.push_configs(:mysql, SYSTEM_CONFIG_FILES[:mysql]) + end + + task :activate, :roles => :db do + send(run_method, "/sbin/chkconfig --add postgresql") + end + + task :deactivate, :roles => :db do + send(run_method, "/sbin/chkconfig --del postgresql") + end + + # Control + + desc "Start PostgreSQL" + task :start, :roles => :db do + send(run_method, "/etc/init.d/postgresql start") + end + + desc "Stop PostgreSQL" + task :stop, :roles => :db do + send(run_method, "/etc/init.d/postgresql stop") + end + + desc "Restart PostgreSQL" + task :restart, :roles => :db do + send(run_method, "/etc/init.d/postgresql restart") + end + + desc "Reload PostgreSQL" + task :reload, :roles => :db do + send(run_method, "/etc/init.d/postgresql reload") + end + + + task :backup, :roles => :db do + end + + task :restore, :roles => :db do + end + + end + end +end + +# +# Setup replication +# + +# setup user for repl +# GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.yourdomain.com' IDENTIFIED BY 'slavepass'; + +# get current position of binlog +# mysql> FLUSH TABLES WITH READ LOCK; +# Query OK, 0 rows affected (0.00 sec) +# +# mysql> SHOW MASTER STATUS; +# +------------------+----------+--------------+------------------+ +# | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +# +------------------+----------+--------------+------------------+ +# | mysql-bin.000012 | 296 | | | +# +------------------+----------+--------------+------------------+ +# 1 row in set (0.00 sec) +# +# # get current data +# mysqldump --all-databases --master-data >dbdump.db +# +# UNLOCK TABLES; + + +# Replication Features and Issues +# http://dev.mysql.com/doc/refman/5.0/en/replication-features.html diff --git a/lib/deprec/recipes/rails.rb b/lib/deprec/recipes/rails.rb new file mode 100644 index 0000000..f907bc0 --- /dev/null +++ b/lib/deprec/recipes/rails.rb @@ -0,0 +1,316 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + + set :database_yml_in_scm, true + set :app_symlinks, nil + set :rails_env, 'production' + set :gems_for_project, nil # Array of gems to be installed for app + set :shared_dirs, nil # Array of directories that should be created under shared/ + # and linked to in the project + + # Hook into the default capistrano deploy tasks + before 'deploy:setup', :except => { :no_release => true } do + top.deprec.rails.setup_user_perms + top.deprec.rails.setup_paths + top.deprec.rails.setup_shared_dirs + top.deprec.rails.install_gems_for_project + end + + # Override default cap task using sudo to create dir + namespace :deploy do + task :setup, :except => { :no_release => true } do + dirs = [deploy_to, releases_path, shared_path] + dirs += %w(system log pids).map { |d| File.join(shared_path, d) } + sudo "sh -c 'umask 02 && mkdir -p #{dirs.join(' ')}'" + end + end + + after 'deploy:setup', :except => { :no_release => true } do + top.deprec.rails.setup_servers + top.deprec.rails.create_config_dir + end + + after 'deploy:symlink', :roles => :app do + top.deprec.rails.symlink_shared_dirs + top.deprec.rails.symlink_database_yml unless database_yml_in_scm + top.deprec.mongrel.set_perms_for_mongrel_dirs + end + + after :deploy, :roles => :app do + deploy.cleanup + end + + # redefine the reaper + namespace :deploy do + task :restart do + top.deprec.mongrel.restart + top.deprec.nginx.restart + end + end + + + PROJECT_CONFIG_FILES[:nginx] = [ + + {:template => 'rails_nginx_vhost.conf.erb', + :path => "rails_nginx_vhost.conf", + :mode => 0644, + :owner => 'root:root'} + ] + + PROJECT_CONFIG_FILES[:monit] = [ + + { :template => 'monit_mongrel.erb', + :path => "monit_mongrel.conf", + :mode => 0600, + :owner => 'root:root'} + ] + + namespace :centos do + namespace :rails do + + task :install, :roles => :app do + install_deps + install_gems + end + + task :install_deps do + apt.install( {:base => %w(sqlite sqlite-devel)}, :stable ) + apt.install( {:base => %w(mysql mysql-devel)}, :stable, :repositories => [:centosplus] ) + end + + # install some required ruby gems + task :install_gems do + gem2.install 'sqlite3-ruby' + gem2.install 'mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql' + gem2.install 'rails' + gem2.install 'rspec' # seems to be required to run rake db:migrate (???) + # gem2.install 'builder' # XXX ? needed ? + end + + task :install_gems_for_project do + if gems_for_project + gems_for_project.each { |gem| gem2.install(gem) } + end + end + + task :config_gen do + PROJECT_CONFIG_FILES[:nginx].each do |file| + deprec2.render_template(:nginx, file) + end + + PROJECT_CONFIG_FILES[:monit].each do |file| + deprec2.render_template(:monit, file) + end + top.deprec.mongrel.config_gen_project + end + + task :config, :roles => [:app, :web] do + deprec2.push_configs(:nginx, PROJECT_CONFIG_FILES[:nginx]) + deprec2.push_configs(:monit, PROJECT_CONFIG_FILES[:monit]) + top.deprec.mongrel.config_project + symlink_nginx_vhost + symlink_monit_config + end + + task :symlink_nginx_vhost, :roles => :web do + sudo "ln -sf #{deploy_to}/nginx/rails_nginx_vhost.conf #{nginx_vhost_dir}/#{application}.conf" + end + + task :symlink_monit_config, :roles => :app do + sudo "ln -sf #{deploy_to}/monit/monit_mongrel.conf #{monit_confd_dir}/mongrel_#{application}.conf" + end + + + task :create_config_dir do + deprec2.mkdir("#{shared_path}/config", :group => group, :mode => 0775, :via => :sudo) + end + + # create deployment group and add current user to it + task :setup_user_perms do + deprec2.groupadd(group) + deprec2.add_user_to_group(user, group) + deprec2.groupadd(mongrel_group) + deprec2.add_user_to_group(user, mongrel_group) + # we've just added ourself to a group - need to teardown connection + # so that next command uses new session where we belong in group + deprec2.teardown_connections + end + + # Setup database server. + task :setup_db, :roles => :db, :only => { :primary => true } do + top.deprec.mysql.setup + end + + # setup extra paths required for deployment + task :setup_paths, :roles => :app do + deprec2.mkdir(deploy_to, :mode => 0775, :group => group, :via => :sudo) + deprec2.mkdir(shared_path, :mode => 0775, :group => group, :via => :sudo) + end + + # Symlink list of files and dirs from shared to current + # + # XXX write up explanation + # + desc "Setup shared dirs" + task :setup_shared_dirs, :roles => [:app, :web] do + if shared_dirs + shared_dirs.each { |dir| deprec2.mkdir( "#{shared_path}/#{dir}", :via => :sudo ) } + end + end + # + desc "Symlink shared dirs." + task :symlink_shared_dirs, :roles => [:app, :web] do + if shared_dirs + shared_dirs.each do |dir| + path = File.split(dir)[0] + if path != '.' + deprec2.mkdir("#{current_path}/#{path}") + end + run "ln -nfs #{shared_path}/#{dir} #{current_path}/#{dir}" + end + end + end + + # desc "Symlink shared files." + # task :symlink_shared_files, :roles => [:app, :web] do + # if shared_files + # shared_files.each { |file| run "ln -nfs #{shared_path}/#{file} #{current_path}/#{file}" } + # end + # end + + # database.yml stuff + # + # XXX DRY this up + # I don't know how to let :gen_db_yml check if values have been set. + # + # if (self.respond_to?("db_host_#{rails_env}".to_sym)) # doesn't seem to work + + set :db_host_default, lambda { Capistrano::CLI.prompt 'Enter database host', 'localhost'} + set :db_host_staging, lambda { db_host_default } + set :db_host_production, lambda { db_host_default } + + set :db_name_default, lambda { Capistrano::CLI.prompt 'Enter database name', "#{application}_#{rails_env}" } + set :db_name_staging, lambda { db_name_default } + set :db_name_production, lambda { db_name_default } + + set :db_user_default, lambda { Capistrano::CLI.prompt 'Enter database user', 'root' } + set :db_user_staging, lambda { db_user_default } + set :db_user_production, lambda { db_user_default } + + set :db_pass_default, lambda { Capistrano::CLI.prompt 'Enter database pass', '' } + set :db_pass_staging, lambda { db_pass_default } + set :db_pass_production, lambda { db_pass_default } + + set :db_adaptor_default, lambda { Capistrano::CLI.prompt 'Enter database adaptor', 'mysql' } + set :db_adaptor_staging, lambda { db_adaptor_default } + set :db_adaptor_production, lambda { db_adaptor_default } + + set :db_socket_default, lambda { Capistrano::CLI.prompt('Enter database socket', '')} + set :db_socket_staging, lambda { db_socket_default } + set :db_socket_production, lambda { db_socket_default } + + task :generate_database_yml, :roles => :app do + database_configuration = render :template => <<-EOF + #{rails_env}: + adapter: #{self.send("db_adaptor_#{rails_env}")} + database: #{self.send("db_name_#{rails_env}")} + username: #{self.send("db_user_#{rails_env}")} + password: #{self.send("db_pass_#{rails_env}")} + host: #{self.send("db_host_#{rails_env}")} + socket: #{self.send("db_socket_#{rails_env}")} + EOF + run "mkdir -p #{deploy_to}/#{shared_dir}/config" + put database_configuration, "#{deploy_to}/#{shared_dir}/config/database.yml" + end + + desc "Link in the production database.yml" + task :symlink_database_yml, :roles => :app do + run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" + end + + desc <<-DESC + install_rails_stack takes a stock standard ubuntu 'gutsy' 7.10 server + and installs everything needed to be a Rails machine + DESC + task :install_rails_stack do + + # Generate configs first in case user input is required + # Then we can go make a cup of tea. + top.deprec.nginx.config_gen + top.deprec.mongrel.config_gen_system + top.deprec.monit.config_gen + + # Nginx as our web frontend + top.deprec.nginx.install + top.deprec.nginx.config + + # Subversion + top.deprec.svn.install + # Git + top.deprec.git.install + # Ruby + top.deprec.ruby.install + top.deprec.rubygems.install + + # Mongrel as our app server + top.deprec.mongrel.install + top.deprec.mongrel.config_system + + # Monit + top.deprec.monit.install + top.deprec.monit.config + + # Install mysql + top.deprec.mysql.install + top.deprec.mysql.start + + # Install rails + top.deprec.rails.install + end + + desc "setup and configure servers" + task :setup_servers do + + top.deprec.nginx.activate + top.deprec.mongrel.create_mongrel_user_and_group + top.deprec.mongrel.config_gen_project + top.deprec.mongrel.config_project + top.deprec.mongrel.activate + top.deprec.monit.activate + top.deprec.rails.config_gen + top.deprec.rails.config + end + end + + namespace :db do + + desc "Create database" + task :create, :roles => :db do + run "cd #{deploy_to}/current && rake db:create RAILS_ENV=#{rails_env}" + end + + desc "Run database migrations" + task :migrate, :roles => :db do + run "cd #{deploy_to}/current && rake db:migrate RAILS_ENV=#{rails_env}" + end + + desc "Run database migrations" + task :schema_load, :roles => :db do + run "cd #{deploy_to}/current && rake db:schema:load RAILS_ENV=#{rails_env}" + end + + desc "Roll database back to previous migration" + task :rollback, :roles => :db do + run "cd #{deploy_to}/current && rake db:rollback RAILS_ENV=#{rails_env}" + end + + end + + + namespace :deploy do + task :restart, :roles => :app, :except => { :no_release => true } do + top.deprec.mongrel.restart + end + end + end +end diff --git a/lib/deprec/recipes/ruby.rb b/lib/deprec/recipes/ruby.rb new file mode 100644 index 0000000..8da1c49 --- /dev/null +++ b/lib/deprec/recipes/ruby.rb @@ -0,0 +1,66 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + + namespace :centos do + namespace :ruby do + + SRC_PACKAGES[:ruby] = { + :filename => 'ruby-1.8.6-p110.tar.gz', + :md5sum => "5d9f903eae163cda2374ef8fdba5c0a5 ruby-1.8.6-p110.tar.gz", + :dir => 'ruby-1.8.6-p110', + :url => "ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p110.tar.gz", + :unpack => "tar zxf ruby-1.8.6-p110.tar.gz;", + :configure => %w( + ./configure + --with-readline-dir=/usr/local + ; + ).reject{|arg| arg.match '#'}.join(' '), + :make => 'make;', + :install => 'make install;' + } + + task :install do + install_deps + deprec2.download_src(SRC_PACKAGES[:ruby], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:ruby], src_dir) + end + + task :install_deps do + apt.install( {:base => %w(openssl openssl-devel)}, :stable ) + end + + end + end + + + namespace :centos do + namespace :rubygems do + + SRC_PACKAGES[:rubygems] = { + :filename => 'rubygems-1.0.1.tgz', + :md5sum => "0d5851084955c327ee1dc9cbd631aa5f rubygems-1.0.1.tgz", + :dir => 'rubygems-1.0.1', + :url => "http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz", + :unpack => "tar zxf rubygems-1.0.1.tgz;", + :install => 'ruby setup.rb;' + } + + task :install do + install_deps + deprec2.download_src(SRC_PACKAGES[:rubygems], src_dir) + deprec2.install_from_src(SRC_PACKAGES[:rubygems], src_dir) + # gem2.upgrade # you may not want to upgrade your gems right now + # If we want to selfupdate then we need to + # create symlink as latest gems version is broken + # gem2.update_system + # sudo ln -s /usr/bin/gem1.8 /usr/bin/gem + end + + # install dependencies for rubygems + task :install_deps do + end + + end + end + +end diff --git a/lib/deprec/recipes/ssh.rb b/lib/deprec/recipes/ssh.rb new file mode 100644 index 0000000..bf9720b --- /dev/null +++ b/lib/deprec/recipes/ssh.rb @@ -0,0 +1,93 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :centos do + namespace :ssh do + + SYSTEM_CONFIG_FILES[:ssh] = [ + + {:template => "sshd_config.erb", + :path => '/etc/ssh/sshd_config', + :mode => 0644, + :owner => 'root:root'}, + + {:template => "ssh_config.erb", + :path => '/etc/ssh/ssh_config', + :mode => 0644, + :owner => 'root:root'} + ] + + task :config_gen do + SYSTEM_CONFIG_FILES[:ssh].each do |file| + deprec2.render_template(:ssh, file) + end + auth_keys_dir = 'config/ssh/authorized_keys' + if ! File.directory?(auth_keys_dir) + puts "Creating #{auth_keys_dir}" + Dir.mkdir(auth_keys_dir) + end + end + + desc "Push ssh config files to server" + task :config do + deprec2.push_configs(:ssh, SYSTEM_CONFIG_FILES[:ssh]) + restart + end + + desc "Start ssh" + task :start do + send(run_method, "/etc/init.d/sshd reload") + end + + desc "Stop ssh" + task :stop do + send(run_method, "/etc/init.d/sshd reload") + end + + desc "Restart ssh" + task :restart do + send(run_method, "/etc/init.d/sshd restart") + end + + desc "Reload ssh" + task :reload do + send(run_method, "/etc/init.d/sshd reload") + end + + desc "Sets up authorized_keys file on remote server" + task :setup_keys do + + default(:target_user) { + Capistrano::CLI.ui.ask "Setup keys for which user?" do |q| + q.default = user + end + } + + if target_user == user + + unless ssh_options[:keys] + puts <<-ERROR + + You need to define the name of your SSH key(s) + e.g. ssh_options[:keys] = %w(/Users/your_username/.ssh/id_rsa) + + You can put this in your .caprc file in your home directory. + + ERROR + exit + end + + deprec2.mkdir '.ssh', :mode => 0700 + put(ssh_options[:keys].collect{|key| File.read(key+'.pub')}.join("\n"), '.ssh/authorized_keys', :mode => 0600 ) + + else + + deprec2.mkdir "/home/#{target_user}/.ssh", :mode => 0700, :owner => "#{target_user}.users", :via => :sudo + std.su_put File.read("config/ssh/authorized_keys/#{target_user}"), "/home/#{target_user}/.ssh/authorized_keys", '/tmp/', :mode => 0600 + sudo "chown #{target_user}.users /home/#{target_user}/.ssh/authorized_keys" + + end + end + + end + end +end diff --git a/lib/deprec/recipes/subversion.rb b/lib/deprec/recipes/subversion.rb new file mode 100644 index 0000000..006e572 --- /dev/null +++ b/lib/deprec/recipes/subversion.rb @@ -0,0 +1,166 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +require 'fileutils' +require 'uri' + +# http://svnbook.red-bean.com/en/1.4/svn-book.html#svn.serverconfig.choosing.apache + +Capistrano::Configuration.instance(:must_exist).load do + namespace :centos do namespace :svn do + + set :scm_group, 'scm' + + # Extract svn attributes from :repository URL + # + # Two examples of :repository entries are: + # + # set :repository, 'svn+ssh://scm.deprecated.org/var/svn/deprec/trunk' + # set :repository, 'file:///tmp/svn/deprec/trunk' + # + # This has only been tested with svn+ssh but file: should work. + # + set (:svn_scheme) { URI.parse(repository).scheme } + set (:svn_host) { URI.parse(repository).host } + set (:repos_path) { URI.parse(repository).path } + set (:repos_root) { + URI.parse(repository).path.sub(/\/(trunk|tags|branches)$/, '') + } + + # account name to perform actions on (such as granting access to an account) + # this is a hack to allow us to optionally pass a variable to tasks + set (:svn_account) do + Capistrano::CLI.ui.ask 'account name' + end + + set(:svn_backup_dir) { File.join(backup_dir, 'svn') } + + desc "Install Subversion" + task :install, :roles => :scm do + install_deps + # XXX should really check if apache has already been installed + # XXX can do that when we move to rake + # deprec2.download_src(src_package, src_dir) + # deprec2.install_from_src(src_package, src_dir) + end + + desc "install dependencies for Subversion" + task :install_deps do + apt.install( {:base => %w(subversion)}, :stable ) + # XXX deprec1 - was building from source to get subversion-1.4.5 onto dapper. Compiled swig bindings for trac + # apt.install( {:base => %w(build-essential wget libneon25 libneon25-dev swig python-dev libexpat1-dev)}, :stable ) + end + + desc "grant a user access to svn repos" + task :grant_user_access, :roles => :scm do + # creates account, scm_group and adds account to group + deprec2.useradd(svn_account) + deprec2.groupadd(scm_group) + deprec2.add_user_to_group(svn_account, scm_group) + end + + desc "Create subversion repository and import project into it" + task :setup, :roles => :scm do + create_repos + import + end + + desc "Create a subversion repository" + task :create_repos, :roles => :scm do + set :svn_account, top.user + grant_user_access + deprec2.mkdir(repos_root, :mode => 02775, :group => scm_group, :via => :sudo) + sudo "svnadmin verify #{repos_root} > /dev/null 2>&1 || sudo svnadmin create #{repos_root}" + sudo "chmod -R g+w #{repos_root}" + end + + # Adapted from code in Bradley Taylors RailsMachine gem + desc "Import project into subversion repository." + task :import, :roles => :scm do + new_path = "../#{application}" + tags = repository.sub("trunk", "tags") + branches = repository.sub("trunk", "branches") + puts "Adding branches and tags" + system "svn mkdir -m 'Adding tags and branches directories' #{tags} #{branches}" + puts "Importing application." + system "svn import #{repository} -m 'Import'" + cwd = Dir.getwd + puts "Moving application to new directory" + Dir.chdir '../' + system "mv #{cwd} #{cwd}.imported" + puts "Checking out application." + system "svn co #{repository} #{application}" + Dir.chdir application + remove_log_and_tmp + puts "Your repository is: #{repository}" + end + + # Lifted from Bradley Taylors RailsMachine gem + desc "remove and ignore log files and tmp from subversion" + task :remove_log_and_tmp, :roles => :scm do + puts "removing log directory contents from svn" + system "svn remove log/*" + puts "ignoring log directory" + system "svn propset svn:ignore '*.log' log/" + system "svn update log/" + puts "removing contents of tmp sub-directorys from svn" + system "svn remove tmp/cache/*" + system "svn remove tmp/pids/*" + system "svn remove tmp/sessions/*" + system "svn remove tmp/sockets/*" + puts "ignoring tmp directory" + system "svn propset svn:ignore '*' tmp/cache" + system "svn propset svn:ignore '*' tmp/pids" + system "svn propset svn:ignore '*' tmp/sessions" + system "svn propset svn:ignore '*' tmp/sockets" + system "svn update tmp/" + puts "committing changes" + system "svn commit -m 'Removed and ignored log files and tmp'" + end + + # desc "Cache svn name and password on the server. Useful for http-based repositories." + task :cache_credentials do + run_with_input "svn list #{repository}" + end + + desc "create backup of trac repository" + task :backup, :roles => :scm do + # http://svnbook.red-bean.com/nightly/en/svn.reposadmin.maint.html#svn.reposadmin.maint.backup + # XXX do we need this? insane! + # echo "REPOS_BASE=/var/svn" > ~/.svntoolsrc + timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S") + dest_dir = File.join(svn_backup_dir, "svn_#{application}_#{timestamp}") + run "svn-dump #{application} #{dest_dir}" + end + + task :restore, :roles => :scm do + # prompt user to select from list of locally stored backups + # tracd_stop + # copy out backup + end + + + # XXX TODO + # desc "backup repository" + # task :svn_backup_respository, :roles => :scm do + # puts "read http://svnbook.red-bean.com/nightly/en/svn-book.html#svn.reposadmin.maint.backup" + # end + + end end +end + +# svnserve setup +# I've previously used ssh exclusively I've decided svnserve is a reasonable choice for collaboration on open source projects. +# It's easier to setup than apache/ssl webdav access. +# +# sudo useradd svn +# sudo mkdir -p /var/svn/deprec_svnserve_root +# sudo ln -sf /var/www/apps/deprec/repos /var/svn/deprec_svnserve_root/deprec +# sudo chown -R svn /var/svn/deprec_svnserve_root/deprec + +# +# XXX put password file into svn and command to push it +# +# # run svnserve +# sudo -u svn svnserve --daemon --root /var/svn/deprec_svnserve_root +# +# # check it out now +# svn co svn://scm.deprecated.org/deprec/trunk deprec diff --git a/lib/deprec/recipes/trac.rb b/lib/deprec/recipes/trac.rb new file mode 100644 index 0000000..f40c474 --- /dev/null +++ b/lib/deprec/recipes/trac.rb @@ -0,0 +1,254 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :deprec do namespace :trac do + + # Master tracd process for server + set :tracd_cmd, '/usr/local/bin/tracd' + set :tracd_port, '9000' + set :tracd_pidfile, '/var/run/tracd.pid' + + # Settings for this projects trac instance + set(:trac_backup_dir) { "#{backup_dir}/trac" } + set(:trac_path) { exists?(:deploy_to) ? "#{deploy_to}/trac" : Capistrano::CLI.ui.ask('path to trac config') } + set(:tracd_parent_dir) { "#{deploy_to}/../trac/projects" } + set(:trac_password_file) { "#{trac_path}/conf/users.htdigest" } + set(:trac_account) { Capistrano::CLI.prompt('enter new trac user account name') } + set :trac_passwordfile_exists, true # hack - should check on remote system instead + set(:trac_header_logo_link) { trac_home_url } + # We will symlink each projects trac dir into this dir for tracd to find + + # project + set(:trac_domain) { domain.sub(/^.*?\./, 'trac.') } + set(:trac_home_url) { "http://#{trac_domain}/" } + set(:trac_desc) { application } + + # Settings only used for generating trac.ini for this project + # - notification + set :trac_always_notify_owner, false + set :trac_always_notify_reporter, false + set :trac_always_notify_updater, true + set :trac_smtp_always_bcc, '' + set :trac_smtp_always_cc, '' + set :trac_smtp_default_domain, '' + set :trac_smtp_enabled, true + set :trac_smtp_from, 'trac@localhost' + set :trac_smtp_password, '' + set :trac_smtp_port, 25 + set :trac_smtp_replyto, 'trac@localhost' + set :trac_smtp_server, 'localhost' + set :trac_smtp_subject_prefix, '__default__' + set :trac_smtp_user, '' + set :trac_use_public_cc, false + set :trac_use_short_addr, false + set :trac_use_tls, false + # - other + set(:trac_base_url) { trac_home_url } + + desc "Install trac on server" + task :install, :roles => :scm do + version = 'trac-0.10.4' + set :src_package, { + :file => version + '.tar.gz', + :md5sum => '52a3a21ad9faafc3b59cbeb87d5a69d2 trac-0.10.4.tar.gz', + :dir => version, + :url => "http://ftp.edgewall.com/pub/trac/#{version}.tar.gz", + :unpack => "tar zxf #{version}.tar.gz;", + :install => 'python ./setup.py install --prefix=/usr/local;' + } + enable_universe + apt.install( {:base => %w(build-essential wget python-sqlite sqlite python-clearsilver)}, :stable ) + deprec2.download_src(src_package, src_dir) + deprec2.install_from_src(src_package, src_dir) + end + + # The start script has a couple of config values in it. + # We may want to extract them into a config file later + # and install this script as part of the :install task. + SYSTEM_CONFIG_FILES[:trac] = [ + {:template => 'tracd-init.erb', + :path => '/etc/init.d/tracd', + :mode => 0755, + :owner => 'root:root'} + ] + + PROJECT_CONFIG_FILES[:trac] = [ + {:template => 'trac.ini.erb', + :path => "conf/trac.ini", + :mode => 0644, + :owner => 'root:root'}, + + {:template => 'apache_vhost.conf.erb', + :path => "conf/trac_apache_vhost.conf", + :mode => 0644, + :owner => 'root:root'} + ] + + desc "Generate config files for trac" + task :config_gen do + config_gen_system + config_gen_project + end + + task :config_gen_system do + SYSTEM_CONFIG_FILES[:trac].each do |file| + deprec2.render_template(:trac, file) + end + end + + task :config_gen_project do + PROJECT_CONFIG_FILES[:trac].each do |file| + deprec2.render_template(:trac, file) + end + end + + desc "Push trac config files to server" + task :config, :roles => :scm do + config_system + config_project + end + + task :config_system, :roles => :scm do + deprec2.push_configs(:trac, SYSTEM_CONFIG_FILES[:trac]) + end + + task :config_project, :roles => :scm do + deprec2.push_configs(:trac, PROJECT_CONFIG_FILES[:trac]) + end + + desc "Initialize the trac db for this project" + task :setup, :roles => :scm do + config_gen_project + config_project + init + set_default_permissions + # create trac account for current user + set :trac_account, user + set :trac_passwordfile_exists, false # hack - should check on remote system instead + user_add + create_pid_dir + end + + task :init, :roles => :scm do + sudo "trac-admin #{trac_path} initenv #{application} sqlite:db/trac.db svn #{repos_root} /usr/local/share/trac/templates" + end + + task :set_default_permissions, :roles => :scm do + anonymous_disable + authenticated_enable + end + + task :start, :roles => :scm do + sudo "/etc/init.d/tracd start" + sudo "/etc/init.d/httpd restart" + end + + task :stop, :roles => :scm do + sudo "/etc/init.d/tracd stop" + end + + task :restart, :roles => :scm do + stop + start + end + + task :activate, :roles => :scm do + activate_system + activate_project + end + + task :activate_system, :roles => :scm do + sudo "update-rc.d tracd defaults" + end + + task :activate_project, :roles => :scm do + symlink_project + end + + task :deactivate, :roles => :scm do + deactivate_system + deactivate_project + end + + task :deactivate_system, :roles => :scm do + sudo "update-rc.d -f tracd remove" + end + + task :deactivate_project, :roles => :scm do + # XXX unlink project config + # XXX restart tracd + end + + desc "Create backup of trac repository" + task :backup, :roles => :web do + # http://trac.edgewall.org/wiki/TracBackup + timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S") + dest_dir = File.join(trac_backup_dir, "trac_#{application}_#{timestamp}") + sudo "trac-admin #{trac_path} hotcopy #{dest_dir}" + end + + desc "Restore trac repository from backup" + task :restore, :roles => :web do + # prompt user to select from list of locally stored backups + # tracd_stop + # copy out backup + end + + # + # Service specific tasks for end users + # + desc "create a trac user" + task :user_add, :roles => :scm do + create_file = trac_passwordfile_exists ? '' : ' -c ' + htdigest = '/usr/local/apache2/bin/htdigest' + # XXX check if htdigest file exists and add '-c' option if not + # sudo "test -f #{trac_path/conf/users.htdigest} + create_file = trac_passwordfile_exists ? '' : ' -c ' + deprec2.sudo_with_input("#{htdigest} #{create_file} #{trac_path}/conf/users.htdigest #{application} #{trac_account}", /password:/) + end + + desc "list trac users" + task :list_users, :roles => :scm do + sudo "cat #{trac_path}/conf/users.htdigest" + end + + # desc "disable anonymous access to everything" + task :anonymous_disable, :roles => :scm do + sudo "trac-admin #{trac_path} permission remove anonymous '*'" + end + + # desc "enable authenticated users access to everything" + task :authenticated_enable, :roles => :scm do + sudo "trac-admin #{trac_path} permission add authenticated TRAC_ADMIN" + end + + # + # Helper tasks used by other tasks + # + + # Link the trac repos for this project into the master trac repos dir + # We do this so we can use trac for multiple projects on the same server + task :symlink_project, :roles => :scm do + sudo "ln -sf ../../#{application}/trac #{tracd_parent_dir}/#{application}" + end + + task :unlink_project, :roles => :scm do + link = "#{tracd_parent_dir}/#{application}" + sudo "test -h #{link} && sudo unlink #{link} || true" + end + + task :symlink_apache_vhost, :roles => :scm do + sudo "ln -sf #{deploy_to}/trac/conf/trac_apache_vhost.conf #{apache_vhost_dir}/#{application}-trac.conf" + end + + task :unlink_apache_vhost, :roles => :scm do + link = "#{apache_vhost_dir}/#{application}-trac.conf" + sudo "test -h #{link} && unlink #{link} || true" + end + + task :create_pid_dir, :roles => :scm do + deprec.mkdir(File.dirname(tracd_pidfile)) + end + +end end + +end \ No newline at end of file diff --git a/lib/deprec/recipes/users.rb b/lib/deprec/recipes/users.rb new file mode 100644 index 0000000..cccf18f --- /dev/null +++ b/lib/deprec/recipes/users.rb @@ -0,0 +1,90 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :centos do + namespace :users do + + # desc "Create user account" + # task :add do + # target_user = Capistrano::CLI.ui.ask "Enter userid for new user" do |q| + # q.default = user + # end + # deprec2.useradd(target_user, :shell => '/bin/bash') + # puts "Setting password for new account" + # deprec2.invoke_with_input("passwd #{target_user}", /UNIX password/) + # end + + desc "Create account" + task :add do + target_user = Capistrano::CLI.ui.ask "Enter userid for new user" do |q| + q.default = user + end + make_admin = Capistrano::CLI.ui.ask "Should this be an admin account?" do |q| + q.default = 'no' + end + copy_keys = false + if File.readable?("config/ssh/authorized_keys/#{target_user}") + copy_keys = Capistrano::CLI.ui.ask "I've found an authorized_keys file for #{target_user}. Should I copy it out?" do |q| + q.default = 'yes' + end + end + + new_password = Capistrano::CLI.ui.ask("Enter new password for #{target_user}") { |q| q.echo = false } + + deprec2.useradd(target_user, :shell => '/bin/bash') + + deprec2.invoke_with_input("passwd #{target_user}", /UNIX password/, new_password) + + if make_admin.grep(/y/i) + deprec2.groupadd('admin') + deprec2.add_user_to_group(target_user, 'admin') + deprec2.append_to_file_if_missing('/etc/sudoers', '%admin ALL=(ALL) ALL') + end + + if copy_keys && copy_keys.grep(/y/i) + set :target_user, target_user + top.centos.ssh.setup_keys + end + + end + + desc "Create account" + task :add_admin do + puts 'deprecated! use deprec:users:add' + add + end + + desc "Change user password" + task :passwd do + target_user = Capistrano::CLI.ui.ask "Enter user to change password for" do |q| + q.default = user if user.is_a?(String) + end + new_password = Capistrano::CLI.ui.ask("Enter new password for #{target_user}") { |q| q.echo = false } + + deprec2.invoke_with_input("passwd #{target_user}", /UNIX password/, new_password) + end + + desc "Add user to group" + task :add_user_to_group do + target_user = Capistrano::CLI.ui.ask "Which user?" do |q| + q.default = user if user.is_a?(String) + end + target_group = Capistrano::CLI.ui.ask "Add to which group?" do |q| + q.default = 'deploy' + end + deprec2.add_user_to_group(target_user, target_group) + end + + # desc "Create group" + # task :add_group do + # target_group = Capistrano::CLI.ui.ask "Enter name for new group" + # deprec2.groupadd(target_group) + # end + # + # desc "Add user to group" + # task :add_user_to_group do + # # XXX not yet implemented + # end + + end + end +end diff --git a/lib/deprec/recipes/xen.rb b/lib/deprec/recipes/xen.rb new file mode 100644 index 0000000..6df59db --- /dev/null +++ b/lib/deprec/recipes/xen.rb @@ -0,0 +1,92 @@ +# Copyright 2006-2008 by Mike Bailey. All rights reserved. +Capistrano::Configuration.instance(:must_exist).load do + namespace :deprec do + namespace :xen do + + # ref: http://www.eadz.co.nz/blog/article/xen-gutsy.html + + SYSTEM_CONFIG_FILES[:xen] = [ + + {:template => "xend-config.sxp.erb", + :path => '/etc/xen/xend-config.sxp', + :mode => 0644, + :owner => 'root:root'}, + + {:template => "xen-tools.conf.erb", + :path => '/etc/xen-tools/xen-tools.conf', + :mode => 0644, + :owner => 'root:root'}, + + {:template => "xm.tmpl.erb", + :path => '/etc/xen-tools/xm.tmpl', + :mode => 0644, + :owner => 'root:root'}, + + {:template => "xendomains.erb", + :path => '/etc/default/xendomains', + :mode => 0755, + :owner => 'root:root'}, + + # This one is a bugfix for gutsy + {:template => "15-disable-hwclock", + :path => '/usr/lib/xen-tools/gutsy.d/15-disable-hwclock', + :mode => 0755, + :owner => 'root:root'}, + + # So is this - xendomains fails to shut down domains on system shutdown + {:template => "xend-init.erb", + :path => '/etc/init.d/xend', + :mode => 0755, + :owner => 'root:root'}, + + # This gives you a second network bridge on second ethernet device + {:template => "network-bridge-wrapper", + :path => '/etc/xen/scripts/network-bridge-wrapper', + :mode => 0755, + :owner => 'root:root'} + + ] + + desc "Install Xen" + task :install, :roles => :dom0 do + install_deps + # it's all in deps baby + end + + task :install_deps do + # for amd64 version of ubuntu 7.10 + apt.install( {:base => %w(linux-image-xen bridge-utils libxen3.1 python-xen-3.1 xen-docs-3.1 xen-hypervisor-3.1 xen-ioemu-3.1 xen-tools xen-utils-3.1 lvm2)}, :stable ) + # alternatively, for x86 version of ubuntu: + # apt-get install ubuntu-xen-server libc6-xen + end + + desc "Generate configuration file(s) for Xen from template(s)" + task :config_gen do + SYSTEM_CONFIG_FILES[:xen].each do |file| + deprec2.render_template(:xen, file) + end + end + + desc "Push Xen config files to server" + task :config, :roles => :dom0 do + deprec2.push_configs(:xen, SYSTEM_CONFIG_FILES[:xen]) + end + + # Create new virtual machine + # xen-create-image --force --ip=192.168.1.31 --hostname=x1 --mac=00:16:3E:11:12:31 + + # Start a virtual image (and open console to it) + # xm create -c /etc/xen/x1.cfg + + end + end +end + +# Stop the 'incrementing ethX problem' +# +# Ubuntu stores the MAC addresses of the NICs it sees. If you change an ethernet card (real or virtual) +# it will assign is a new ethX address. That's why you'll sometimes find eth2 but no eth1. +# Your domU's should have a MAC address assigned in their config file but if you come across this problem, +# fix it with this: +# +# sudo rm /etc/udev/rules.d/70-persistent-net.rules \ No newline at end of file diff --git a/lib/deprec/templates/aoe/aoe-init b/lib/deprec/templates/aoe/aoe-init new file mode 100644 index 0000000..6c25cc9 --- /dev/null +++ b/lib/deprec/templates/aoe/aoe-init @@ -0,0 +1,55 @@ +#! /bin/sh +# aoe-init - example init script for ATA over Ethernet storage +# +# Edit this script for your purposes. (Changing "eth1" to the +# appropriate interface name, adding commands, etc.) You might +# need to tune the sleep times. +# +# Install this script in /etc/init.d with the other init scripts. +# +# Make it executable: +# chmod 755 /etc/init.d/aoe-init +# +# Install symlinks for boot time: +# cd /etc/rc3.d && ln -s ../init.d/aoe-init S99aoe-init +# cd /etc/rc5.d && ln -s ../init.d/aoe-init S99aoe-init +# +# Install symlinks for shutdown time: +# cd /etc/rc0.d && ln -s ../init.d/aoe-init K01aoe-init +# cd /etc/rc1.d && ln -s ../init.d/aoe-init K01aoe-init +# cd /etc/rc2.d && ln -s ../init.d/aoe-init K01aoe-init +# cd /etc/rc6.d && ln -s ../init.d/aoe-init K01aoe-init +# + +case "$1" in + "start") + # load any needed network drivers here + + # replace "eth1" with your aoe network interface + ifconfig eth1 up + + # time for network interface to come up + sleep 4 + + modprobe aoe + + # time for AoE discovery and udev + sleep 7 + + # add your raid assemble commands here + # add any LVM commands if needed (e.g. vgchange) + # add your filesystem mount commands here + + test -d /var/lock/subsys && touch /var/lock/subsys/aoe-init + ;; + "stop") + # add your filesystem umount commands here + # deactivate LVM volume groups if needed + # add your raid stop commands here + rmmod aoe + rm -f /var/lock/subsys/aoe-init + ;; + *) + echo "usage: `basename $0` {start|stop}" 1>&2 + ;; +esac \ No newline at end of file diff --git a/lib/deprec/templates/aoe/fence_aoemask b/lib/deprec/templates/aoe/fence_aoemask new file mode 100644 index 0000000..d7f1632 --- /dev/null +++ b/lib/deprec/templates/aoe/fence_aoemask @@ -0,0 +1,351 @@ +#!/usr/bin/perl + +# +# Wrapper to aoemask for use in a cluster fence. +# Copyright (C) 2007 Brian Weck (bweck@weck.net) +# +# This script utilizes the 'aoemask' utility from: +# http://www.coraid.com/support/sr/ +# which is written by Sam Hopkins. +# +# ======================================================================= +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# ======================================================================= +# +# ~~~~~ REVISION HISTORY ~~~~~ +# 2007-08-17 - v1 - Brian Weck +# Initial release. +# +# ~~~~~ OVERVIEW ~~~~~ +# Initial mask settings on the AoE device should contain the set of all +# MAC addresses using the AoE device from the cluster. +# +# When a fence operation occurs on a node, the fenced node's mac address is +# removed from the mask list on the AoE device. This method is conceptually +# the same as fencing via a fabric switch. +# +# Once a node is fenced, the MAC address is removed from the mask list on +# the AoE device. When the fenced node is ready to rejoin the cluster, +# the MAC address must be added to the device's mask list using this +# script or using aoemask. +# +# Script returns 0 on SUCCESS and non-zero otherwise. +# +# ~~~~~ INSTALLATION ~~~~~ +# Add this file as /sbin/fence_aoemask directory and ensure the file has +# simliar permissions as the other fence_* agents. +# +# ~~~~~ CONFIGURATION ~~~~~ +# This software operates on a single shelf / slot at a time. In order to +# fence multiple shelf and slots the user should create multiple fences. +# +# e.g. a cluster.conf snippet. +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# +# Command line options: +# see man aoemask.8 +# +# stdin options (passed from fenced): +# shelf= | +# slot= | +# interface= | +# mac= | +# [ action=(disable|enable) ] | default is defined in $opt_action +# [ debug= ] | +# [ exclusive= ] | +# [ list= ] | +# [ spoof= ] | Spoof behavior is to assume success always. +# [ timeout= ] | +# [ verbose= ] | Option is used to increase logging of fence agent. +# + +# Define where you aoemask binary lives if it is not in the path. +my $aoemask_prog="/usr/local/sbin/aoemask"; +my $opt_action = 'disable'; # Default fence action + +# Get the script name from $0 and strip directory names +$_=$0; +s/.*\///; +my $proggy = $_; + +# +# +# +my $aoemask=$aoemask_prog; +my $opt_list = 1; +my $opt_debug = 1; +my $opt_verbose = 0; + +# +sub _log +{ + ($msg)=@_; + print STDOUT $msg; +} + +# +sub exit_success +{ + my $rc = 0; + _log "$proggy returning $rc\n" if $opt_verbose; + exit $rc; +} + +# +sub exit_fail +{ + my $rc = 1; + _log "$proggy returning $rc\n" if $opt_verbose; + exit $rc; +} + +# +sub fail_usage +{ + ($msg)=@_; + _log $msg."\n" if $msg; + _log "Please use see usage.\n"; + exit_fail(); +} + +# +# If running command line, pass args as specified directly to aoemask +if (@ARGV > 0) +{ + # Check for min number of args, 5 + if( @ARGV < 5 ) + { + $aoemask .= " -h"; + } + else + { + # stub in the args + foreach $i (0 .. $#ARGV) + { + $aoemask .= " $ARGV[$i]"; + } + } +} +else # Running via fenced, read the args in from stdin +{ + read_stdin_as_options(); + + # validate required args are present + fail_usage "No shelf specified." unless defined $opt_shelf; + fail_usage "No slot specified." unless defined $opt_slot; + fail_usage "No interface specified." unless defined $opt_interface; + fail_usage "No mac specified." unless defined $opt_mac; + + $aoemask .= " -d" if defined $opt_debug; + $aoemask .= " -e" if defined $opt_exclusive; + $aoemask .= " -l" if defined $opt_list; + $aoemask .= " -s $opt_spoof" if defined $opt_spoof; + $aoemask .= " -w $opt_timeout" if defined $opt_timeout; + $aoemask .= " $opt_shelf $opt_slot $opt_interface"; + + $_=$opt_action; + if (/enable/) { $aoemask .= " +$opt_mac"; } + elsif (/disable/) { $aoemask .= " -$opt_mac"; } + else + { + # This would only be reached if in the cluster.conf one specified action= + fail_usage "Unknown action: $_"; + } +} + +_log "$proggy executing '$aoemask'\n" if $opt_verbose; + +# +# aoemask (release 1) always returns an exit code of 1 +# if aoemask returned success or failure based on the response; could as follows: +# +# system($aoemask); +# $rc = ($? >> 8) & 0xff; +# exit $rc; +# + +# therefore, we must ensure the listing function is performed and grep'd +open(FH, "$aoemask 2>&1 |"); +@lines = ; +close FH; + +# +if ($opt_verbose) +{ + _log "-- begin read response --\n"; + foreach $line (@lines) { chop $line; _log "$line\n"; } + _log "-- end read response --\n"; +} + +# +if ($opt_user_says_list) +{ + @x = grep { /$opt_shelf\.$opt_slot/ } @lines; + _log foreach @x; +} + +# +# If spoofing, nothing is returned, we assume success. +exit_success() if $opt_spoof; + +# check output of aoemask for proper values depending on action. +if( ($opt_action =~ /enable/) && (grep { /$opt_mac/ } @lines) ) +{ + _log "action is to enable and found mac $opt_mac in list"."\n" if $opt_verbose; + exit_success(); +} +elsif( ($opt_action =~ /disable/) && !(grep { /$opt_mac/ } @lines) ) +{ + # here's a caveat .. which requires the debug flag to be on. + # if one is performing a disable, and specify an invalid slot / shelf / interface + # a grep for the mac will not show and therfore a return success. + # + # Workaround: need to check for an additional string, of: + # read -1 bytes + # + if( ! grep { /read -1 bytes/} @lines ) + { + # did not read that string; all is ok. + _log "action is to disable and did not find mac $opt_mac in list"."\n" if $opt_verbose; + exit_success(); + } + else + { + _log "No bytes were read from '$aoemask'.\n"; + _log "Check the slot|shelf|interface configs.\n" + } +} + +# If none of the above matched, we failed. +exit_fail(); + + +# +# Parse the stdin options +# +sub read_stdin_as_options() +{ + my $opt; + my $line = 0; + while( defined($in = <>) ) + { + $_ = $in; + chomp; + + # strip leading and trailing whitespace + s/^\s*//; + s/\s*$//; + + # skip any comments + next if /^#/; + + $line+=1; + $opt=$_; + next unless $opt; + + ($name,$val)=split /\s*=\s*/, $opt; + + if ( $name eq "" ) + { + _log "parse error: illegal name in option $line\n"; + exit_fail(); + } + + # shelf= + # slot= + # interface= + # mac= + # action=(disable|enable) + elsif ($name eq "shelf" ) + { + $opt_shelf = $val; + } + elsif ($name eq "slot" ) + { + $opt_slot = $val; + } + elsif ($name eq "interface" ) + { + $opt_interface = $val; + } + elsif ($name eq "mac" ) + { + $opt_mac = $val; + # pull out any ':' if configured as such. + # (even though aoemask can handle it) + $opt_mac =~ s/://g; + # uppercase the alphas + $opt_mac =~ tr/a-z/A-Z/; + } + elsif ($name eq "action") + { + $opt_action = $val; + } + + # debug= + # exclusive= + # list= + # spoof= + # timeout= + elsif ($name eq "debug" ) + { + $opt_debug = 1; + } + elsif ($name eq "exclusive" ) + { + $opt_exclusive = 1; + } + elsif ($name eq "list" ) + { + $opt_list = 1; + $opt_user_says_list = 1; + } + elsif ($name eq "spoof" ) + { + $opt_spoof = $val; + } + elsif ($name eq "timeout" ) + { + $opt_timeout = $val; + } + + # verbose= + elsif ($name eq "verbose" ) + { + $opt_verbose = 1; + } + } +} + diff --git a/lib/deprec/templates/apache/httpd-vhost-app.conf.erb b/lib/deprec/templates/apache/httpd-vhost-app.conf.erb new file mode 100644 index 0000000..0207521 --- /dev/null +++ b/lib/deprec/templates/apache/httpd-vhost-app.conf.erb @@ -0,0 +1,144 @@ +:80> + ServerName <%= apache_server_name %> + <% apache_server_aliases.each do |a| %> + ServerAlias <%= "#{a}" %> + <% end %> + + DocumentRoot <%= "#{current_path}/public" %> + + > + Options FollowSymLinks + AllowOverride None + Order allow,deny + Allow from all + + + # Configure mongrel_cluster + > + <% start_port = apache_proxy_port %> + <% end_port = apache_proxy_port + apache_proxy_servers - 1 %> + <% start_port.upto(end_port) do |port| %> + BalancerMember http://<%= "#{apache_proxy_address}:#{port.to_s}" %> + <% end %> + + + RewriteEngine On + + <% if apache_ssl_enabled && apache_ssl_forward_all %> + RewriteRule ^(.*)$ https://<%= domain %>$1 + <% end %> + + # Prevent access to .svn directories + RewriteRule ^(.*/)?\.svn/ - [F,L] + ErrorDocument 403 "Access Forbidden" + + # Check for maintenance file and redirect all requests + RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$ + RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f + RewriteCond %{SCRIPT_FILENAME} !maintenance.html + RewriteRule ^.*$ /system/maintenance.html [L] + + # Rewrite index to check for static + RewriteRule ^/$ /index.html [QSA] + + # Rewrite to check for Rails cached page + RewriteRule ^([^.]+)$ $1.html [QSA] + + # Redirect all non-static requests to cluster + RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f + RewriteRule ^/(.*)$ balancer://<%= "#{application}_cluster" %>%{REQUEST_URI} [P,QSA,L] + + # Deflate + AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript + BrowserMatch ^Mozilla/4 gzip-only-text/html + BrowserMatch ^Mozilla/4\.0[678] no-gzip + BrowserMatch \bMSIE !no-gzip !gzip-only-text/html + + ErrorLog logs/<%= domain %>-error_log + CustomLog logs/<%= domain %>-access_log combined + + + +<% if apache_ssl_enabled %> +:443> + +ServerName <%= apache_server_name %> +<% apache_server_aliases.each do |a| %> +ServerAlias <%= "#{a}" %> +<% end %> +DocumentRoot <%= "#{current_path}/public" %> + +> + Options FollowSymLinks + AllowOverride None + Order allow,deny + Allow from all + + +# Configure mongrel_cluster +> + <% start_port = apache_proxy_port %> + <% end_port = apache_proxy_port + apache_proxy_servers - 1 %> + <% start_port.upto(end_port) do |port| %> + BalancerMember http://<%= "#{apache_proxy_address}:#{port.to_s}" %> + <% end %> + + +RewriteEngine On + +# Prevent access to .svn directories +RewriteRule ^(.*/)?\.svn/ - [F,L] +ErrorDocument 403 "Access Forbidden" + +# Check for maintenance file and redirect all requests +RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$ +RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f +RewriteCond %{SCRIPT_FILENAME} !maintenance.html +RewriteRule ^.*$ /system/maintenance.html [L] + +# Rewrite index to check for static +RewriteRule ^/$ /index.html [QSA] + +# Rewrite to check for Rails cached page +RewriteRule ^([^.]+)$ $1.html [QSA] + +# Redirect all non-static requests to cluster +RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f +# Add header for Mongrel to set HTTPS environment for Rails +RequestHeader set X-Forwarded-Proto "https" +RewriteRule ^/(.*)$ balancer://<%= "#{application}_cluster" %>%{REQUEST_URI} [P,QSA,L] + +# Deflate +AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript +BrowserMatch ^Mozilla/4 gzip-only-text/html +BrowserMatch ^Mozilla/4\.0[678] no-gzip +BrowserMatch \bMSIE !no-gzip !gzip-only-text/html + +# SSL Engine Switch +SSLEngine on + +# SSL Cipher Suite: +SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL + +# Server Certificate +SSLCertificateFile /usr/local/apache2/conf/ssl.crt/<%= domain %>.crt + +# Server Private Key +SSLCertificateKeyFile /usr/local/apache2/conf/ssl.key/<%= domain %>.key + +<% if apache_ssl_chainfile %> +# Intermediate keys +SSLCertificateChainFile /usr/local/apache2/conf/ssl.crt/<%= domain %>-chainfile.crt +<% end %> + + +BrowserMatch ".*MSIE.*" \ + nokeepalive ssl-unclean-shutdown \ + downgrade-1.0 force-response-1.0 + +ErrorLog logs/<%= domain %>-error_log +CustomLog logs/<%= domain %>-access_log combined +CustomLog logs/<%= domain %>-ssl_log \ + "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" + +<% end %> \ No newline at end of file diff --git a/lib/deprec/templates/apache/httpd.conf b/lib/deprec/templates/apache/httpd.conf new file mode 100644 index 0000000..b2ceba6 --- /dev/null +++ b/lib/deprec/templates/apache/httpd.conf @@ -0,0 +1,465 @@ +# +# This is the main Apache HTTP server configuration file. It contains the +# configuration directives that give the server its instructions. +# See for detailed information. +# In particular, see +# +# for a discussion of each configuration directive. +# +# Do NOT simply read the instructions in here without understanding +# what they do. They're here only as hints or reminders. If you are unsure +# consult the online docs. You have been warned. +# +# Configuration and logfile names: If the filenames you specify for many +# of the server's control files begin with "/" (or "drive:/" for Win32), the +# server will use that explicit path. If the filenames do *not* begin +# with "/", the value of ServerRoot is prepended -- so "logs/foo.log" +# with ServerRoot set to "/usr/local/apache2" will be interpreted by the +# server as "/usr/local/apache2/logs/foo.log". + +# +# ServerRoot: The top of the directory tree under which the server's +# configuration, error, and log files are kept. +# +# Do not add a slash at the end of the directory path. If you point +# ServerRoot at a non-local disk, be sure to point the LockFile directive +# at a local disk. If you wish to share the same ServerRoot for multiple +# httpd daemons, you will need to change at least LockFile and PidFile. +# +ServerRoot "/usr/local/apache2" + +# +# Listen: Allows you to bind Apache to specific IP addresses and/or +# ports, instead of the default. See also the +# directive. +# +# Change this to Listen on specific IP addresses as shown below to +# prevent Apache from glomming onto all bound IP addresses. +# +#Listen 12.34.56.78:80 +Listen 80 + +# +# Dynamic Shared Object (DSO) Support +# +# To be able to use the functionality of a module which was built as a DSO you +# have to place corresponding `LoadModule' lines at this location so the +# directives contained in it are actually available _before_ they are used. +# Statically compiled modules (those listed by `httpd -l') do not need +# to be loaded here. +# +# Example: +# LoadModule foo_module modules/mod_foo.so +# +LoadModule authn_file_module modules/mod_authn_file.so +LoadModule authn_dbm_module modules/mod_authn_dbm.so +LoadModule authn_anon_module modules/mod_authn_anon.so +LoadModule authn_dbd_module modules/mod_authn_dbd.so +LoadModule authn_default_module modules/mod_authn_default.so +LoadModule authz_host_module modules/mod_authz_host.so +LoadModule authz_groupfile_module modules/mod_authz_groupfile.so +LoadModule authz_user_module modules/mod_authz_user.so +LoadModule authz_dbm_module modules/mod_authz_dbm.so +LoadModule authz_owner_module modules/mod_authz_owner.so +LoadModule authz_default_module modules/mod_authz_default.so +LoadModule auth_basic_module modules/mod_auth_basic.so +LoadModule auth_digest_module modules/mod_auth_digest.so +LoadModule cache_module modules/mod_cache.so +LoadModule dbd_module modules/mod_dbd.so +LoadModule dumpio_module modules/mod_dumpio.so +LoadModule ext_filter_module modules/mod_ext_filter.so +LoadModule include_module modules/mod_include.so +LoadModule filter_module modules/mod_filter.so +LoadModule deflate_module modules/mod_deflate.so +LoadModule log_config_module modules/mod_log_config.so +LoadModule log_forensic_module modules/mod_log_forensic.so +LoadModule logio_module modules/mod_logio.so +LoadModule env_module modules/mod_env.so +LoadModule mime_magic_module modules/mod_mime_magic.so +LoadModule cern_meta_module modules/mod_cern_meta.so +LoadModule expires_module modules/mod_expires.so +LoadModule headers_module modules/mod_headers.so +LoadModule ident_module modules/mod_ident.so +LoadModule usertrack_module modules/mod_usertrack.so +LoadModule unique_id_module modules/mod_unique_id.so +LoadModule setenvif_module modules/mod_setenvif.so +LoadModule version_module modules/mod_version.so +LoadModule proxy_module modules/mod_proxy.so +LoadModule proxy_connect_module modules/mod_proxy_connect.so +LoadModule proxy_ftp_module modules/mod_proxy_ftp.so +LoadModule proxy_http_module modules/mod_proxy_http.so +LoadModule proxy_ajp_module modules/mod_proxy_ajp.so +LoadModule proxy_balancer_module modules/mod_proxy_balancer.so +LoadModule ssl_module modules/mod_ssl.so +LoadModule mime_module modules/mod_mime.so +LoadModule dav_module modules/mod_dav.so +LoadModule status_module modules/mod_status.so +LoadModule autoindex_module modules/mod_autoindex.so +LoadModule asis_module modules/mod_asis.so +LoadModule info_module modules/mod_info.so +LoadModule cgi_module modules/mod_cgi.so +LoadModule dav_fs_module modules/mod_dav_fs.so +LoadModule vhost_alias_module modules/mod_vhost_alias.so +LoadModule negotiation_module modules/mod_negotiation.so +LoadModule dir_module modules/mod_dir.so +LoadModule imagemap_module modules/mod_imagemap.so +LoadModule actions_module modules/mod_actions.so +LoadModule speling_module modules/mod_speling.so +LoadModule userdir_module modules/mod_userdir.so +LoadModule alias_module modules/mod_alias.so +LoadModule rewrite_module modules/mod_rewrite.so + + +# +# If you wish httpd to run as a different user or group, you must run +# httpd as root initially and it will switch. +# +# User/Group: The name (or #number) of the user/group to run httpd as. +# It is usually good practice to create a dedicated user and group for +# running httpd, as with most system services. +# +User daemon +Group daemon + + +# 'Main' server configuration +# +# The directives in this section set up the values used by the 'main' +# server, which responds to any requests that aren't handled by a +# definition. These values also provide defaults for +# any containers you may define later in the file. +# +# All of these directives may appear inside containers, +# in which case these default settings will be overridden for the +# virtual host being defined. +# + +# +# ServerAdmin: Your address, where problems with the server should be +# e-mailed. This address appears on some server-generated pages, such +# as error documents. e.g. admin@your-domain.com +# +ServerAdmin you@example.com + +# +# ServerName gives the name and port that the server uses to identify itself. +# This can often be determined automatically, but we recommend you specify +# it explicitly to prevent problems during startup. +# +# If your host doesn't have a registered DNS name, enter its IP address here. +# +#ServerName www.example.com:80 + +# +# DocumentRoot: The directory out of which you will serve your +# documents. By default, all requests are taken from this directory, but +# symbolic links and aliases may be used to point to other locations. +# +DocumentRoot "/usr/local/apache2/htdocs" + +# +# Each directory to which Apache has access can be configured with respect +# to which services and features are allowed and/or disabled in that +# directory (and its subdirectories). +# +# First, we configure the "default" to be a very restrictive set of +# features. +# + + Options FollowSymLinks + AllowOverride None + Order deny,allow + Deny from all + + +# +# Note that from this point forward you must specifically allow +# particular features to be enabled - so if something's not working as +# you might expect, make sure that you have specifically enabled it +# below. +# + +# +# This should be changed to whatever you set DocumentRoot to. +# + + # + # Possible values for the Options directive are "None", "All", + # or any combination of: + # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews + # + # Note that "MultiViews" must be named *explicitly* --- "Options All" + # doesn't give it to you. + # + # The Options directive is both complicated and important. Please see + # http://httpd.apache.org/docs/2.2/mod/core.html#options + # for more information. + # + Options Indexes FollowSymLinks + + # + # AllowOverride controls what directives may be placed in .htaccess files. + # It can be "All", "None", or any combination of the keywords: + # Options FileInfo AuthConfig Limit + # + AllowOverride None + + # + # Controls who can get stuff from this server. + # + Order allow,deny + Allow from all + + + +# +# DirectoryIndex: sets the file that Apache will serve if a directory +# is requested. +# + + DirectoryIndex index.html + + +# +# The following lines prevent .htaccess and .htpasswd files from being +# viewed by Web clients. +# + + Order allow,deny + Deny from all + Satisfy All + + +# +# ErrorLog: The location of the error log file. +# If you do not specify an ErrorLog directive within a +# container, error messages relating to that virtual host will be +# logged here. If you *do* define an error logfile for a +# container, that host's errors will be logged there and not here. +# +ErrorLog logs/error_log + +# +# LogLevel: Control the number of messages logged to the error_log. +# Possible values include: debug, info, notice, warn, error, crit, +# alert, emerg. +# +LogLevel warn + + + # + # The following directives define some format nicknames for use with + # a CustomLog directive (see below). + # + LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined + LogFormat "%h %l %u %t \"%r\" %>s %b" common + + + # You need to enable mod_logio.c to use %I and %O + LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio + + + # + # The location and format of the access logfile (Common Logfile Format). + # If you do not define any access logfiles within a + # container, they will be logged here. Contrariwise, if you *do* + # define per- access logfiles, transactions will be + # logged therein and *not* in this file. + # + CustomLog logs/access_log common + + # + # If you prefer a logfile with access, agent, and referer information + # (Combined Logfile Format) you can use the following directive. + # + #CustomLog logs/access_log combined + + + + # + # Redirect: Allows you to tell clients about documents that used to + # exist in your server's namespace, but do not anymore. The client + # will make a new request for the document at its new location. + # Example: + # Redirect permanent /foo http://www.example.com/bar + + # + # Alias: Maps web paths into filesystem paths and is used to + # access content that does not live under the DocumentRoot. + # Example: + # Alias /webpath /full/filesystem/path + # + # If you include a trailing / on /webpath then the server will + # require it to be present in the URL. You will also likely + # need to provide a section to allow access to + # the filesystem path. + + # + # ScriptAlias: This controls which directories contain server scripts. + # ScriptAliases are essentially the same as Aliases, except that + # documents in the target directory are treated as applications and + # run by the server when requested rather than as documents sent to the + # client. The same rules about trailing "/" apply to ScriptAlias + # directives as to Alias. + # + ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/" + + + + + # + # ScriptSock: On threaded servers, designate the path to the UNIX + # socket used to communicate with the CGI daemon of mod_cgid. + # + #Scriptsock logs/cgisock + + +# +# "/usr/local/apache2/cgi-bin" should be changed to whatever your ScriptAliased +# CGI directory exists, if you have that configured. +# + + AllowOverride None + Options None + Order allow,deny + Allow from all + + +# +# DefaultType: the default MIME type the server will use for a document +# if it cannot otherwise determine one, such as from filename extensions. +# If your server contains mostly text or HTML documents, "text/plain" is +# a good value. If most of your content is binary, such as applications +# or images, you may want to use "application/octet-stream" instead to +# keep browsers from trying to display binary files as though they are +# text. +# +DefaultType text/plain + + + # + # TypesConfig points to the file containing the list of mappings from + # filename extension to MIME-type. + # + TypesConfig conf/mime.types + + # + # AddType allows you to add to or override the MIME configuration + # file specified in TypesConfig for specific file types. + # + #AddType application/x-gzip .tgz + # + # AddEncoding allows you to have certain browsers uncompress + # information on the fly. Note: Not all browsers support this. + # + #AddEncoding x-compress .Z + #AddEncoding x-gzip .gz .tgz + # + # If the AddEncoding directives above are commented-out, then you + # probably should define those extensions to indicate media types: + # + AddType application/x-compress .Z + AddType application/x-gzip .gz .tgz + + # + # AddHandler allows you to map certain file extensions to "handlers": + # actions unrelated to filetype. These can be either built into the server + # or added with the Action directive (see below) + # + # To use CGI scripts outside of ScriptAliased directories: + # (You will also need to add "ExecCGI" to the "Options" directive.) + # + #AddHandler cgi-script .cgi + + # For type maps (negotiated resources): + #AddHandler type-map var + + # + # Filters allow you to process content before it is sent to the client. + # + # To parse .shtml files for server-side includes (SSI): + # (You will also need to add "Includes" to the "Options" directive.) + # + #AddType text/html .shtml + #AddOutputFilter INCLUDES .shtml + + +# +# The mod_mime_magic module allows the server to use various hints from the +# contents of the file itself to determine its type. The MIMEMagicFile +# directive tells the module where the hint definitions are located. +# +#MIMEMagicFile conf/magic + +# +# Customizable error responses come in three flavors: +# 1) plain text 2) local redirects 3) external redirects +# +# Some examples: +#ErrorDocument 500 "The server made a boo boo." +#ErrorDocument 404 /missing.html +#ErrorDocument 404 "/cgi-bin/missing_handler.pl" +#ErrorDocument 402 http://www.example.com/subscription_info.html +# + +# +# EnableMMAP and EnableSendfile: On systems that support it, +# memory-mapping or the sendfile syscall is used to deliver +# files. This usually improves server performance, but must +# be turned off when serving from networked-mounted +# filesystems or if support for these functions is otherwise +# broken on your system. +# +#EnableMMAP off +#EnableSendfile off + +# Supplemental configuration +# +# The configuration files in the conf/extra/ directory can be +# included to add extra features or to modify the default configuration of +# the server, or you may simply copy their contents here and change as +# necessary. + +# Server-pool management (MPM specific) +#Include conf/extra/httpd-mpm.conf + +# Multi-language error messages +#Include conf/extra/httpd-multilang-errordoc.conf + +# Fancy directory listings +#Include conf/extra/httpd-autoindex.conf + +# Language settings +#Include conf/extra/httpd-languages.conf + +# User home directories +#Include conf/extra/httpd-userdir.conf + +# Real-time info on requests and configuration +#Include conf/extra/httpd-info.conf + +# Virtual hosts +#Include conf/extra/httpd-vhosts.conf + +# Local access to the Apache HTTP Server Manual +#Include conf/extra/httpd-manual.conf + +# Distributed authoring and versioning (WebDAV) +#Include conf/extra/httpd-dav.conf + +# Various default settings +#Include conf/extra/httpd-default.conf + +# Secure (SSL/TLS) connections +#Include conf/extra/httpd-ssl.conf +# +# Note: The following must must be present to support +# starting without SSL on platforms with no /dev/random equivalent +# but a statically compiled-in mod_ssl. +# + +SSLRandomSeed startup builtin +SSLRandomSeed connect builtin + +Include conf/apps/ +NameVirtualHost *:80 diff --git a/lib/deprec/templates/apache/index.html.erb b/lib/deprec/templates/apache/index.html.erb new file mode 100644 index 0000000..9a0d125 --- /dev/null +++ b/lib/deprec/templates/apache/index.html.erb @@ -0,0 +1,37 @@ + + + + + Apache2 installed by deprec + + + + +
+

Apache2 installed by deprec

+

Commands

+
+
cap deprec:apache:start
Start apache
+
cap deprec:apache:stop
Stop apache
+
cap deprec:apache:restart
Stop restart
+
cap deprec:apache:reload
Reload apache
+ +
cap deprec:apache:install
Install apache
+
cap deprec:apache:config_gen
Generate apache configs
+ +
cap deprec:apache:activate
Start Apache when server boots
+
cap deprec:apache:deactivate
Don't start Apache when server boots
+ +
+ +
+

Installation options

+ <% SRC_PACKAGES[:apache].each do |key, val| %> +
<%= key %>
+
<%= val %>
+ <% end %> +
+
+ + \ No newline at end of file diff --git a/lib/deprec/templates/apache/master.css b/lib/deprec/templates/apache/master.css new file mode 100644 index 0000000..e7d8753 --- /dev/null +++ b/lib/deprec/templates/apache/master.css @@ -0,0 +1,72 @@ +/*----------------------------------------------------------------------------- +Basic Stylesheet + +version: 1 +author: Mike Bailey +email: mike@bailey.net.au +website: http://mike.bailey.net.au/ +-----------------------------------------------------------------------------*/ + +/* General stuff *************************************************************/ + +* { + padding:0; + margin: 0; + font-family: sans-serif; +} + +body { + text-align: center; + min-width: 760; +} + +.clear { + clear: both; +} + +h1 { + padding: 0.5em; +} + +dl { + border: 1px solid red; + padding: 1em; +} + +dl p { + font-size: 1.5em; + padding: .5em 0; +} + +dt { + padding: 0 0 0 1em; +} + +dd { + padding: 0 0 1em 2em; + color: darkblue; +} + + +/* Layout ********************************************************************/ + +#wrapper { + width: 720px; + background: #d0d0d0; + margin: 0 auto; + text-align: left; +} + + +/* Navigation links **********************************************************/ + +ul#navlinks { + width: 720px; + list-style: none; + background: #FAA819; + float: left; +} + +ul li { + float:left; +} \ No newline at end of file diff --git a/lib/deprec/templates/centos/repository.erb b/lib/deprec/templates/centos/repository.erb new file mode 100644 index 0000000..59fc62b --- /dev/null +++ b/lib/deprec/templates/centos/repository.erb @@ -0,0 +1,6 @@ +[<%= options[:repository][:code] %>] +name=<%= options[:repository][:name] %> +baseurl=<%= options[:repository][:baseurl] %> +enabled=<%= options[:repository][:enabled] %> +gpgcheck=<%= options[:repository][:gpgcheck] %> +gpgkey=<%= options[:repository][:gpgkey] %> diff --git a/lib/deprec/templates/coraid/aoe-init b/lib/deprec/templates/coraid/aoe-init new file mode 100644 index 0000000..6c25cc9 --- /dev/null +++ b/lib/deprec/templates/coraid/aoe-init @@ -0,0 +1,55 @@ +#! /bin/sh +# aoe-init - example init script for ATA over Ethernet storage +# +# Edit this script for your purposes. (Changing "eth1" to the +# appropriate interface name, adding commands, etc.) You might +# need to tune the sleep times. +# +# Install this script in /etc/init.d with the other init scripts. +# +# Make it executable: +# chmod 755 /etc/init.d/aoe-init +# +# Install symlinks for boot time: +# cd /etc/rc3.d && ln -s ../init.d/aoe-init S99aoe-init +# cd /etc/rc5.d && ln -s ../init.d/aoe-init S99aoe-init +# +# Install symlinks for shutdown time: +# cd /etc/rc0.d && ln -s ../init.d/aoe-init K01aoe-init +# cd /etc/rc1.d && ln -s ../init.d/aoe-init K01aoe-init +# cd /etc/rc2.d && ln -s ../init.d/aoe-init K01aoe-init +# cd /etc/rc6.d && ln -s ../init.d/aoe-init K01aoe-init +# + +case "$1" in + "start") + # load any needed network drivers here + + # replace "eth1" with your aoe network interface + ifconfig eth1 up + + # time for network interface to come up + sleep 4 + + modprobe aoe + + # time for AoE discovery and udev + sleep 7 + + # add your raid assemble commands here + # add any LVM commands if needed (e.g. vgchange) + # add your filesystem mount commands here + + test -d /var/lock/subsys && touch /var/lock/subsys/aoe-init + ;; + "stop") + # add your filesystem umount commands here + # deactivate LVM volume groups if needed + # add your raid stop commands here + rmmod aoe + rm -f /var/lock/subsys/aoe-init + ;; + *) + echo "usage: `basename $0` {start|stop}" 1>&2 + ;; +esac \ No newline at end of file diff --git a/lib/deprec/templates/deprec/caprc.erb b/lib/deprec/templates/deprec/caprc.erb new file mode 100644 index 0000000..e8f76fe --- /dev/null +++ b/lib/deprec/templates/deprec/caprc.erb @@ -0,0 +1,14 @@ +ssh_options[:paranoid] = false +ssh_options[:forward_agent] = true + + +# Just import the general purpose tasks +require '/deprec/general_purpose' if respond_to?(:namespace) + +# Enable all deprec tasks all the time. This will change the +# behviour of some standard cap tasks (like 'cap deploy') so +# only enable it if you know what you're doing! +# +# require 'deprec/recipes' unless respond_to?(:namespace) + + diff --git a/lib/deprec/templates/heartbeat/authkeys.erb b/lib/deprec/templates/heartbeat/authkeys.erb new file mode 100644 index 0000000..9be6dd4 --- /dev/null +++ b/lib/deprec/templates/heartbeat/authkeys.erb @@ -0,0 +1,2 @@ +auth 1 +1 sha1 <%= heartbeat_auth_key %> \ No newline at end of file diff --git a/lib/deprec/templates/heartbeat/ha.cf.erb b/lib/deprec/templates/heartbeat/ha.cf.erb new file mode 100644 index 0000000..2a03fcb --- /dev/null +++ b/lib/deprec/templates/heartbeat/ha.cf.erb @@ -0,0 +1,15 @@ +# http://linux-ha.org/ha.cf +logfacility daemon +keepalive 1 +deadtime 10 +warntime 5 +initdead 120 # depend on your hardware +udpport 694 +ping <%= heartbeat_ping %> +bcast <%= heartbeat_bcast %> +auto_failback <%= heartbeat_auto_failback %> +<% heartbeat_nodes.each do |node| -%> +node <%= node %> +<% end -%> +respawn hacluster /usr/lib/heartbeat/ipfail +use_logd yes \ No newline at end of file diff --git a/lib/deprec/templates/heartbeat/haresources.erb b/lib/deprec/templates/heartbeat/haresources.erb new file mode 100644 index 0000000..c45928e --- /dev/null +++ b/lib/deprec/templates/heartbeat/haresources.erb @@ -0,0 +1 @@ +<%= heartbeat_preferred_node %> <%= heartbeat_resources %> \ No newline at end of file diff --git a/lib/deprec/templates/mongrel/mongrel_cluster-init-script b/lib/deprec/templates/mongrel/mongrel_cluster-init-script new file mode 100644 index 0000000..f595cc3 --- /dev/null +++ b/lib/deprec/templates/mongrel/mongrel_cluster-init-script @@ -0,0 +1,54 @@ +#!/bin/bash +# +# Copyright (c) 2007 Bradley Taylor, bradley@railsmachine.com +# +# mongrel_cluster Startup script for Mongrel clusters. +# +# chkconfig: - 85 15 +# description: mongrel_cluster manages multiple Mongrel processes for use \ +# behind a load balancer. +# + +PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local:/usr/local/sbin:/usr/local/bin +CONF_DIR=/etc/mongrel_cluster +PID_DIR=/var/run/mongrel_cluster +# USER=mongrel + +EVENT=1 + +RETVAL=0 + +# Gracefully exit if the controller is missing. +which mongrel_cluster_ctl >/dev/null || exit 0 + +# Go no further if config directory is missing. +[ -d "$CONF_DIR" ] || exit 0 + +case "$1" in + start) + # Create pid directory + mkdir -p $PID_DIR + # chown $USER:$USER $PID_DIR + + mongrel_cluster_ctl start -c $CONF_DIR + RETVAL=$? + ;; + stop) + mongrel_cluster_ctl stop -c $CONF_DIR + RETVAL=$? + ;; + restart) + mongrel_cluster_ctl restart -c $CONF_DIR + RETVAL=$? + ;; + status) + mongrel_cluster_ctl status -c $CONF_DIR + RETVAL=$? + ;; + *) + echo "Usage: mongrel_cluster {start|stop|restart|status}" + exit 1 + ;; +esac + +exit $RETVAL diff --git a/lib/deprec/templates/mongrel/mongrel_cluster.logrotate.d b/lib/deprec/templates/mongrel/mongrel_cluster.logrotate.d new file mode 100644 index 0000000..79587a0 --- /dev/null +++ b/lib/deprec/templates/mongrel/mongrel_cluster.logrotate.d @@ -0,0 +1,14 @@ +/var/log/mongrel/<%= application %>/*.log { + daily + missingok + rotate 28 + compress + notifempty + sharedscripts + extension gz + postrotate + for i in `ls /data/<%= @username %>/shared/log/*.pid`; do + kill -USR2 `cat $i` + done + endscript +} \ No newline at end of file diff --git a/lib/deprec/templates/mongrel/mongrel_cluster.yml.erb b/lib/deprec/templates/mongrel/mongrel_cluster.yml.erb new file mode 100644 index 0000000..8637e02 --- /dev/null +++ b/lib/deprec/templates/mongrel/mongrel_cluster.yml.erb @@ -0,0 +1,10 @@ +--- +user: <%= mongrel_user %> +group: <%= mongrel_group %> +cwd: <%= current_path %> +log_file: <%= mongrel_log_dir %>/mongrel.log +port: "<%= mongrel_port.to_s %>" +environment: <%= mongrel_environment %> +address: <%= mongrel_address %> +pid_file: <%= mongrel_pid_dir %>/mongrel.pid +servers: <%= mongrel_servers.to_s %> \ No newline at end of file diff --git a/lib/deprec/templates/monit/monit-init-script b/lib/deprec/templates/monit/monit-init-script new file mode 100644 index 0000000..acec23c --- /dev/null +++ b/lib/deprec/templates/monit/monit-init-script @@ -0,0 +1,104 @@ +#!/bin/sh +# /etc/init.d/monit start and stop monit daemon monitor process. +# Fredrik Steen, stone@debian.org +: +PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +DAEMON=/usr/local/bin/monit +CONFIG="/etc/monitrc" +NAME=monit +DESC="daemon monitor" + +set -e + +# Check if DAEMON binary exist +test -f $DAEMON || exit 0 + +ARGS="-c $CONFIG" + +monit_not_configured () { + echo -e "monit won't be started/stopped\n\tunless it it's configured" + if [ "$1" != "stop" ] + then + echo -e "\tplease configure monit and then edit /etc/default/monit" + echo -e "\tand set the \"startup\" variable to 1 in order to allow " + echo -e "\tmonit to start" + fi + exit 0 +} + +monit_check_config () { + # Check for emtpy config, probably default configfile. + if [ "`grep -s -v \"^#\" $CONFIG`" = "" ]; then + echo "empty config, please edit $CONFIG." + exit 0 + fi +} + +monit_check_perms () { + # Check the permission on configfile. + # The permission must not have more than -rwx------ (0700) permissions. + + # Skip checking, fix perms instead. + /bin/chmod go-rwx $CONFIG + +} + +monit_delayed_monitoring () { + if [ -x $DELAY ]; then + $DELAY & + elif [ -f $DELAY ]; then + echo + echo "[WARNING] A delayed start file exists ($DELAY) but it is not executable." + fi +} + +monit_check_syntax () { + $DAEMON -t; +# if [ $? ] ; then +# echo "syntax good" +# else +# echo "syntax bad" +# fi +} + + +monit_checks () { + # Check for emtpy configfile + monit_check_config + # Check permissions of configfile + monit_check_perms +} + +case "$1" in + start) + echo -n "Starting $DESC: " + monit_checks $1 + echo -n "$NAME" + start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \ + --exec $DAEMON > /dev/null 2>&1 -- $ARGS + monit_delayed_monitoring + echo "." + ;; + stop) + echo -n "Stopping $DESC: " + #monit_checks $1 + echo -n "$NAME" + start-stop-daemon --retry 5 --oknodo --stop --quiet --pidfile /var/run/$NAME.pid \ + --exec $DAEMON > /dev/null 2>&1 + echo "." + ;; + restart|force-reload) + $0 stop + $0 start + ;; + syntax) + monit_check_syntax + ;; + *) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|restart|force-reload|syntax}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/lib/deprec/templates/monit/monit_mongrel.erb b/lib/deprec/templates/monit/monit_mongrel.erb new file mode 100644 index 0000000..d0309bb --- /dev/null +++ b/lib/deprec/templates/monit/monit_mongrel.erb @@ -0,0 +1,17 @@ +<% mongrel_servers.times do |counter| -%> + check process mongrel-<%=mongrel_port+counter%> with pidfile <%= mongrel_pid_dir %>/mongrel.<%=mongrel_port+counter%>.pid + group mongrel + start program = "/usr/local/bin/ruby /usr/local/bin/mongrel_rails start -d -e production -a 127.0.0.1 -c <%= deploy_to %>/current --user <%= mongrel_user %> --group <%= mongrel_group %> -p <%=mongrel_port+counter%> -P <%= mongrel_pid_dir %>/mongrel.<%=mongrel_port+counter%>.pid -l <%= mongrel_log_dir %>/mongrel.<%=mongrel_port+counter%>.log" + stop program = "/usr/local/bin/ruby /usr/local/bin/mongrel_rails stop -P <%= mongrel_pid_dir %>/mongrel.<%=mongrel_port+counter%>.pid" + + if failed host 127.0.0.1 port <%=mongrel_port+counter%> protocol http + with timeout 10 seconds + then alert + + if totalmem > 100 Mb then restart + if cpu > 60% for 2 cycles then alert + if cpu > 80% for 5 cycles then restart + if loadavg(5min) > 10 for 8 cycles then restart + if 3 restarts within 5 cycles then timeout + +<% end -%> diff --git a/lib/deprec/templates/monit/monitrc.erb b/lib/deprec/templates/monit/monitrc.erb new file mode 100644 index 0000000..8e19f92 --- /dev/null +++ b/lib/deprec/templates/monit/monitrc.erb @@ -0,0 +1,227 @@ +############################################################################### +## Monit control file +############################################################################### +## +## Comments begin with a '#' and extend through the end of the line. Keywords +## are case insensitive. All path's MUST BE FULLY QUALIFIED, starting with '/'. +## +## Below you will find examples of some frequently used statements. For +## information about the control file, a complete list of statements and +## options please have a look in the monit manual. +## +## +############################################################################### +## Global section +############################################################################### +## +## Start monit in the background (run as a daemon) and check services at +## 2-minute intervals. +# +set daemon <%= monit_check_interval %> +# +# +## Set syslog logging with the 'daemon' facility. If the FACILITY option is +## omitted, monit will use 'user' facility by default. If you want to log to +## a stand alone log file instead, specify the path to a log file +# +set logfile <%= monit_log %> +# +# +## Set the list of mail servers for alert delivery. Multiple servers may be +## specified using comma separator. By default monit uses port 25 - this +## is possible to override with the PORT option. +# +<%= '# ' unless monit_mailserver %>set mailserver <%= monit_mailserver || 'localhost' %> # primary mailserver (append a comma +# # to this line if you add more.) +# backup.bar.baz port 10025, # backup mailserver on port 10025 +# localhost # fallback relay +# +# +## By default monit will drop alert events if no mail servers are available. +## If you want to keep the alerts for a later delivery retry, you can use the +## EVENTQUEUE statement. The base directory where undelivered alerts will be +## stored is specified by the BASEDIR option. You can limit the maximal queue +## size using the SLOTS option (if omitted, the queue is limited by space +## available in the back end filesystem). +# +# set eventqueue +# basedir /var/monit # set the base directory where events will be stored +# slots 100 # optionaly limit the queue size +# +# +## Monit by default uses the following alert mail format: +## +## --8<-- +## From: monit@$HOST # sender +## Subject: monit alert -- $EVENT $SERVICE # subject +## +## $EVENT Service $SERVICE # +## # +## Date: $DATE # +## Action: $ACTION # +## Host: $HOST # body +## Description: $DESCRIPTION # +## # +## Your faithful employee, # +## monit # +## --8<-- +## +## You can override this message format or parts of it, such as subject +## or sender using the MAIL-FORMAT statement. Macros such as $DATE, etc. +## are expanded at runtime. For example, to override the sender: +# +<%= '# ' unless monit_mailserver %>set mail-format { from: <%= monit_mail_from %> } +# +# +## You can set alert recipients here whom will receive alerts if/when a +## service defined in this file has errors. Alerts may be restricted on +## events by using a filter as in the second example below. +# +<% monit_alert_recipients.each do |recipient| %> +<%= '# ' unless monit_mailserver %>set alert <%= recipient %> # receive all alerts +<% end %> +<% monit_timeout_recipients.each do |recipient| %> +<%= '# ' unless monit_mailserver %>set alert <%= recipient %> only on { timeout } # receive just service- + # timeout alert +<% end %> + +# +# +## Monit has an embedded web server which can be used to view status of +## services monitored, the current configuration, actual services parameters +## and manage services from a web interface. +# +<% if monit_webserver_enabled %> +set httpd port <%= monit_webserver_port %> and + use address <%= monit_webserver_address %> # listen on <%= monit_webserver_address %> + <% monit_webserver_allowed_hosts_and_networks.each do |host| %> + allow <%= host %> # allow <%= host %> to connect to the server + <% end %> + allow <%= monit_webserver_auth_user %>:<%= monit_webserver_auth_pass %> # require user <%= monit_webserver_auth_user %> with password <%= monit_webserver_auth_pass %> +<% end %> +# +# +############################################################################### +## Services +############################################################################### +## +## Check general system resources such as load average, cpu and memory +## usage. Each test specifies a resource, conditions and the action to be +## performed should a test fail. +# +# check system myhost.mydomain.tld +# if loadavg (1min) > 4 then alert +# if loadavg (5min) > 2 then alert +# if memory usage > 75% then alert +# if cpu usage (user) > 70% then alert +# if cpu usage (system) > 30% then alert +# if cpu usage (wait) > 20% then alert +# +# +## Check a file for existence, checksum, permissions, uid and gid. In addition +## to alert recipients in the global section, customized alert will be sent to +## additional recipients by specifying a local alert handler. The service may +## be grouped using the GROUP option. +# +# check file apache_bin with path /usr/local/apache/bin/httpd +# if failed checksum and +# expect the sum 8f7f419955cefa0b33a2ba316cba3659 then unmonitor +# if failed permission 755 then unmonitor +# if failed uid root then unmonitor +# if failed gid root then unmonitor +# alert security@foo.bar on { +# checksum, permission, uid, gid, unmonitor +# } with the mail-format { subject: Alarm! } +# group server +# +# +## Check that a process is running, in this case Apache, and that it respond +## to HTTP and HTTPS requests. Check its resource usage such as cpu and memory, +## and number of children. If the process is not running, monit will restart +## it by default. In case the service was restarted very often and the +## problem remains, it is possible to disable monitoring using the TIMEOUT +## statement. This service depends on another service (apache_bin) which +## is defined above. +# +# check process apache with pidfile /usr/local/apache/logs/httpd.pid +# start program = "/etc/init.d/httpd start" +# stop program = "/etc/init.d/httpd stop" +# if cpu > 60% for 2 cycles then alert +# if cpu > 80% for 5 cycles then restart +# if totalmem > 200.0 MB for 5 cycles then restart +# if children > 250 then restart +# if loadavg(5min) greater than 10 for 8 cycles then stop +# if failed host www.tildeslash.com port 80 protocol http +# and request "/monit/doc/next.php" +# then restart +# if failed port 443 type tcpssl protocol http +# with timeout 15 seconds +# then restart +# if 3 restarts within 5 cycles then timeout +# depends on apache_bin +# group server +# +# +## Check device permissions, uid, gid, space and inode usage. Other services, +## such as databases, may depend on this resource and an automatically graceful +## stop may be cascaded to them before the filesystem will become full and data +## lost. +# +# check device datafs with path /dev/sdb1 +# start program = "/bin/mount /data" +# stop program = "/bin/umount /data" +# if failed permission 660 then unmonitor +# if failed uid root then unmonitor +# if failed gid disk then unmonitor +# if space usage > 80% for 5 times within 15 cycles then alert +# if space usage > 99% then stop +# if inode usage > 30000 then alert +# if inode usage > 99% then stop +# group server +# +# +## Check a file's timestamp. In this example, we test if a file is older +## than 15 minutes and assume something is wrong if its not updated. Also, +## if the file size exceed a given limit, execute a script +# +# check file database with path /data/mydatabase.db +# if failed permission 700 then alert +# if failed uid data then alert +# if failed gid data then alert +# if timestamp > 15 minutes then alert +# if size > 100 MB then exec "/my/cleanup/script" +# +# +## Check directory permission, uid and gid. An event is triggered if the +## directory does not belong to the user with uid 0 and gid 0. In addition, +## the permissions have to match the octal description of 755 (see chmod(1)). +# +# check directory bin with path /bin +# if failed permission 755 then unmonitor +# if failed uid 0 then unmonitor +# if failed gid 0 then unmonitor +# +# +## Check a remote host network services availability using a ping test and +## check response content from a web server. Up to three pings are sent and +## connection to a port and a application level network check is performed. +# +# check host myserver with address 192.168.1.1 +# if failed icmp type echo count 3 with timeout 3 seconds then alert +# if failed port 3306 protocol mysql with timeout 15 seconds then alert +# if failed url +# http://user:password@www.foo.bar:8080/?querystring +# and content == 'action="j_security_check"' +# then alert +# +# +############################################################################### +## Includes +############################################################################### +## +## It is possible to include additional configuration parts from other files or +## directories. +# +include /etc/monit.d/* +# +# diff --git a/lib/deprec/templates/monit/nothing b/lib/deprec/templates/monit/nothing new file mode 100644 index 0000000..e69de29 diff --git a/lib/deprec/templates/mysql/create_databases.sql b/lib/deprec/templates/mysql/create_databases.sql new file mode 100644 index 0000000..c4566e9 --- /dev/null +++ b/lib/deprec/templates/mysql/create_databases.sql @@ -0,0 +1,20 @@ +create database <%= @username %>_prod; +GRANT USAGE ON *.* TO '<%= @username %>_db'@'%'; + +GRANT ALL PRIVILEGES +ON <%= @username %>_prod.* +TO <%= @username %>_db@'%' +IDENTIFIED BY '<%= @mysqlpass %>'; + +FLUSH PRIVILEGES; + + +create database <%= @username %>_stage; +GRANT USAGE ON *.* TO '<%= @username %>_db'@'%'; + +GRANT ALL PRIVILEGES +ON <%= @username %>_stage.* +TO <%= @username %>_db@'%' +IDENTIFIED BY '<%= @mysqlpass %>'; + +FLUSH PRIVILEGES; diff --git a/lib/deprec/templates/mysql/database.yml.prod b/lib/deprec/templates/mysql/database.yml.prod new file mode 100644 index 0000000..9007aaa --- /dev/null +++ b/lib/deprec/templates/mysql/database.yml.prod @@ -0,0 +1,6 @@ +production: + adapter: mysql + database: <%= @username %>_prod + username: <%= @username %>_db + password: <%= @mysqlpass %> + host: <%= @mysql_host %> diff --git a/lib/deprec/templates/mysql/database.yml.stage b/lib/deprec/templates/mysql/database.yml.stage new file mode 100644 index 0000000..2f7e98e --- /dev/null +++ b/lib/deprec/templates/mysql/database.yml.stage @@ -0,0 +1,6 @@ +production: + adapter: mysql + database: <%= @username %>_stage + username: <%= @username %>_db + password: <%= @mysqlpass %> + host: <%= @mysql_host %> \ No newline at end of file diff --git a/lib/deprec/templates/mysql/my.cnf.erb b/lib/deprec/templates/mysql/my.cnf.erb new file mode 100644 index 0000000..72b71c0 --- /dev/null +++ b/lib/deprec/templates/mysql/my.cnf.erb @@ -0,0 +1,140 @@ +# +# The MySQL database server configuration file. +# +# You can copy this to one of: +# - "/etc/mysql/my.cnf" to set global options, +# - "~/.my.cnf" to set user-specific options. +# +# One can use all long options that the program supports. +# Run program with --help to get a list of available options and with +# --print-defaults to see which it would actually understand and use. +# +# For explanations see +# http://dev.mysql.com/doc/mysql/en/server-system-variables.html + +# This will be passed to all mysql clients +# It has been reported that passwords should be enclosed with ticks/quotes +# escpecially if they contain "#" chars... +# Remember to edit /etc/mysql/debian.cnf when changing the socket location. +[client] +port = 3306 +socket = /var/run/mysqld/mysqld.sock + +# Here is entries for some specific programs +# The following values assume you have at least 32M ram + +# This was formally known as [safe_mysqld]. Both versions are currently parsed. +[mysqld_safe] +socket = /var/run/mysqld/mysqld.sock +nice = 0 + +[mysqld] +# +# * Basic Settings +# +user = mysql +pid-file = /var/run/mysqld/mysqld.pid +socket = /var/run/mysqld/mysqld.sock +port = 3306 +basedir = /usr +datadir = /var/lib/mysql +tmpdir = /tmp +language = /usr/share/mysql/english +skip-external-locking +# +# Instead of skip-networking the default is now to listen only on +# localhost which is more compatible and is not less secure. +bind-address = 127.0.0.1 +# +# * Fine Tuning +# +key_buffer = 16M +max_allowed_packet = 16M +thread_stack = 128K +thread_cache_size = 8 +#max_connections = 100 +#table_cache = 64 +#thread_concurrency = 10 +# +# * Query Cache Configuration +# +query_cache_limit = 1M +query_cache_size = 16M +# +# * Logging and Replication +# +# Both location gets rotated by the cronjob. +# Be aware that this log type is a performance killer. +#log = /var/log/mysql/mysql.log +# +# Error logging goes to syslog. This is a Debian improvement :) +# +# Here you can see queries with especially long duration +#log_slow_queries = /var/log/mysql/mysql-slow.log +#long_query_time = 2 +#log-queries-not-using-indexes +# +# The following can be used as easy to replay backup logs or for replication. +# note: if you are setting up a replication slave, see README.Debian about +# other settings you may need to change. +#server-id = 1 +log_bin = /var/log/mysql/mysql-bin.log +# WARNING: Using expire_logs_days without bin_log crashes the server! See README.Debian! +expire_logs_days = 10 +max_binlog_size = 100M +#binlog_do_db = include_database_name +#binlog_ignore_db = include_database_name +# +# * BerkeleyDB +# +# Using BerkeleyDB is now discouraged as its support will cease in 5.1.12. +skip-bdb +# +# * InnoDB +# +# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. +# Read the manual for more InnoDB related options. There are many! +# You might want to disable InnoDB to shrink the mysqld process by circa 100MB. +#skip-innodb +# +# * Security Features +# +# Read the manual, too, if you want chroot! +# chroot = /var/lib/mysql/ +# +# For generating SSL certificates I recommend the OpenSSL GUI "tinyca". +# +# ssl-ca=/etc/mysql/cacert.pem +# ssl-cert=/etc/mysql/server-cert.pem +# ssl-key=/etc/mysql/server-key.pem + + + +[mysqldump] +quick +quote-names +max_allowed_packet = 16M + +[mysql] +#no-auto-rehash # faster start of mysql but no tab completition + +[isamchk] +key_buffer = 16M + +# +# * NDB Cluster +# +# See /usr/share/doc/mysql-server-*/README.Debian for more information. +# +# The following configuration is read by the NDB Data Nodes (ndbd processes) +# not from the NDB Management Nodes (ndb_mgmd processes). +# +# [MYSQL_CLUSTER] +# ndb-connectstring=127.0.0.1 + + +# +# * IMPORTANT: Additional settings that can override those from this file! +# +!includedir /etc/mysql/conf.d/ + diff --git a/lib/deprec/templates/mysql/sphinx.conf.prod b/lib/deprec/templates/mysql/sphinx.conf.prod new file mode 100644 index 0000000..99ce45d --- /dev/null +++ b/lib/deprec/templates/mysql/sphinx.conf.prod @@ -0,0 +1,542 @@ +# +# Sphinx configuration file sample +# + +############################################################################# +## data source definition +############################################################################# + +source src1 +{ + # data source type + # for now, known types are 'mysql', 'pgsql' and 'xmlpipe' + # MUST be defined + type = mysql + + # whether to strip HTML + # values can be 0 (don't strip) or 1 (do strip) + # WARNING, only works with mysql source for now + # WARNING, should work ok for PERFECTLY formed XHTML for now + # WARNING, POSSIBLE TO BUG on malformed everday HTML + # optional, default is 0 + strip_html = 0 + + # what HTML attributes to index if stripping HTML + # format is as follows: + # + # index_html_attrs = img=alt,title; a=title; + # + # optional, default is to not index anything + index_html_attrs = + + ##################################################################### + + # some straightforward parameters for 'mysql' source type + sql_host = <%= @mysql_host %> + sql_user = <%= @username %>_db + sql_pass = <%= @mysqlpass %> + sql_db = <%= @username %>_prod + sql_port = 3306 # optional, default is 3306 + + # sql_sock = /tmp/mysql.sock + # + # optional + # usually '/var/lib/mysql/mysql.sock' on Linux + # usually '/tmp/mysql.sock' on FreeBSD + + # pre-query, executed before the main fetch query + # useful eg. to setup encoding or mark records + # optional, default is empty + # + # sql_query_pre = SET CHARACTER_SET_RESULTS=cp1251 + sql_query_pre = + + # main document fetch query + # + # you can specify up to 32 (formally SPH_MAX_FIELDS in sphinx.h) fields; + # all of the fields which are not document_id or attributes (see below) + # will be full-text indexed + # + # document_id MUST be the very first field + # document_id MUST be positive (non-zero, non-negative) + # document_id MUST fit into 32 bits + # document_id MUST be unique + # + # mandatory + sql_query = \ + SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \ + FROM documents + + # query range setup + # + # useful to avoid MyISAM table locks and big result sets + # when indexing lots of data + # + # to use query ranges, you should + # 1) provide a query to fetch min/max id (ie. id range) from data set; + # 2) configure step size in which this range will be walked; + # 3) use $start and $end macros somewhere in the main fetch query. + # + # 'sql_query_range' must return exactly two integer fields + # in exactly min_id, max_id order + # + # 'sql_range_step' must be a positive integer + # optional, default is 1024 + # + # 'sql_query' must contain both '$start' and '$end' macros + # if you are using query ranges (because it obviously would be an + # error to index the whole table many times) + # + # note that the intervals specified by $start/$end do not + # overlap, so you should NOT remove document ids which are exactly + # equal to $start or $end in your query + # + # here's an example which will index 'documents' table + # fetching (at most) one thousand entries at a time: + # + # sql_query_range = SELECT MIN(id),MAX(id) FROM documents + # sql_range_step = 1000 + # sql_query = \ + # SELECT doc.id, doc.id AS group, doc.title, doc.data \ + # FROM documents doc \ + # WHERE id>=$start AND id<=$end + + + # attribute columns + # + # attribute values MUST be positive (non-zero, non-negative) integers + # attribute values MUST fit into 32 bits + # + # attributes are additional values associated with each document which + # may be used to perform additional filtering and sorting during search. + # attributes are NOT full-text indexed; they are stored in the full text + # index as is. + # + # a good example would be a forum posts table. one might need to search + # through 'title' and 'content' fields but to limit search to specific + # values of 'author_id', or 'forum_id', or to sort by 'post_date', or to + # group matches by 'thread_id', or to group posts by month of the + # 'post_date' and provide statistics. + # + # this all can be achieved by specifying all the mentioned columns + # (excluding 'title' and 'content' which are full-text fields) as + # attributes and then using API calls to setup filtering, sorting, + # and grouping. + # + # sql_group_column is used to declare integer attributes. + # + # sql_date_column is used to declare UNIX timestamp attributes. + # + # sql_str2ordinal_column is used to declare integer attributes which + # values are computed as ordinal numbers of corresponding column value + # in sorted list of column values. WARNING, all such strings values + # are going to be stored in RAM while indexing, and "C" locale will + # be used when sorting! + # + # starting with 0.9.7, there may be multiple attribute columns specified. + # here's an example for that mentioned posts table: + # + # sql_group_column = author_id + # sql_group_column = forum_id + # sql_group_column = thread_id + # sql_date_column = post_unix_timestamp + # sql_date_column = last_edit_unix_timestamp + # + # optional, default is empty + sql_group_column = group_id + sql_date_column = date_added + # sql_str2ordinal_column = author_name + + # post-query, executed on the end of main fetch query + # + # note that indexing is NOT completed at the point when post-query + # gets executed and might very well fail + # + # optional, default is empty + sql_query_post = + + # post-index-query, executed on succsefully completed indexing + # + # $maxid macro is the max document ID which was actually + # fetched from the database + # + # optional, default is empty + # + # sql_query_post_index = REPLACE INTO counters ( id, val ) \ + # VALUES ( 'max_indexed_id', $maxid ) + + + # document info query + # + # ONLY used by search utility to display document information + # MUST be able to fetch document info by its id, therefore + # MUST contain '$id' macro + # + # optional, default is empty + sql_query_info = SELECT * FROM documents WHERE id=$id + + ##################################################################### + + # demo config for 'xmlpipe' source type is a little below + # + # with xmlpipe, indexer opens a pipe to a given command, + # and then reads documents from stdin + # + # indexer expects one or more documents from xmlpipe stdin + # each document must be formatted exactly as follows: + # + # + # 123 + # 45 + # 1132223498 + # test title + # + # this is my document body + # + # + # + # timestamp element is optional, its default value is 1 + # all the other elements are mandatory + + # type = xmlpipe + # xmlpipe_command = cat /usr/local/var/test.xml +} + + +# inherited source example +# +# all the parameters are copied from the parent source, +# and may then be overridden in this source definition +source src1stripped : src1 +{ + strip_html = 1 +} + +############################################################################# +## index definition +############################################################################# + +# local index example +# +# this is an index which is stored locally in the filesystem +# +# all indexing-time options (such as morphology and charsets) +# are configured per local index +index test1 +{ + # which document source to index + # at least one MUST be defined + # + # multiple sources MAY be specified; to do so, just add more + # "source = NAME" lines. in this case, ALL the document IDs + # in ALL the specified sources MUST be unique + source = src1 + + # this is path and index file name without extension + # + # indexer will append different extensions to this path to + # generate names for both permanent and temporary index files + # + # .tmp* files are temporary and can be safely removed + # if indexer fails to remove them automatically + # + # .sp* files are fulltext index data files. specifically, + # .spa contains attribute values attached to each document id + # .spd contains doclists and hitlists + # .sph contains index header (schema and other settings) + # .spi contains wordlists + # + # MUST be defined + path = /data/<%= @username %>/shared/log/indexes/test1 + + # docinfo (ie. per-document attribute values) storage strategy + # defines how docinfo will be stored + # + # available values are "none", "inline" and "extern" + # + # "none" means there'll be no docinfo at all (no groups/dates) + # + # "inline" means that the docinfo will be stored in the .spd + # file along with the document ID lists (doclists) + # + # "extern" means that the docinfo will be stored in the .spa + # file separately + # + # externally stored docinfo should (basically) be kept in RAM + # when querying; therefore, "inline" may be the only viable option + # for really huge (50-100+ million docs) datasets. however, for + # smaller datasets "extern" storage makes both indexing and + # searching MUCH more efficient. + # + # additional search-time memory requirements for extern storage are + # + # ( 1 + number_of_attrs )*number_of_docs*4 bytes + # + # so 10 million docs with 2 groups and 1 timestamp will take + # (1+2+1)*10M*4 = 160 MB of RAM. this is PER DAEMON, ie. searchd + # will alloc 160 MB on startup, read the data and keep it shared + # between queries; the children will NOT allocate additional + # copies of this data. + # + # default is "extern" (as most collections are smaller than 100M docs) + docinfo = extern + + # morphology + # + # currently supported morphology preprocessors are Porter stemmers + # for English and Russian, and Soundex. more stemmers could be added + # at users request. + # + # available values are "none", "stem_en", "stem_ru", "stem_enru", + # and "soundex" + # + # optional, default is "none" + # + # morphology = none + # morphology = stem_en + # morphology = stem_ru + # morphology = stem_enru + # morphology = soundex + morphology = none + + # stopwords file + # + # format is plain text in whatever encoding you use + # optional, default is empty + # + # stopwords = /usr/local/var/data/stopwords.txt + stopwords = + + # minimum word length + # + # only the words that are of this length and above will be indexed; + # for example, if min_word_len is 4, "the" won't be indexed, + # but "they" will be. + # + # default is 1, which (obviously) means to index everything + min_word_len = 1 + + # charset encoding type + # + # known types are 'sbcs' (Single Byte CharSet) and 'utf-8' + # + # optional, default is sbcs + charset_type = sbcs + + # charset definition and case folding rules "table" + # + # optional, default value depends on charset_type + # + # for now, defaults are configured to support English and Russian + # this behavior MAY change in future versions + # + # 'sbcs' default value is + # charset_table = 0..9, A..Z->a..z, _, a..z, U+A8->U+B8, U+B8, U+C0..U+DF->U+E0..U+FF, U+E0..U+FF + # + # 'utf-8' default value is + # charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F + + # minimum prefix length + # + # if prefix length is positive, indexer will not only index all words, + # but all the possible prefixes (ie. word beginnings) as well + # + # for instance, "exam" query against such index will match documents + # which contain "example" word, even if they do not contain "exam" + # + # indexing prefixes will make the index grow significantly + # and could degrade search times + # + # currently there's no way to rank perfect word matches higher + # than prefix matches using only one index; you could setup two + # indexes for that + # + # default is 0, which means NOT to index prefixes + min_prefix_len = 0 + + # minimum infix length + # + # if infix length is positive, indexer will not only index all words, + # but all the possible infixes (ie. characters subsequences starting + # anywhere inside the word) as well + # + # for instance, "amp" query against such index will match documents + # which contain "example" word, even if they do not contain "amp" + # + # indexing prefixes will make the index grow significantly + # and could degrade search times + # + # currently there's no way to rank perfect word matches higher + # than infix matches using only one index; you could setup two + # indexes for that + # + # default is 0, which means NOT to index infixes + min_infix_len = 0 + + # n-grams length + # + # n-grams provide basic CJK support for unsegmented texts. if using + # n-grams, streams of CJK characters are indexed as n-grams. for example, + # if incoming stream is ABCDEF and n is 2, this text would be indexed + # as if it was AB BC CD DE EF. + # + # this feature is in alpha version state and only n=1 is currently + # supported; this is going to be improved. + # + # note that if search query is segmented (ie. words are separated with + # whitespace), words are in quotes and extended matching mode is used, + # then all matching documents will be returned even if their text was + # *not* segmented. in the example above, ABCDEF text will be indexed as + # A B C D E F, and "BCD" query will be transformed to "B C D" (where + # quotes is phrase matching operator), so the document will match. + # + # optional, default is 0, which means NOT to use n-grams + # + # ngram_len = 1 + + # n-gram characters table + # + # specifies what specific characters are subject to n-gram + # extraction. format is similar to charset_table. + # + # optional, default is empty + # + # ngrams_chars = U+3000..U+2FA1F +} + + +# inherited index example +# +# all the parameters are copied from the parent index, +# and may then be overridden in this index definition +index test1stemmed : test1 +{ + path = /data/<%= @username %>/shared/log/indexes/test1stemmed + morphology = stem_en +} + + +# distributed index example +# +# this is a virtual index which can NOT be directly indexed, +# and only contains references to other local and/or remote indexes +# +# if searchd receives a query against this index, +# it does the following: +# +# 1) connects to all the specified remote agents, +# 2) issues the query, +# 3) searches local indexes (while the remote agents are searching), +# 4) collects remote search results, +# 5) merges all the results together (removing the duplicates), +# 6) sends the merged resuls to client. +# +# this index type is primarily intenteded to be able to split huge (100GB+) +# datasets into chunks placed on different physical servers and them search +# through those chunks in parallel, reducing response times and server load; +# it seems, however, that it could also be used to take advantage of +# multi-processor systems or to implement HA (high-availability) search. +index dist1 +{ + # 'distributed' index type MUST be specified + type = distributed + + # local index to be searched + # there can be many local indexes configured + local = test1 + local = test1stemmed + + # remote agent + # multiple remote agents may be specified + # syntax is 'hostname:port:index1,[index2[,...]] + agent = localhost:3313:remote1 + agent = localhost:3314:remote2,remote3 + + # remote agent connection timeout, milliseconds + # optional, default is 1000 ms, ie. 1 sec + agent_connect_timeout = 1000 + + # remote agent query timeout, milliseconds + # optional, default is 3000 ms, ie. 3 sec + agent_query_timeout = 3000 +} + +############################################################################# +## indexer settings +############################################################################# + +indexer +{ + # memory limit + # + # may be specified in bytes (no postfix), kilobytes (mem_limit=1000K) + # or megabytes (mem_limit=10M) + # + # will grow if set unacceptably low + # will warn if set too low and potentially hurting the performance + # + # optional, default is 32M + mem_limit = 32M +} + +############################################################################# +## searchd settings +############################################################################# + +searchd +{ + # IP address on which search daemon will bind and accept + # incoming network requests + # + # optional, default is to listen on all addresses, + # ie. address = 0.0.0.0 + # + # address = 127.0.0.1 + # address = 192.168.0.1 + + + # port on which search daemon will listen + port = 3312 + + + # log file + # searchd run info is logged here + log = /var/log/engineyard/sphinx/<%= @username %>/searchd.log + + + # query log file + # all the search queries are logged here + query_log = /var/log/engineyard/sphinx/<%= @username %>/searchd_query.log + + + # client read timeout, seconds + read_timeout = 5 + + + # maximum amount of children to fork + # useful to control server load + max_children = 30 + + + # a file which will contain searchd process ID + # used for different external automation scripts + # MUST be present + pid_file = /data/<%= @username %>/shared/log/searchd.pid + + + # maximum amount of matches this daemon would ever retrieve + # from each index and serve to client + # + # this parameter affects per-client memory and CPU usage + # (16+ bytes per match) in match sorting phase; so blindly raising + # it to 1 million is definitely NOT recommended + # + # starting from 0.9.7, it can be decreased on the fly through + # the corresponding API call; increasing is prohibited to protect + # against malicious and/or malformed requests + # + # default is 1000 (just like with Google) + max_matches = 1000 +} + +# --eof-- diff --git a/lib/deprec/templates/mysql/sphinx.conf.stage b/lib/deprec/templates/mysql/sphinx.conf.stage new file mode 100644 index 0000000..aaac7a2 --- /dev/null +++ b/lib/deprec/templates/mysql/sphinx.conf.stage @@ -0,0 +1,542 @@ +# +# Sphinx configuration file sample +# + +############################################################################# +## data source definition +############################################################################# + +source src1 +{ + # data source type + # for now, known types are 'mysql', 'pgsql' and 'xmlpipe' + # MUST be defined + type = mysql + + # whether to strip HTML + # values can be 0 (don't strip) or 1 (do strip) + # WARNING, only works with mysql source for now + # WARNING, should work ok for PERFECTLY formed XHTML for now + # WARNING, POSSIBLE TO BUG on malformed everday HTML + # optional, default is 0 + strip_html = 0 + + # what HTML attributes to index if stripping HTML + # format is as follows: + # + # index_html_attrs = img=alt,title; a=title; + # + # optional, default is to not index anything + index_html_attrs = + + ##################################################################### + + # some straightforward parameters for 'mysql' source type + sql_host = <%= @mysql_host %> + sql_user = <%= @username %>_db + sql_pass = <%= @mysqlpass %> + sql_db = <%= @username %>_stage + sql_port = 3306 # optional, default is 3306 + + # sql_sock = /tmp/mysql.sock + # + # optional + # usually '/var/lib/mysql/mysql.sock' on Linux + # usually '/tmp/mysql.sock' on FreeBSD + + # pre-query, executed before the main fetch query + # useful eg. to setup encoding or mark records + # optional, default is empty + # + # sql_query_pre = SET CHARACTER_SET_RESULTS=cp1251 + sql_query_pre = + + # main document fetch query + # + # you can specify up to 32 (formally SPH_MAX_FIELDS in sphinx.h) fields; + # all of the fields which are not document_id or attributes (see below) + # will be full-text indexed + # + # document_id MUST be the very first field + # document_id MUST be positive (non-zero, non-negative) + # document_id MUST fit into 32 bits + # document_id MUST be unique + # + # mandatory + sql_query = \ + SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \ + FROM documents + + # query range setup + # + # useful to avoid MyISAM table locks and big result sets + # when indexing lots of data + # + # to use query ranges, you should + # 1) provide a query to fetch min/max id (ie. id range) from data set; + # 2) configure step size in which this range will be walked; + # 3) use $start and $end macros somewhere in the main fetch query. + # + # 'sql_query_range' must return exactly two integer fields + # in exactly min_id, max_id order + # + # 'sql_range_step' must be a positive integer + # optional, default is 1024 + # + # 'sql_query' must contain both '$start' and '$end' macros + # if you are using query ranges (because it obviously would be an + # error to index the whole table many times) + # + # note that the intervals specified by $start/$end do not + # overlap, so you should NOT remove document ids which are exactly + # equal to $start or $end in your query + # + # here's an example which will index 'documents' table + # fetching (at most) one thousand entries at a time: + # + # sql_query_range = SELECT MIN(id),MAX(id) FROM documents + # sql_range_step = 1000 + # sql_query = \ + # SELECT doc.id, doc.id AS group, doc.title, doc.data \ + # FROM documents doc \ + # WHERE id>=$start AND id<=$end + + + # attribute columns + # + # attribute values MUST be positive (non-zero, non-negative) integers + # attribute values MUST fit into 32 bits + # + # attributes are additional values associated with each document which + # may be used to perform additional filtering and sorting during search. + # attributes are NOT full-text indexed; they are stored in the full text + # index as is. + # + # a good example would be a forum posts table. one might need to search + # through 'title' and 'content' fields but to limit search to specific + # values of 'author_id', or 'forum_id', or to sort by 'post_date', or to + # group matches by 'thread_id', or to group posts by month of the + # 'post_date' and provide statistics. + # + # this all can be achieved by specifying all the mentioned columns + # (excluding 'title' and 'content' which are full-text fields) as + # attributes and then using API calls to setup filtering, sorting, + # and grouping. + # + # sql_group_column is used to declare integer attributes. + # + # sql_date_column is used to declare UNIX timestamp attributes. + # + # sql_str2ordinal_column is used to declare integer attributes which + # values are computed as ordinal numbers of corresponding column value + # in sorted list of column values. WARNING, all such strings values + # are going to be stored in RAM while indexing, and "C" locale will + # be used when sorting! + # + # starting with 0.9.7, there may be multiple attribute columns specified. + # here's an example for that mentioned posts table: + # + # sql_group_column = author_id + # sql_group_column = forum_id + # sql_group_column = thread_id + # sql_date_column = post_unix_timestamp + # sql_date_column = last_edit_unix_timestamp + # + # optional, default is empty + sql_group_column = group_id + sql_date_column = date_added + # sql_str2ordinal_column = author_name + + # post-query, executed on the end of main fetch query + # + # note that indexing is NOT completed at the point when post-query + # gets executed and might very well fail + # + # optional, default is empty + sql_query_post = + + # post-index-query, executed on succsefully completed indexing + # + # $maxid macro is the max document ID which was actually + # fetched from the database + # + # optional, default is empty + # + # sql_query_post_index = REPLACE INTO counters ( id, val ) \ + # VALUES ( 'max_indexed_id', $maxid ) + + + # document info query + # + # ONLY used by search utility to display document information + # MUST be able to fetch document info by its id, therefore + # MUST contain '$id' macro + # + # optional, default is empty + sql_query_info = SELECT * FROM documents WHERE id=$id + + ##################################################################### + + # demo config for 'xmlpipe' source type is a little below + # + # with xmlpipe, indexer opens a pipe to a given command, + # and then reads documents from stdin + # + # indexer expects one or more documents from xmlpipe stdin + # each document must be formatted exactly as follows: + # + # + # 123 + # 45 + # 1132223498 + # test title + # + # this is my document body + # + # + # + # timestamp element is optional, its default value is 1 + # all the other elements are mandatory + + # type = xmlpipe + # xmlpipe_command = cat /usr/local/var/test.xml +} + + +# inherited source example +# +# all the parameters are copied from the parent source, +# and may then be overridden in this source definition +source src1stripped : src1 +{ + strip_html = 1 +} + +############################################################################# +## index definition +############################################################################# + +# local index example +# +# this is an index which is stored locally in the filesystem +# +# all indexing-time options (such as morphology and charsets) +# are configured per local index +index test1 +{ + # which document source to index + # at least one MUST be defined + # + # multiple sources MAY be specified; to do so, just add more + # "source = NAME" lines. in this case, ALL the document IDs + # in ALL the specified sources MUST be unique + source = src1 + + # this is path and index file name without extension + # + # indexer will append different extensions to this path to + # generate names for both permanent and temporary index files + # + # .tmp* files are temporary and can be safely removed + # if indexer fails to remove them automatically + # + # .sp* files are fulltext index data files. specifically, + # .spa contains attribute values attached to each document id + # .spd contains doclists and hitlists + # .sph contains index header (schema and other settings) + # .spi contains wordlists + # + # MUST be defined + path = /data/<%= @username %>/shared/log/indexes/test1 + + # docinfo (ie. per-document attribute values) storage strategy + # defines how docinfo will be stored + # + # available values are "none", "inline" and "extern" + # + # "none" means there'll be no docinfo at all (no groups/dates) + # + # "inline" means that the docinfo will be stored in the .spd + # file along with the document ID lists (doclists) + # + # "extern" means that the docinfo will be stored in the .spa + # file separately + # + # externally stored docinfo should (basically) be kept in RAM + # when querying; therefore, "inline" may be the only viable option + # for really huge (50-100+ million docs) datasets. however, for + # smaller datasets "extern" storage makes both indexing and + # searching MUCH more efficient. + # + # additional search-time memory requirements for extern storage are + # + # ( 1 + number_of_attrs )*number_of_docs*4 bytes + # + # so 10 million docs with 2 groups and 1 timestamp will take + # (1+2+1)*10M*4 = 160 MB of RAM. this is PER DAEMON, ie. searchd + # will alloc 160 MB on startup, read the data and keep it shared + # between queries; the children will NOT allocate additional + # copies of this data. + # + # default is "extern" (as most collections are smaller than 100M docs) + docinfo = extern + + # morphology + # + # currently supported morphology preprocessors are Porter stemmers + # for English and Russian, and Soundex. more stemmers could be added + # at users request. + # + # available values are "none", "stem_en", "stem_ru", "stem_enru", + # and "soundex" + # + # optional, default is "none" + # + # morphology = none + # morphology = stem_en + # morphology = stem_ru + # morphology = stem_enru + # morphology = soundex + morphology = none + + # stopwords file + # + # format is plain text in whatever encoding you use + # optional, default is empty + # + # stopwords = /usr/local/var/data/stopwords.txt + stopwords = + + # minimum word length + # + # only the words that are of this length and above will be indexed; + # for example, if min_word_len is 4, "the" won't be indexed, + # but "they" will be. + # + # default is 1, which (obviously) means to index everything + min_word_len = 1 + + # charset encoding type + # + # known types are 'sbcs' (Single Byte CharSet) and 'utf-8' + # + # optional, default is sbcs + charset_type = sbcs + + # charset definition and case folding rules "table" + # + # optional, default value depends on charset_type + # + # for now, defaults are configured to support English and Russian + # this behavior MAY change in future versions + # + # 'sbcs' default value is + # charset_table = 0..9, A..Z->a..z, _, a..z, U+A8->U+B8, U+B8, U+C0..U+DF->U+E0..U+FF, U+E0..U+FF + # + # 'utf-8' default value is + # charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F + + # minimum prefix length + # + # if prefix length is positive, indexer will not only index all words, + # but all the possible prefixes (ie. word beginnings) as well + # + # for instance, "exam" query against such index will match documents + # which contain "example" word, even if they do not contain "exam" + # + # indexing prefixes will make the index grow significantly + # and could degrade search times + # + # currently there's no way to rank perfect word matches higher + # than prefix matches using only one index; you could setup two + # indexes for that + # + # default is 0, which means NOT to index prefixes + min_prefix_len = 0 + + # minimum infix length + # + # if infix length is positive, indexer will not only index all words, + # but all the possible infixes (ie. characters subsequences starting + # anywhere inside the word) as well + # + # for instance, "amp" query against such index will match documents + # which contain "example" word, even if they do not contain "amp" + # + # indexing prefixes will make the index grow significantly + # and could degrade search times + # + # currently there's no way to rank perfect word matches higher + # than infix matches using only one index; you could setup two + # indexes for that + # + # default is 0, which means NOT to index infixes + min_infix_len = 0 + + # n-grams length + # + # n-grams provide basic CJK support for unsegmented texts. if using + # n-grams, streams of CJK characters are indexed as n-grams. for example, + # if incoming stream is ABCDEF and n is 2, this text would be indexed + # as if it was AB BC CD DE EF. + # + # this feature is in alpha version state and only n=1 is currently + # supported; this is going to be improved. + # + # note that if search query is segmented (ie. words are separated with + # whitespace), words are in quotes and extended matching mode is used, + # then all matching documents will be returned even if their text was + # *not* segmented. in the example above, ABCDEF text will be indexed as + # A B C D E F, and "BCD" query will be transformed to "B C D" (where + # quotes is phrase matching operator), so the document will match. + # + # optional, default is 0, which means NOT to use n-grams + # + # ngram_len = 1 + + # n-gram characters table + # + # specifies what specific characters are subject to n-gram + # extraction. format is similar to charset_table. + # + # optional, default is empty + # + # ngrams_chars = U+3000..U+2FA1F +} + + +# inherited index example +# +# all the parameters are copied from the parent index, +# and may then be overridden in this index definition +index test1stemmed : test1 +{ + path = /data/<%= @username %>/shared/log/indexes/test1stemmed + morphology = stem_en +} + + +# distributed index example +# +# this is a virtual index which can NOT be directly indexed, +# and only contains references to other local and/or remote indexes +# +# if searchd receives a query against this index, +# it does the following: +# +# 1) connects to all the specified remote agents, +# 2) issues the query, +# 3) searches local indexes (while the remote agents are searching), +# 4) collects remote search results, +# 5) merges all the results together (removing the duplicates), +# 6) sends the merged resuls to client. +# +# this index type is primarily intenteded to be able to split huge (100GB+) +# datasets into chunks placed on different physical servers and them search +# through those chunks in parallel, reducing response times and server load; +# it seems, however, that it could also be used to take advantage of +# multi-processor systems or to implement HA (high-availability) search. +index dist1 +{ + # 'distributed' index type MUST be specified + type = distributed + + # local index to be searched + # there can be many local indexes configured + local = test1 + local = test1stemmed + + # remote agent + # multiple remote agents may be specified + # syntax is 'hostname:port:index1,[index2[,...]] + agent = localhost:3313:remote1 + agent = localhost:3314:remote2,remote3 + + # remote agent connection timeout, milliseconds + # optional, default is 1000 ms, ie. 1 sec + agent_connect_timeout = 1000 + + # remote agent query timeout, milliseconds + # optional, default is 3000 ms, ie. 3 sec + agent_query_timeout = 3000 +} + +############################################################################# +## indexer settings +############################################################################# + +indexer +{ + # memory limit + # + # may be specified in bytes (no postfix), kilobytes (mem_limit=1000K) + # or megabytes (mem_limit=10M) + # + # will grow if set unacceptably low + # will warn if set too low and potentially hurting the performance + # + # optional, default is 32M + mem_limit = 32M +} + +############################################################################# +## searchd settings +############################################################################# + +searchd +{ + # IP address on which search daemon will bind and accept + # incoming network requests + # + # optional, default is to listen on all addresses, + # ie. address = 0.0.0.0 + # + # address = 127.0.0.1 + # address = 192.168.0.1 + + + # port on which search daemon will listen + port = 3312 + + + # log file + # searchd run info is logged here + log = /var/log/engineyard/sphinx/<%= @username %>/searchd.log + + + # query log file + # all the search queries are logged here + query_log = /var/log/engineyard/sphinx/<%= @username %>/searchd_query.log + + + # client read timeout, seconds + read_timeout = 5 + + + # maximum amount of children to fork + # useful to control server load + max_children = 30 + + + # a file which will contain searchd process ID + # used for different external automation scripts + # MUST be present + pid_file = /data/<%= @username %>/shared/log/searchd.pid + + + # maximum amount of matches this daemon would ever retrieve + # from each index and serve to client + # + # this parameter affects per-client memory and CPU usage + # (16+ bytes per match) in match sorting phase; so blindly raising + # it to 1 million is definitely NOT recommended + # + # starting from 0.9.7, it can be decreased on the fly through + # the corresponding API call; increasing is prohibited to protect + # against malicious and/or malformed requests + # + # default is 1000 (just like with Google) + max_matches = 1000 +} + +# --eof-- diff --git a/lib/deprec/templates/nagios/cgi.cfg.erb b/lib/deprec/templates/nagios/cgi.cfg.erb new file mode 100644 index 0000000..d16d4a7 --- /dev/null +++ b/lib/deprec/templates/nagios/cgi.cfg.erb @@ -0,0 +1,321 @@ +################################################################# +# +# CGI.CFG - Sample CGI Configuration File for Nagios 3.0b7 +# +# Last Modified: 10-07-2007 +# +################################################################# + + +# MAIN CONFIGURATION FILE +# This tells the CGIs where to find your main configuration file. +# The CGIs will read the main and host config files for any other +# data they might need. + +main_config_file=/usr/local/nagios/etc/nagios.cfg + + + +# PHYSICAL HTML PATH +# This is the path where the HTML files for Nagios reside. This +# value is used to locate the logo images needed by the statusmap +# and statuswrl CGIs. + +physical_html_path=/usr/local/nagios/share + + + +# URL HTML PATH +# This is the path portion of the URL that corresponds to the +# physical location of the Nagios HTML files (as defined above). +# This value is used by the CGIs to locate the online documentation +# and graphics. If you access the Nagios pages with an URL like +# http://www.myhost.com/nagios, this value should be '/nagios' +# (without the quotes). + +url_html_path=/nagios + + + +# CONTEXT-SENSITIVE HELP +# This option determines whether or not a context-sensitive +# help icon will be displayed for most of the CGIs. +# Values: 0 = disables context-sensitive help +# 1 = enables context-sensitive help + +show_context_help=0 + + + +# PENDING STATES OPTION +# This option determines what states should be displayed in the web +# interface for hosts/services that have not yet been checked. +# Values: 0 = leave hosts/services that have not been check yet in their original state +# 1 = mark hosts/services that have not been checked yet as PENDING + +use_pending_states=1 + + + + +# AUTHENTICATION USAGE +# This option controls whether or not the CGIs will use any +# authentication when displaying host and service information, as +# well as committing commands to Nagios for processing. +# +# Read the HTML documentation to learn how the authorization works! +# +# NOTE: It is a really *bad* idea to disable authorization, unless +# you plan on removing the command CGI (cmd.cgi)! Failure to do +# so will leave you wide open to kiddies messing with Nagios and +# possibly hitting you with a denial of service attack by filling up +# your drive by continuously writing to your command file! +# +# Setting this value to 0 will cause the CGIs to *not* use +# authentication (bad idea), while any other value will make them +# use the authentication functions (the default). + +use_authentication=1 + + + +# DEFAULT USER +# Setting this variable will define a default user name that can +# access pages without authentication. This allows people within a +# secure domain (i.e., behind a firewall) to see the current status +# without authenticating. You may want to use this to avoid basic +# authentication if you are not using a secure server since basic +# authentication transmits passwords in the clear. +# +# Important: Do not define a default username unless you are +# running a secure web server and are sure that everyone who has +# access to the CGIs has been authenticated in some manner! If you +# define this variable, anyone who has not authenticated to the web +# server will inherit all rights you assign to this user! + +#default_user_name=guest + + + +# SYSTEM/PROCESS INFORMATION ACCESS +# This option is a comma-delimited list of all usernames that +# have access to viewing the Nagios process information as +# provided by the Extended Information CGI (extinfo.cgi). By +# default, *no one* has access to this unless you choose to +# not use authorization. You may use an asterisk (*) to +# authorize any user who has authenticated to the web server. + +authorized_for_system_information=nagiosadmin + + + +# CONFIGURATION INFORMATION ACCESS +# This option is a comma-delimited list of all usernames that +# can view ALL configuration information (hosts, commands, etc). +# By default, users can only view configuration information +# for the hosts and services they are contacts for. You may use +# an asterisk (*) to authorize any user who has authenticated +# to the web server. + +authorized_for_configuration_information=nagiosadmin + + + +# SYSTEM/PROCESS COMMAND ACCESS +# This option is a comma-delimited list of all usernames that +# can issue shutdown and restart commands to Nagios via the +# command CGI (cmd.cgi). Users in this list can also change +# the program mode to active or standby. By default, *no one* +# has access to this unless you choose to not use authorization. +# You may use an asterisk (*) to authorize any user who has +# authenticated to the web server. + +authorized_for_system_commands=nagiosadmin + + + +# GLOBAL HOST/SERVICE VIEW ACCESS +# These two options are comma-delimited lists of all usernames that +# can view information for all hosts and services that are being +# monitored. By default, users can only view information +# for hosts or services that they are contacts for (unless you +# you choose to not use authorization). You may use an asterisk (*) +# to authorize any user who has authenticated to the web server. + + +authorized_for_all_services=nagiosadmin +authorized_for_all_hosts=nagiosadmin + + + +# GLOBAL HOST/SERVICE COMMAND ACCESS +# These two options are comma-delimited lists of all usernames that +# can issue host or service related commands via the command +# CGI (cmd.cgi) for all hosts and services that are being monitored. +# By default, users can only issue commands for hosts or services +# that they are contacts for (unless you you choose to not use +# authorization). You may use an asterisk (*) to authorize any +# user who has authenticated to the web server. + +authorized_for_all_service_commands=nagiosadmin +authorized_for_all_host_commands=nagiosadmin + + + + +# STATUSMAP BACKGROUND IMAGE +# This option allows you to specify an image to be used as a +# background in the statusmap CGI. It is assumed that the image +# resides in the HTML images path (i.e. /usr/local/nagios/share/images). +# This path is automatically determined by appending "/images" +# to the path specified by the 'physical_html_path' directive. +# Note: The image file may be in GIF, PNG, JPEG, or GD2 format. +# However, I recommend that you convert your image to GD2 format +# (uncompressed), as this will cause less CPU load when the CGI +# generates the image. + +#statusmap_background_image=smbackground.gd2 + + + +# DEFAULT STATUSMAP LAYOUT METHOD +# This option allows you to specify the default layout method +# the statusmap CGI should use for drawing hosts. If you do +# not use this option, the default is to use user-defined +# coordinates. Valid options are as follows: +# 0 = User-defined coordinates +# 1 = Depth layers +# 2 = Collapsed tree +# 3 = Balanced tree +# 4 = Circular +# 5 = Circular (Marked Up) + +default_statusmap_layout=5 + + + +# DEFAULT STATUSWRL LAYOUT METHOD +# This option allows you to specify the default layout method +# the statuswrl (VRML) CGI should use for drawing hosts. If you +# do not use this option, the default is to use user-defined +# coordinates. Valid options are as follows: +# 0 = User-defined coordinates +# 2 = Collapsed tree +# 3 = Balanced tree +# 4 = Circular + +default_statuswrl_layout=4 + + + +# STATUSWRL INCLUDE +# This option allows you to include your own objects in the +# generated VRML world. It is assumed that the file +# resides in the HTML path (i.e. /usr/local/nagios/share). + +#statuswrl_include=myworld.wrl + + + +# PING SYNTAX +# This option determines what syntax should be used when +# attempting to ping a host from the WAP interface (using +# the statuswml CGI. You must include the full path to +# the ping binary, along with all required options. The +# $HOSTADDRESS$ macro is substituted with the address of +# the host before the command is executed. +# Please note that the syntax for the ping binary is +# notorious for being different on virtually ever *NIX +# OS and distribution, so you may have to tweak this to +# work on your system. + +ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$ + + + +# REFRESH RATE +# This option allows you to specify the refresh rate in seconds +# of various CGIs (status, statusmap, extinfo, and outages). + +refresh_rate=90 + + + +# ESCAPE HTML TAGS +# This option determines whether HTML tags in host and service +# status output is escaped in the web interface. If enabled, +# your plugin output will not be able to contain clickable links. + +escape_html_tags=1 + + + + +# SOUND OPTIONS +# These options allow you to specify an optional audio file +# that should be played in your browser window when there are +# problems on the network. The audio files are used only in +# the status CGI. Only the sound for the most critical problem +# will be played. Order of importance (higher to lower) is as +# follows: unreachable hosts, down hosts, critical services, +# warning services, and unknown services. If there are no +# visible problems, the sound file optionally specified by +# 'normal_sound' variable will be played. +# +# +# = +# +# Note: All audio files must be placed in the /media subdirectory +# under the HTML path (i.e. /usr/local/nagios/share/media/). + +#host_unreachable_sound=hostdown.wav +#host_down_sound=hostdown.wav +#service_critical_sound=critical.wav +#service_warning_sound=warning.wav +#service_unknown_sound=warning.wav +#normal_sound=noproblem.wav + + + +# URL TARGET FRAMES +# These options determine the target frames in which notes and +# action URLs will open. + +action_url_target=_blank +notes_url_target=_blank + + + + +# LOCK AUTHOR NAMES OPTION +# This option determines whether users can change the author name +# when submitting comments, scheduling downtime. If disabled, the +# author names will be locked into their contact name, as defined in Nagios. +# Values: 0 = allow editing author names +# 1 = lock author names (disallow editing) + +lock_author_names=1 + + + + +# SPLUNK INTEGRATION OPTIONS +# These options allow you to enable integration with Splunk +# in the web interface. If enabled, you'll be presented with +# "Splunk It" links in various places in the CGIs (log file, +# alert history, host/service detail, etc). Useful if you're +# trying to research why a particular problem occurred. +# For more information on Splunk, visit http://www.splunk.com/ + +# This option determines whether the Splunk integration is enabled +# Values: 0 = disable Splunk integration +# 1 = enable Splunk integration + +#enable_splunk_integration=1 + + +# This option should be the URL used to access your instance of Splunk + +#splunk_url=http://127.0.0.1:8000/ + + diff --git a/lib/deprec/templates/nagios/commands.cfg.erb b/lib/deprec/templates/nagios/commands.cfg.erb new file mode 100644 index 0000000..0c2483e --- /dev/null +++ b/lib/deprec/templates/nagios/commands.cfg.erb @@ -0,0 +1,240 @@ +############################################################################### +# COMMANDS.CFG - SAMPLE COMMAND DEFINITIONS FOR NAGIOS 3.0b7 +# +# Last Modified: 05-31-2007 +# +# NOTES: This config file provides you with some example command definitions +# that you can reference in host, service, and contact definitions. +# +# You don't need to keep commands in a separate file from your other +# object definitions. This has been done just to make things easier to +# understand. +# +############################################################################### + + +################################################################################ +# +# SAMPLE NOTIFICATION COMMANDS +# +# These are some example notification commands. They may or may not work on +# your system without modification. As an example, some systems will require +# you to use "/usr/bin/mailx" instead of "/usr/bin/mail" in the commands below. +# +################################################################################ + + +# 'notify-host-by-email' command definition +define command{ + command_name notify-host-by-email + command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ + } + +# 'notify-service-by-email' command definition +define command{ + command_name notify-service-by-email + command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ + } + + + + + +################################################################################ +# +# SAMPLE HOST CHECK COMMANDS +# +################################################################################ + + +# This command checks to see if a host is "alive" by pinging it +# The check must result in a 100% packet loss or 5 second (5000ms) round trip +# average time to produce a critical error. +# Note: Five ICMP echo packets are sent (determined by the '-p 5' argument) + +# 'check-host-alive' command definition +define command{ + command_name check-host-alive + command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5 + } + + + + +################################################################################ +# +# SAMPLE SERVICE CHECK COMMANDS +# +# These are some example service check commands. They may or may not work on +# your system, as they must be modified for your plugins. See the HTML +# documentation on the plugins for examples of how to configure command definitions. +# +# NOTE: The following 'check_local_...' functions are designed to monitor +# various metrics on the host that Nagios is running on (i.e. this one). +################################################################################ + +# 'check_local_disk' command definition +define command{ + command_name check_local_disk + command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$ + } + + +# 'check_local_load' command definition +define command{ + command_name check_local_load + command_line $USER1$/check_load -w $ARG1$ -c $ARG2$ + } + + +# 'check_local_procs' command definition +define command{ + command_name check_local_procs + command_line $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$ + } + + +# 'check_local_users' command definition +define command{ + command_name check_local_users + command_line $USER1$/check_users -w $ARG1$ -c $ARG2$ + } + + +# 'check_local_swap' command definition +define command{ + command_name check_local_swap + command_line $USER1$/check_swap -w $ARG1$ -c $ARG2$ + } + + +# 'check_local_mrtgtraf' command definition +define command{ + command_name check_local_mrtgtraf + command_line $USER1$/check_mrtgtraf -F $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -e $ARG5$ + } + + +################################################################################ +# NOTE: The following 'check_...' commands are used to monitor services on +# both local and remote hosts. +################################################################################ + +# 'check_ftp' command definition +define command{ + command_name check_ftp + command_line $USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$ + } + + +# 'check_hpjd' command definition +define command{ + command_name check_hpjd + command_line $USER1$/check_hpjd -H $HOSTADDRESS$ $ARG1$ + } + + +# 'check_snmp' command definition +define command{ + command_name check_snmp + command_line $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$ + } + + +# 'check_http' command definition +define command{ + command_name check_http + command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$ + } + + +# 'check_ssh' command definition +define command{ + command_name check_ssh + command_line $USER1$/check_ssh $ARG1$ $HOSTADDRESS$ + } + + +# 'check_dhcp' command definition +define command{ + command_name check_dhcp + command_line $USER1$/check_dhcp $ARG1$ + } + + +# 'check_ping' command definition +define command{ + command_name check_ping + command_line $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5 + } + + +# 'check_pop' command definition +define command{ + command_name check_pop + command_line $USER1$/check_pop -H $HOSTADDRESS$ $ARG1$ + } + + +# 'check_imap' command definition +define command{ + command_name check_imap + command_line $USER1$/check_imap -H $HOSTADDRESS$ $ARG1$ + } + + +# 'check_smtp' command definition +define command{ + command_name check_smtp + command_line $USER1$/check_smtp -H $HOSTADDRESS$ $ARG1$ + } + + +# 'check_tcp' command definition +define command{ + command_name check_tcp + command_line $USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$ + } + + +# 'check_udp' command definition +define command{ + command_name check_udp + command_line $USER1$/check_udp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$ + } + + +# 'check_nt' command definition +define command{ + command_name check_nt + command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$ + } + + + +################################################################################ +# +# SAMPLE PERFORMANCE DATA COMMANDS +# +# These are sample performance data commands that can be used to send performance +# data output to two text files (one for hosts, another for services). If you +# plan on simply writing performance data out to a file, consider using the +# host_perfdata_file and service_perfdata_file options in the main config file. +# +################################################################################ + + +# 'process-host-perfdata' command definition +define command{ + command_name process-host-perfdata + command_line /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /usr/local/nagios/var/host-perfdata.out + } + + +# 'process-service-perfdata' command definition +define command{ + command_name process-service-perfdata + command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /usr/local/nagios/var/service-perfdata.out + } + + diff --git a/lib/deprec/templates/nagios/contacts.cfg.erb b/lib/deprec/templates/nagios/contacts.cfg.erb new file mode 100644 index 0000000..1d5ae19 --- /dev/null +++ b/lib/deprec/templates/nagios/contacts.cfg.erb @@ -0,0 +1,75 @@ +############################################################################### +# CONTACTS.CFG - SAMPLE CONTACT/CONTACTGROUP DEFINITIONS +# +# Last Modified: 05-31-2007 +# +# NOTES: This config file provides you with some example contact and contact +# group definitions that you can reference in host and service +# definitions. +# +# You don't need to keep these definitions in a separate file from your +# other object definitions. This has been done just to make things +# easier to understand. +# +############################################################################### + + + +############################################################################### +############################################################################### +# +# CONTACTS +# +############################################################################### +############################################################################### + +# Just one contact defined by default - the Nagios admin (that's you) +# This contact definition inherits a lot of default values from the 'generic-contact' +# template which is defined elsewhere. + +define contact{ + contact_name nagiosadmin ; Short name of user + use generic-contact ; Inherit default values from generic-contact template (defined above) + alias Nagios Admin ; Full name of user + + email root@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** + } + + + +############################################################################### +############################################################################### +# +# CONTACT GROUPS +# +############################################################################### +############################################################################### + +# We only have one contact in this simple configuration file, so there is +# no need to create more than one contact group. + +define contactgroup{ + contactgroup_name admins + alias Nagios Administrators + members nagiosadmin + } + +# define contact{ # example contact +# contact_name linus +# alias Linux Torvalds +# # contactgroups contactgroup_names +# host_notifications_enabled 1 +# service_notifications_enabled 1 +# host_notification_period 24x7 +# service_notification_period 24x7 +# host_notification_options d,u,r,f,s,n +# service_notification_options w,u,c,r,f,s,n +# host_notification_commands notify-host-by-email +# service_notification_commands notify-service-by-email +# email linus@hotmail.com +# # pager pager_number or pager_email_gateway +# # addressx additional_contact_address +# # can_submit_commands [0/1] +# # retain_status_information [0/1] +# # retain_nonstatus_information [0/1] +# } \ No newline at end of file diff --git a/lib/deprec/templates/nagios/hosts.cfg.erb b/lib/deprec/templates/nagios/hosts.cfg.erb new file mode 100644 index 0000000..009d318 --- /dev/null +++ b/lib/deprec/templates/nagios/hosts.cfg.erb @@ -0,0 +1,70 @@ +define hostgroup{ + hostgroup_name microsoft + alias Big like IBM + # members hosts + # hostgroup_members hostgroups + # notes note_string + # notes_url url + # action_url url +} + +define host{ # example host with + host_name www.microsoft.com + # alias Microsoft homepage + # display_name Some Fancy Name + address www.microsoft.com + hostgroups microsoft + check_command check-host-alive + # initial_state [o,d,u] + max_check_attempts 5 + check_interval 5 + retry_interval 1 + # active_checks_enabled [0/1] + # passive_checks_enabled [0/1] + check_period 24x7 + # obsess_over_host [0/1] + # check_freshness [0/1] + # freshness_threshold # + # event_handler command_name + # event_handler_enabled [0/1] + # low_flap_threshold # + # high_flap_threshold # + # flap_detection_enabled [0/1] + # flap_detection_options [o,d,u] + # process_perf_data [0/1] + # retain_status_information [0/1] + # retain_nonstatus_information [0/1] + # contacts steve + contact_groups admins + notification_interval 5 + # first_notification_delay # + notification_period 24x7 + # notification_options [d,u,r,f,s] + # notifications_enabled [0/1] + # stalking_options [o,d,u] + # notes note_string + # notes_url url + # action_url url + # icon_image image_file + # icon_image_alt alt_string + # vrml_image image_file + # statusmap_image image_file + # 2d_coords x_coord,y_coord + # 3d_coords x_coord,y_coord,z_coord +} + +define host{ + host_name www.hotmail.com + # alias hotmail + # display_name Fancy name for hotmail + address www.hotmail.com + hostgroups microsoft + check_command check-host-alive + max_check_attempts 5 + check_interval 5 + retry_interval 1 + check_period 24x7 + contact_groups admins + notification_interval 5 + notification_period 24x7 +} diff --git a/lib/deprec/templates/nagios/htpasswd.users b/lib/deprec/templates/nagios/htpasswd.users new file mode 100644 index 0000000..2afd901 --- /dev/null +++ b/lib/deprec/templates/nagios/htpasswd.users @@ -0,0 +1 @@ +# access control for nagios web interface diff --git a/lib/deprec/templates/nagios/localhost.cfg.erb b/lib/deprec/templates/nagios/localhost.cfg.erb new file mode 100644 index 0000000..6882ced --- /dev/null +++ b/lib/deprec/templates/nagios/localhost.cfg.erb @@ -0,0 +1,157 @@ +############################################################################### +# LOCALHOST.CFG - SAMPLE OBJECT CONFIG FILE FOR MONITORING THIS MACHINE +# +# Last Modified: 05-31-2007 +# +# NOTE: This config file is intended to serve as an *extremely* simple +# example of how you can create configuration entries to monitor +# the local (Linux) machine. +# +############################################################################### + + + + +############################################################################### +############################################################################### +# +# HOST DEFINITION +# +############################################################################### +############################################################################### + +# Define a host for the local machine + +define host{ + use linux-server ; Name of host template to use + ; This host definition will inherit all variables that are defined + ; in (or inherited by) the linux-server host template definition. + host_name localhost + alias localhost + address 127.0.0.1 + } + + + +############################################################################### +############################################################################### +# +# HOST GROUP DEFINITION +# +############################################################################### +############################################################################### + +# Define an optional hostgroup for Linux machines + +define hostgroup{ + hostgroup_name linux-servers ; The name of the hostgroup + alias Linux Servers ; Long name of the group + members localhost ; Comma separated list of hosts that belong to this group + } + + + +############################################################################### +############################################################################### +# +# SERVICE DEFINITIONS +# +############################################################################### +############################################################################### + + +# Define a service to "ping" the local machine + +define service{ + use local-service ; Name of service template to use + host_name localhost + service_description PING + check_command check_ping!100.0,20%!500.0,60% + } + + +# Define a service to check the disk space of the root partition +# on the local machine. Warning if < 20% free, critical if +# < 10% free space on partition. + +define service{ + use local-service ; Name of service template to use + host_name localhost + service_description Root Partition + check_command check_local_disk!20%!10%!/ + } + + + +# Define a service to check the number of currently logged in +# users on the local machine. Warning if > 20 users, critical +# if > 50 users. + +define service{ + use local-service ; Name of service template to use + host_name localhost + service_description Current Users + check_command check_local_users!20!50 + } + + +# Define a service to check the number of currently running procs +# on the local machine. Warning if > 250 processes, critical if +# > 400 users. + +define service{ + use local-service ; Name of service template to use + host_name localhost + service_description Total Processes + check_command check_local_procs!250!400!RSZDT + } + + + +# Define a service to check the load on the local machine. + +define service{ + use local-service ; Name of service template to use + host_name localhost + service_description Current Load + check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0 + } + + + +# Define a service to check the swap usage the local machine. +# Critical if less than 10% of swap is free, warning if less than 20% is free + +define service{ + use local-service ; Name of service template to use + host_name localhost + service_description Swap Usage + check_command check_local_swap!20!10 + } + + + +# Define a service to check SSH on the local machine. +# Disable notifications for this service by default, as not all users may have SSH enabled. + +define service{ + use local-service ; Name of service template to use + host_name localhost + service_description SSH + check_command check_ssh + notifications_enabled 0 + } + + + +# Define a service to check HTTP on the local machine. +# Disable notifications for this service by default, as not all users may have HTTP enabled. + +define service{ + use local-service ; Name of service template to use + host_name localhost + service_description HTTP + check_command check_http + notifications_enabled 0 + } + diff --git a/lib/deprec/templates/nagios/nagios.cfg.erb b/lib/deprec/templates/nagios/nagios.cfg.erb new file mode 100644 index 0000000..7020bce --- /dev/null +++ b/lib/deprec/templates/nagios/nagios.cfg.erb @@ -0,0 +1,1274 @@ +############################################################################## +# +# NAGIOS.CFG - Sample Main Config File for Nagios 3.0b7 +# +# Read the documentation for more information on this configuration +# file. I've provided some comments here, but things may not be so +# clear without further explanation. +# +# Last Modified: 11-06-2007 +# +############################################################################## + + +# LOG FILE +# This is the main log file where service and host events are logged +# for historical purposes. This should be the first option specified +# in the config file!!! + +log_file=/usr/local/nagios/var/nagios.log + + + +# OBJECT CONFIGURATION FILE(S) +# These are the object configuration files in which you define hosts, +# host groups, contacts, contact groups, services, etc. +# You can split your object definitions across several config files +# if you wish (as shown below), or keep them all in a single config file. + +# You can specify individual object config files as shown below: +#cfg_file=/usr/local/nagios/etc/objects/commands.cfg +#cfg_file=/usr/local/nagios/etc/objects/contacts.cfg +#cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg +#cfg_file=/usr/local/nagios/etc/objects/templates.cfg + +# Definitions for monitoring the local (Linux) host +#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg + +# Definitions for monitoring a Windows machine +#cfg_file=/usr/local/nagios/etc/objects/windows.cfg + +# Definitions for monitoring a router/switch +#cfg_file=/usr/local/nagios/etc/objects/switch.cfg + +# Definitions for monitoring a network printer +#cfg_file=/usr/local/nagios/etc/objects/printer.cfg + + +# You can also tell Nagios to process all config files (with a .cfg +# extension) in a particular directory by using the cfg_dir +# directive as shown below: + +cfg_dir=/usr/local/nagios/etc/objects + + +#cfg_dir=/usr/local/nagios/etc/servers +#cfg_dir=/usr/local/nagios/etc/printers +#cfg_dir=/usr/local/nagios/etc/switches +#cfg_dir=/usr/local/nagios/etc/routers + + + + +# OBJECT CACHE FILE +# This option determines where object definitions are cached when +# Nagios starts/restarts. The CGIs read object definitions from +# this cache file (rather than looking at the object config files +# directly) in order to prevent inconsistencies that can occur +# when the config files are modified after Nagios starts. + +object_cache_file=/usr/local/nagios/var/objects.cache + + + +# PRE-CACHED OBJECT FILE +# This options determines the location of the precached object file. +# If you run Nagios with the -p command line option, it will preprocess +# your object configuration file(s) and write the cached config to this +# file. You can then start Nagios with the -u option to have it read +# object definitions from this precached file, rather than the standard +# object configuration files (see the cfg_file and cfg_dir options above). +# Using a precached object file can speed up the time needed to (re)start +# the Nagios process if you've got a large and/or complex configuration. +# Read the documentation section on optimizing Nagios to find our more +# about how this feature works. + +precached_object_file=/usr/local/nagios/var/objects.precache + + + +# RESOURCE FILE +# This is an optional resource file that contains $USERx$ macro +# definitions. Multiple resource files can be specified by using +# multiple resource_file definitions. The CGIs will not attempt to +# read the contents of resource files, so information that is +# considered to be sensitive (usernames, passwords, etc) can be +# defined as macros in this file and restrictive permissions (600) +# can be placed on this file. + +resource_file=/usr/local/nagios/etc/resource.cfg + + + +# STATUS FILE +# This is where the current status of all monitored services and +# hosts is stored. Its contents are read and processed by the CGIs. +# The contents of the status file are deleted every time Nagios +# restarts. + +status_file=/usr/local/nagios/var/status.dat + + + +# STATUS FILE UPDATE INTERVAL +# Combined with the aggregate_status_updates option, +# this option determines the frequency (in seconds) that +# Nagios will periodically dump program, host, and +# service status data. + +status_update_interval=10 + + + +# NAGIOS USER +# This determines the effective user that Nagios should run as. +# You can either supply a username or a UID. + +nagios_user=nagios + + + +# NAGIOS GROUP +# This determines the effective group that Nagios should run as. +# You can either supply a group name or a GID. + +nagios_group=nagios + + + +# EXTERNAL COMMAND OPTION +# This option allows you to specify whether or not Nagios should check +# for external commands (in the command file defined below). By default +# Nagios will *not* check for external commands, just to be on the +# cautious side. If you want to be able to use the CGI command interface +# you will have to enable this. +# Values: 0 = disable commands, 1 = enable commands + +check_external_commands=1 + + + +# EXTERNAL COMMAND CHECK INTERVAL +# This is the interval at which Nagios should check for external commands. +# This value works of the interval_length you specify later. If you leave +# that at its default value of 60 (seconds), a value of 1 here will cause +# Nagios to check for external commands every minute. If you specify a +# number followed by an "s" (i.e. 15s), this will be interpreted to mean +# actual seconds rather than a multiple of the interval_length variable. +# Note: In addition to reading the external command file at regularly +# scheduled intervals, Nagios will also check for external commands after +# event handlers are executed. +# NOTE: Setting this value to -1 causes Nagios to check the external +# command file as often as possible. + +#command_check_interval=15s +command_check_interval=-1 + + + +# EXTERNAL COMMAND FILE +# This is the file that Nagios checks for external command requests. +# It is also where the command CGI will write commands that are submitted +# by users, so it must be writeable by the user that the web server +# is running as (usually 'nobody'). Permissions should be set at the +# directory level instead of on the file, as the file is deleted every +# time its contents are processed. + +command_file=/usr/local/nagios/var/rw/nagios.cmd + + + +# EXTERNAL COMMAND BUFFER SLOTS +# This settings is used to tweak the number of items or "slots" that +# the Nagios daemon should allocate to the buffer that holds incoming +# external commands before they are processed. As external commands +# are processed by the daemon, they are removed from the buffer. + +external_command_buffer_slots=4096 + + + +# LOCK FILE +# This is the lockfile that Nagios will use to store its PID number +# in when it is running in daemon mode. + +lock_file=/usr/local/nagios/var/nagios.lock + + + +# TEMP FILE +# This is a temporary file that is used as scratch space when Nagios +# updates the status log, cleans the comment file, etc. This file +# is created, used, and deleted throughout the time that Nagios is +# running. + +temp_file=/usr/local/nagios/var/nagios.tmp + + + +# TEMP PATH +# This is path where Nagios can create temp files for service and +# host check results, etc. + +temp_path=/tmp + + + +# EVENT BROKER OPTIONS +# Controls what (if any) data gets sent to the event broker. +# Values: 0 = Broker nothing +# -1 = Broker everything +# = See documentation + +event_broker_options=-1 + + + +# EVENT BROKER MODULE(S) +# This directive is used to specify an event broker module that should +# by loaded by Nagios at startup. Use multiple directives if you want +# to load more than one module. Arguments that should be passed to +# the module at startup are seperated from the module path by a space. +# +#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING +#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# +# Do NOT overwrite modules while they are being used by Nagios or Nagios +# will crash in a fiery display of SEGFAULT glory. This is a bug/limitation +# either in dlopen(), the kernel, and/or the filesystem. And maybe Nagios... +# +# The correct/safe way of updating a module is by using one of these methods: +# 1. Shutdown Nagios, replace the module file, restart Nagios +# 2. Delete the original module file, move the new module file into place, restart Nagios +# +# Example: +# +# broker_module= [moduleargs] + +#broker_module=/somewhere/module1.o +#broker_module=/somewhere/module2.o arg1 arg2=3 debug=0 + + + +# LOG ROTATION METHOD +# This is the log rotation method that Nagios should use to rotate +# the main log file. Values are as follows.. +# n = None - don't rotate the log +# h = Hourly rotation (top of the hour) +# d = Daily rotation (midnight every day) +# w = Weekly rotation (midnight on Saturday evening) +# m = Monthly rotation (midnight last day of month) + +log_rotation_method=d + + + +# LOG ARCHIVE PATH +# This is the directory where archived (rotated) log files should be +# placed (assuming you've chosen to do log rotation). + +log_archive_path=/usr/local/nagios/var/archives + + + +# LOGGING OPTIONS +# If you want messages logged to the syslog facility, as well as the +# Nagios log file set this option to 1. If not, set it to 0. + +use_syslog=1 + + + +# NOTIFICATION LOGGING OPTION +# If you don't want notifications to be logged, set this value to 0. +# If notifications should be logged, set the value to 1. + +log_notifications=1 + + + +# SERVICE RETRY LOGGING OPTION +# If you don't want service check retries to be logged, set this value +# to 0. If retries should be logged, set the value to 1. + +log_service_retries=1 + + + +# HOST RETRY LOGGING OPTION +# If you don't want host check retries to be logged, set this value to +# 0. If retries should be logged, set the value to 1. + +log_host_retries=1 + + + +# EVENT HANDLER LOGGING OPTION +# If you don't want host and service event handlers to be logged, set +# this value to 0. If event handlers should be logged, set the value +# to 1. + +log_event_handlers=1 + + + +# INITIAL STATES LOGGING OPTION +# If you want Nagios to log all initial host and service states to +# the main log file (the first time the service or host is checked) +# you can enable this option by setting this value to 1. If you +# are not using an external application that does long term state +# statistics reporting, you do not need to enable this option. In +# this case, set the value to 0. + +log_initial_states=0 + + + +# EXTERNAL COMMANDS LOGGING OPTION +# If you don't want Nagios to log external commands, set this value +# to 0. If external commands should be logged, set this value to 1. +# Note: This option does not include logging of passive service +# checks - see the option below for controlling whether or not +# passive checks are logged. + +log_external_commands=1 + + + +# PASSIVE CHECKS LOGGING OPTION +# If you don't want Nagios to log passive host and service checks, set +# this value to 0. If passive checks should be logged, set +# this value to 1. + +log_passive_checks=1 + + + +# GLOBAL HOST AND SERVICE EVENT HANDLERS +# These options allow you to specify a host and service event handler +# command that is to be run for every host or service state change. +# The global event handler is executed immediately prior to the event +# handler that you have optionally specified in each host or +# service definition. The command argument is the short name of a +# command definition that you define in your host configuration file. +# Read the HTML docs for more information. + +#global_host_event_handler=somecommand +#global_service_event_handler=somecommand + + + +# SERVICE INTER-CHECK DELAY METHOD +# This is the method that Nagios should use when initially +# "spreading out" service checks when it starts monitoring. The +# default is to use smart delay calculation, which will try to +# space all service checks out evenly to minimize CPU load. +# Using the dumb setting will cause all checks to be scheduled +# at the same time (with no delay between them)! This is not a +# good thing for production, but is useful when testing the +# parallelization functionality. +# n = None - don't use any delay between checks +# d = Use a "dumb" delay of 1 second between checks +# s = Use "smart" inter-check delay calculation +# x.xx = Use an inter-check delay of x.xx seconds + +service_inter_check_delay_method=s + + + +# MAXIMUM SERVICE CHECK SPREAD +# This variable determines the timeframe (in minutes) from the +# program start time that an initial check of all services should +# be completed. Default is 30 minutes. + +max_service_check_spread=30 + + + +# SERVICE CHECK INTERLEAVE FACTOR +# This variable determines how service checks are interleaved. +# Interleaving the service checks allows for a more even +# distribution of service checks and reduced load on remote +# hosts. Setting this value to 1 is equivalent to how versions +# of Nagios previous to 0.0.5 did service checks. Set this +# value to s (smart) for automatic calculation of the interleave +# factor unless you have a specific reason to change it. +# s = Use "smart" interleave factor calculation +# x = Use an interleave factor of x, where x is a +# number greater than or equal to 1. + +service_interleave_factor=s + + + +# HOST INTER-CHECK DELAY METHOD +# This is the method that Nagios should use when initially +# "spreading out" host checks when it starts monitoring. The +# default is to use smart delay calculation, which will try to +# space all host checks out evenly to minimize CPU load. +# Using the dumb setting will cause all checks to be scheduled +# at the same time (with no delay between them)! +# n = None - don't use any delay between checks +# d = Use a "dumb" delay of 1 second between checks +# s = Use "smart" inter-check delay calculation +# x.xx = Use an inter-check delay of x.xx seconds + +host_inter_check_delay_method=s + + + +# MAXIMUM HOST CHECK SPREAD +# This variable determines the timeframe (in minutes) from the +# program start time that an initial check of all hosts should +# be completed. Default is 30 minutes. + +max_host_check_spread=30 + + + +# MAXIMUM CONCURRENT SERVICE CHECKS +# This option allows you to specify the maximum number of +# service checks that can be run in parallel at any given time. +# Specifying a value of 1 for this variable essentially prevents +# any service checks from being parallelized. A value of 0 +# will not restrict the number of concurrent checks that are +# being executed. + +max_concurrent_checks=0 + + + +# HOST AND SERVICE CHECK REAPER FREQUENCY +# This is the frequency (in seconds!) that Nagios will process +# the results of host and service checks. + +check_result_reaper_frequency=10 + + + + +# MAX CHECK RESULT REAPER TIME +# This is the max amount of time (in seconds) that a single +# check result reaper event will be allowed to run before +# returning control back to Nagios so it can perform other +# duties. + +max_check_result_reaper_time=30 + + + + +# CHECK RESULT PATH +# This is directory where Nagios stores the results of host and +# service checks that have not yet been processed. +# +# Note: Make sure that only one instance of Nagios has access +# to this directory! + +check_result_path=/usr/local/nagios/var/spool/checkresults + + + + +# MAX CHECK RESULT FILE AGE +# This option determines the maximum age (in seconds) which check +# result files are considered to be valid. Files older than this +# threshold will be mercilessly deleted without further processing. + +max_check_result_file_age=3600 + + + + +# CACHED HOST CHECK HORIZON +# This option determines the maximum amount of time (in seconds) +# that the state of a previous host check is considered current. +# Cached host states (from host checks that were performed more +# recently that the timeframe specified by this value) can immensely +# improve performance in regards to the host check logic. +# Too high of a value for this option may result in inaccurate host +# states being used by Nagios, while a lower value may result in a +# performance hit for host checks. Use a value of 0 to disable host +# check caching. + +cached_host_check_horizon=15 + + + +# CACHED SERVICE CHECK HORIZON +# This option determines the maximum amount of time (in seconds) +# that the state of a previous service check is considered current. +# Cached service states (from service checks that were performed more +# recently that the timeframe specified by this value) can immensely +# improve performance in regards to predictive dependency checks. +# Use a value of 0 to disable service check caching. + +cached_service_check_horizon=15 + + + +# ENABLE PREDICTIVE HOST DEPENDENCY CHECKS +# This option determines whether or not Nagios will attempt to execute +# checks of hosts when it predicts that future dependency logic test +# may be needed. These predictive checks can help ensure that your +# host dependency logic works well. +# Values: +# 0 = Disable predictive checks +# 1 = Enable predictive checks (default) + +enable_predictive_host_dependency_checks=1 + + + +# ENABLE PREDICTIVE SERVICE DEPENDENCY CHECKS +# This option determines whether or not Nagios will attempt to execute +# checks of service when it predicts that future dependency logic test +# may be needed. These predictive checks can help ensure that your +# service dependency logic works well. +# Values: +# 0 = Disable predictive checks +# 1 = Enable predictive checks (default) + +enable_predictive_service_dependency_checks=1 + + + +# AUTO-RESCHEDULING OPTION +# This option determines whether or not Nagios will attempt to +# automatically reschedule active host and service checks to +# "smooth" them out over time. This can help balance the load on +# the monitoring server. +# WARNING: THIS IS AN EXPERIMENTAL FEATURE - IT CAN DEGRADE +# PERFORMANCE, RATHER THAN INCREASE IT, IF USED IMPROPERLY + +auto_reschedule_checks=0 + + + +# AUTO-RESCHEDULING INTERVAL +# This option determines how often (in seconds) Nagios will +# attempt to automatically reschedule checks. This option only +# has an effect if the auto_reschedule_checks option is enabled. +# Default is 30 seconds. +# WARNING: THIS IS AN EXPERIMENTAL FEATURE - IT CAN DEGRADE +# PERFORMANCE, RATHER THAN INCREASE IT, IF USED IMPROPERLY + +auto_rescheduling_interval=30 + + + +# AUTO-RESCHEDULING WINDOW +# This option determines the "window" of time (in seconds) that +# Nagios will look at when automatically rescheduling checks. +# Only host and service checks that occur in the next X seconds +# (determined by this variable) will be rescheduled. This option +# only has an effect if the auto_reschedule_checks option is +# enabled. Default is 180 seconds (3 minutes). +# WARNING: THIS IS AN EXPERIMENTAL FEATURE - IT CAN DEGRADE +# PERFORMANCE, RATHER THAN INCREASE IT, IF USED IMPROPERLY + +auto_rescheduling_window=180 + + + +# SLEEP TIME +# This is the number of seconds to sleep between checking for system +# events and service checks that need to be run. + +sleep_time=0.25 + + + +# TIMEOUT VALUES +# These options control how much time Nagios will allow various +# types of commands to execute before killing them off. Options +# are available for controlling maximum time allotted for +# service checks, host checks, event handlers, notifications, the +# ocsp command, and performance data commands. All values are in +# seconds. + +service_check_timeout=60 +host_check_timeout=30 +event_handler_timeout=30 +notification_timeout=30 +ocsp_timeout=5 +perfdata_timeout=5 + + + +# RETAIN STATE INFORMATION +# This setting determines whether or not Nagios will save state +# information for services and hosts before it shuts down. Upon +# startup Nagios will reload all saved service and host state +# information before starting to monitor. This is useful for +# maintaining long-term data on state statistics, etc, but will +# slow Nagios down a bit when it (re)starts. Since its only +# a one-time penalty, I think its well worth the additional +# startup delay. + +retain_state_information=1 + + + +# STATE RETENTION FILE +# This is the file that Nagios should use to store host and +# service state information before it shuts down. The state +# information in this file is also read immediately prior to +# starting to monitor the network when Nagios is restarted. +# This file is used only if the preserve_state_information +# variable is set to 1. + +state_retention_file=/usr/local/nagios/var/retention.dat + + + +# RETENTION DATA UPDATE INTERVAL +# This setting determines how often (in minutes) that Nagios +# will automatically save retention data during normal operation. +# If you set this value to 0, Nagios will not save retention +# data at regular interval, but it will still save retention +# data before shutting down or restarting. If you have disabled +# state retention, this option has no effect. + +retention_update_interval=60 + + + +# USE RETAINED PROGRAM STATE +# This setting determines whether or not Nagios will set +# program status variables based on the values saved in the +# retention file. If you want to use retained program status +# information, set this value to 1. If not, set this value +# to 0. + +use_retained_program_state=1 + + + +# USE RETAINED SCHEDULING INFO +# This setting determines whether or not Nagios will retain +# the scheduling info (next check time) for hosts and services +# based on the values saved in the retention file. If you +# If you want to use retained scheduling info, set this +# value to 1. If not, set this value to 0. + +use_retained_scheduling_info=1 + + + +# RETAINED ATTRIBUTE MASKS (ADVANCED FEATURE) +# The following variables are used to specify specific host and +# service attributes that should *not* be retained by Nagios during +# program restarts. +# +# The values of the masks are bitwise ANDs of values specified +# by the "MODATTR_" definitions found in include/common.h. +# For example, if you do not want the current enabled/disabled state +# of flap detection and event handlers for hosts to be retained, you +# would use a value of 24 for the host attribute mask... +# MODATTR_EVENT_HANDLER_ENABLED (8) + MODATTR_FLAP_DETECTION_ENABLED (16) = 24 + +# This mask determines what host attributes are not retained +retained_host_attribute_mask=0 + +# This mask determines what service attributes are not retained +retained_service_attribute_mask=0 + +# These two masks determine what process attributes are not retained. +# There are two masks, because some process attributes have host and service +# options. For example, you can disable active host checks, but leave active +# service checks enabled. +retained_process_host_attribute_mask=0 +retained_process_service_attribute_mask=0 + +# These two masks determine what contact attributes are not retained. +# There are two masks, because some contact attributes have host and +# service options. For example, you can disable host notifications for +# a contact, but leave service notifications enabled for them. +retained_contact_host_attribute_mask=0 +retained_contact_service_attribute_mask=0 + + + +# INTERVAL LENGTH +# This is the seconds per unit interval as used in the +# host/contact/service configuration files. Setting this to 60 means +# that each interval is one minute long (60 seconds). Other settings +# have not been tested much, so your mileage is likely to vary... + +interval_length=60 + + + +# AGGRESSIVE HOST CHECKING OPTION +# If you don't want to turn on aggressive host checking features, set +# this value to 0 (the default). Otherwise set this value to 1 to +# enable the aggressive check option. Read the docs for more info +# on what aggressive host check is or check out the source code in +# base/checks.c + +use_aggressive_host_checking=0 + + + +# SERVICE CHECK EXECUTION OPTION +# This determines whether or not Nagios will actively execute +# service checks when it initially starts. If this option is +# disabled, checks are not actively made, but Nagios can still +# receive and process passive check results that come in. Unless +# you're implementing redundant hosts or have a special need for +# disabling the execution of service checks, leave this enabled! +# Values: 1 = enable checks, 0 = disable checks + +execute_service_checks=1 + + + +# PASSIVE SERVICE CHECK ACCEPTANCE OPTION +# This determines whether or not Nagios will accept passive +# service checks results when it initially (re)starts. +# Values: 1 = accept passive checks, 0 = reject passive checks + +accept_passive_service_checks=1 + + + +# HOST CHECK EXECUTION OPTION +# This determines whether or not Nagios will actively execute +# host checks when it initially starts. If this option is +# disabled, checks are not actively made, but Nagios can still +# receive and process passive check results that come in. Unless +# you're implementing redundant hosts or have a special need for +# disabling the execution of host checks, leave this enabled! +# Values: 1 = enable checks, 0 = disable checks + +execute_host_checks=1 + + + +# PASSIVE HOST CHECK ACCEPTANCE OPTION +# This determines whether or not Nagios will accept passive +# host checks results when it initially (re)starts. +# Values: 1 = accept passive checks, 0 = reject passive checks + +accept_passive_host_checks=1 + + + +# NOTIFICATIONS OPTION +# This determines whether or not Nagios will sent out any host or +# service notifications when it is initially (re)started. +# Values: 1 = enable notifications, 0 = disable notifications + +enable_notifications=1 + + + +# EVENT HANDLER USE OPTION +# This determines whether or not Nagios will run any host or +# service event handlers when it is initially (re)started. Unless +# you're implementing redundant hosts, leave this option enabled. +# Values: 1 = enable event handlers, 0 = disable event handlers + +enable_event_handlers=1 + + + +# PROCESS PERFORMANCE DATA OPTION +# This determines whether or not Nagios will process performance +# data returned from service and host checks. If this option is +# enabled, host performance data will be processed using the +# host_perfdata_command (defined below) and service performance +# data will be processed using the service_perfdata_command (also +# defined below). Read the HTML docs for more information on +# performance data. +# Values: 1 = process performance data, 0 = do not process performance data + +process_performance_data=0 + + + +# HOST AND SERVICE PERFORMANCE DATA PROCESSING COMMANDS +# These commands are run after every host and service check is +# performed. These commands are executed only if the +# enable_performance_data option (above) is set to 1. The command +# argument is the short name of a command definition that you +# define in your host configuration file. Read the HTML docs for +# more information on performance data. + +#host_perfdata_command=process-host-perfdata +#service_perfdata_command=process-service-perfdata + + + +# HOST AND SERVICE PERFORMANCE DATA FILES +# These files are used to store host and service performance data. +# Performance data is only written to these files if the +# enable_performance_data option (above) is set to 1. + +#host_perfdata_file=/tmp/host-perfdata +#service_perfdata_file=/tmp/service-perfdata + + + +# HOST AND SERVICE PERFORMANCE DATA FILE TEMPLATES +# These options determine what data is written (and how) to the +# performance data files. The templates may contain macros, special +# characters (\t for tab, \r for carriage return, \n for newline) +# and plain text. A newline is automatically added after each write +# to the performance data file. Some examples of what you can do are +# shown below. + +#host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$ +#service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$ + + + +# HOST AND SERVICE PERFORMANCE DATA FILE MODES +# This option determines whether or not the host and service +# performance data files are opened in write ("w") or append ("a") +# mode. If you want to use named pipes, you should use the special +# pipe ("p") mode which avoid blocking at startup, otherwise you will +# likely want the defult append ("a") mode. + +#host_perfdata_file_mode=a +#service_perfdata_file_mode=a + + + +# HOST AND SERVICE PERFORMANCE DATA FILE PROCESSING INTERVAL +# These options determine how often (in seconds) the host and service +# performance data files are processed using the commands defined +# below. A value of 0 indicates the files should not be periodically +# processed. + +#host_perfdata_file_processing_interval=0 +#service_perfdata_file_processing_interval=0 + + + +# HOST AND SERVICE PERFORMANCE DATA FILE PROCESSING COMMANDS +# These commands are used to periodically process the host and +# service performance data files. The interval at which the +# processing occurs is determined by the options above. + +#host_perfdata_file_processing_command=process-host-perfdata-file +#service_perfdata_file_processing_command=process-service-perfdata-file + + + +# OBSESS OVER SERVICE CHECKS OPTION +# This determines whether or not Nagios will obsess over service +# checks and run the ocsp_command defined below. Unless you're +# planning on implementing distributed monitoring, do not enable +# this option. Read the HTML docs for more information on +# implementing distributed monitoring. +# Values: 1 = obsess over services, 0 = do not obsess (default) + +obsess_over_services=0 + + + +# OBSESSIVE COMPULSIVE SERVICE PROCESSOR COMMAND +# This is the command that is run for every service check that is +# processed by Nagios. This command is executed only if the +# obsess_over_services option (above) is set to 1. The command +# argument is the short name of a command definition that you +# define in your host configuration file. Read the HTML docs for +# more information on implementing distributed monitoring. + +#ocsp_command=somecommand + + + +# OBSESS OVER HOST CHECKS OPTION +# This determines whether or not Nagios will obsess over host +# checks and run the ochp_command defined below. Unless you're +# planning on implementing distributed monitoring, do not enable +# this option. Read the HTML docs for more information on +# implementing distributed monitoring. +# Values: 1 = obsess over hosts, 0 = do not obsess (default) + +obsess_over_hosts=0 + + + +# OBSESSIVE COMPULSIVE HOST PROCESSOR COMMAND +# This is the command that is run for every host check that is +# processed by Nagios. This command is executed only if the +# obsess_over_hosts option (above) is set to 1. The command +# argument is the short name of a command definition that you +# define in your host configuration file. Read the HTML docs for +# more information on implementing distributed monitoring. + +#ochp_command=somecommand + + + +# TRANSLATE PASSIVE HOST CHECKS OPTION +# This determines whether or not Nagios will translate +# DOWN/UNREACHABLE passive host check results into their proper +# state for this instance of Nagios. This option is useful +# if you have distributed or failover monitoring setup. In +# these cases your other Nagios servers probably have a different +# "view" of the network, with regards to the parent/child relationship +# of hosts. If a distributed monitoring server thinks a host +# is DOWN, it may actually be UNREACHABLE from the point of +# this Nagios instance. Enabling this option will tell Nagios +# to translate any DOWN or UNREACHABLE host states it receives +# passively into the correct state from the view of this server. +# Values: 1 = perform translation, 0 = do not translate (default) + +translate_passive_host_checks=0 + + + +# PASSIVE HOST CHECKS ARE SOFT OPTION +# This determines whether or not Nagios will treat passive host +# checks as being HARD or SOFT. By default, a passive host check +# result will put a host into a HARD state type. This can be changed +# by enabling this option. +# Values: 0 = passive checks are HARD, 1 = passive checks are SOFT + +passive_host_checks_are_soft=0 + + + +# ORPHANED HOST/SERVICE CHECK OPTIONS +# These options determine whether or not Nagios will periodically +# check for orphaned host service checks. Since service checks are +# not rescheduled until the results of their previous execution +# instance are processed, there exists a possibility that some +# checks may never get rescheduled. A similar situation exists for +# host checks, although the exact scheduling details differ a bit +# from service checks. Orphaned checks seem to be a rare +# problem and should not happen under normal circumstances. +# If you have problems with service checks never getting +# rescheduled, make sure you have orphaned service checks enabled. +# Values: 1 = enable checks, 0 = disable checks + +check_for_orphaned_services=1 +check_for_orphaned_hosts=1 + + + +# SERVICE FRESHNESS CHECK OPTION +# This option determines whether or not Nagios will periodically +# check the "freshness" of service results. Enabling this option +# is useful for ensuring passive checks are received in a timely +# manner. +# Values: 1 = enabled freshness checking, 0 = disable freshness checking + +check_service_freshness=1 + + + +# SERVICE FRESHNESS CHECK INTERVAL +# This setting determines how often (in seconds) Nagios will +# check the "freshness" of service check results. If you have +# disabled service freshness checking, this option has no effect. + +service_freshness_check_interval=60 + + + +# HOST FRESHNESS CHECK OPTION +# This option determines whether or not Nagios will periodically +# check the "freshness" of host results. Enabling this option +# is useful for ensuring passive checks are received in a timely +# manner. +# Values: 1 = enabled freshness checking, 0 = disable freshness checking + +check_host_freshness=0 + + + +# HOST FRESHNESS CHECK INTERVAL +# This setting determines how often (in seconds) Nagios will +# check the "freshness" of host check results. If you have +# disabled host freshness checking, this option has no effect. + +host_freshness_check_interval=60 + + + + +# ADDITIONAL FRESHNESS THRESHOLD LATENCY +# This setting determines the number of seconds that Nagios +# will add to any host and service freshness thresholds that +# it calculates (those not explicitly specified by the user). + +additional_freshness_latency=15 + + + + +# FLAP DETECTION OPTION +# This option determines whether or not Nagios will try +# and detect hosts and services that are "flapping". +# Flapping occurs when a host or service changes between +# states too frequently. When Nagios detects that a +# host or service is flapping, it will temporarily suppress +# notifications for that host/service until it stops +# flapping. Flap detection is very experimental, so read +# the HTML documentation before enabling this feature! +# Values: 1 = enable flap detection +# 0 = disable flap detection (default) + +enable_flap_detection=1 + + + +# FLAP DETECTION THRESHOLDS FOR HOSTS AND SERVICES +# Read the HTML documentation on flap detection for +# an explanation of what this option does. This option +# has no effect if flap detection is disabled. + +low_service_flap_threshold=5.0 +high_service_flap_threshold=20.0 +low_host_flap_threshold=5.0 +high_host_flap_threshold=20.0 + + + +# DATE FORMAT OPTION +# This option determines how short dates are displayed. Valid options +# include: +# us (MM-DD-YYYY HH:MM:SS) +# euro (DD-MM-YYYY HH:MM:SS) +# iso8601 (YYYY-MM-DD HH:MM:SS) +# strict-iso8601 (YYYY-MM-DDTHH:MM:SS) +# + +date_format=us + + + + +# TIMEZONE OFFSET +# This option is used to override the default timezone that this +# instance of Nagios runs in. If not specified, Nagios will use +# the system configured timezone. +# +# NOTE: In order to display the correct timezone in the CGIs, you +# will also need to alter the Apache directives for the CGI path +# to include your timezone. Example: +# +# +# SetEnv TZ "Australia/Brisbane" +# ... +# + +#use_timezone=US/Mountain +#use_timezone=Australia/Brisbane + + + + +# P1.PL FILE LOCATION +# This value determines where the p1.pl perl script (used by the +# embedded Perl interpreter) is located. If you didn't compile +# Nagios with embedded Perl support, this option has no effect. + +p1_file=/usr/local/nagios/bin/p1.pl + + + +# EMBEDDED PERL INTERPRETER OPTION +# This option determines whether or not the embedded Perl interpreter +# will be enabled during runtime. This option has no effect if Nagios +# has not been compiled with support for embedded Perl. +# Values: 0 = disable interpreter, 1 = enable interpreter + +enable_embedded_perl=1 + + + +# EMBEDDED PERL USAGE OPTION +# This option determines whether or not Nagios will process Perl plugins +# and scripts with the embedded Perl interpreter if the plugins/scripts +# do not explicitly indicate whether or not it is okay to do so. Read +# the HTML documentation on the embedded Perl interpreter for more +# information on how this option works. + +use_embedded_perl_implicitly=1 + + + +# ILLEGAL OBJECT NAME CHARACTERS +# This option allows you to specify illegal characters that cannot +# be used in host names, service descriptions, or names of other +# object types. + +illegal_object_name_chars=`~!$%^&*|'"<>?,()= + + + +# ILLEGAL MACRO OUTPUT CHARACTERS +# This option allows you to specify illegal characters that are +# stripped from macros before being used in notifications, event +# handlers, etc. This DOES NOT affect macros used in service or +# host check commands. +# The following macros are stripped of the characters you specify: +# $HOSTOUTPUT$ +# $HOSTPERFDATA$ +# $HOSTACKAUTHOR$ +# $HOSTACKCOMMENT$ +# $SERVICEOUTPUT$ +# $SERVICEPERFDATA$ +# $SERVICEACKAUTHOR$ +# $SERVICEACKCOMMENT$ + +illegal_macro_output_chars=`~$&|'"<> + + + +# REGULAR EXPRESSION MATCHING +# This option controls whether or not regular expression matching +# takes place in the object config files. Regular expression +# matching is used to match host, hostgroup, service, and service +# group names/descriptions in some fields of various object types. +# Values: 1 = enable regexp matching, 0 = disable regexp matching + +use_regexp_matching=0 + + + +# "TRUE" REGULAR EXPRESSION MATCHING +# This option controls whether or not "true" regular expression +# matching takes place in the object config files. This option +# only has an effect if regular expression matching is enabled +# (see above). If this option is DISABLED, regular expression +# matching only occurs if a string contains wildcard characters +# (* and ?). If the option is ENABLED, regexp matching occurs +# all the time (which can be annoying). +# Values: 1 = enable true matching, 0 = disable true matching + +use_true_regexp_matching=0 + + + +# ADMINISTRATOR EMAIL/PAGER ADDRESSES +# The email and pager address of a global administrator (likely you). +# Nagios never uses these values itself, but you can access them by +# using the $ADMINEMAIL$ and $ADMINPAGER$ macros in your notification +# commands. + +admin_email=nagios@localhost +admin_pager=pagenagios@localhost + + + +# DAEMON CORE DUMP OPTION +# This option determines whether or not Nagios is allowed to create +# a core dump when it runs as a daemon. Note that it is generally +# considered bad form to allow this, but it may be useful for +# debugging purposes. Enabling this option doesn't guarantee that +# a core file will be produced, but that's just life... +# Values: 1 - Allow core dumps +# 0 - Do not allow core dumps (default) + +daemon_dumps_core=0 + + + +# LARGE INSTALLATION TWEAKS OPTION +# This option determines whether or not Nagios will take some shortcuts +# which can save on memory and CPU usage in large Nagios installations. +# Read the documentation for more information on the benefits/tradeoffs +# of enabling this option. +# Values: 1 - Enabled tweaks +# 0 - Disable tweaks (default) + +use_large_installation_tweaks=0 + + + +# ENABLE ENVIRONMENT MACROS +# This option determines whether or not Nagios will make all standard +# macros available as environment variables when host/service checks +# and system commands (event handlers, notifications, etc.) are +# executed. Enabling this option can cause performance issues in +# large installations, as it will consume a bit more memory and (more +# importantly) consume more CPU. +# Values: 1 - Enable environment variable macros (default) +# 0 - Disable environment variable macros + +enable_environment_macros=1 + + + +# CHILD PROCESS MEMORY OPTION +# This option determines whether or not Nagios will free memory in +# child processes (processed used to execute system commands and host/ +# service checks). If you specify a value here, it will override +# program defaults. +# Value: 1 - Free memory in child processes +# 0 - Do not free memory in child processes + +#free_child_process_memory=1 + + + +# CHILD PROCESS FORKING BEHAVIOR +# This option determines how Nagios will fork child processes +# (used to execute system commands and host/service checks). Normally +# child processes are fork()ed twice, which provides a very high level +# of isolation from problems. Fork()ing once is probably enough and will +# save a great deal on CPU usage (in large installs), so you might +# want to consider using this. If you specify a value here, it will +# program defaults. +# Value: 1 - Child processes fork() twice +# 0 - Child processes fork() just once + +#child_processes_fork_twice=1 + + + +# DEBUG LEVEL +# This option determines how much (if any) debugging information will +# be written to the debug file. OR values together to log multiple +# types of information. +# Values: -1 = Everything +# 0 = Nothing +# 1 = Functions +# 2 = Configuration +# 4 = Process information +# 8 = Scheduled events +# 16 = Host/service checks +# 32 = Notifications +# 64 = Event broker +# 128 = Check IPC + +debug_level=0 + + + +# DEBUG VERBOSITY +# This option determines how verbose the debug log out will be. +# Values: 0 = Brief output +# 1 = More detailed +# 2 = Very detailed + +debug_verbosity=1 + + + +# DEBUG FILE +# This option determines where Nagios should write debugging information. + +debug_file=/usr/local/nagios/var/nagios.debug + + + +# MAX DEBUG FILE SIZE +# This option determines the maximum size (in bytes) of the debug file. If +# the file grows larger than this size, it will be renamed with a .old +# extension. If a file already exists with a .old extension it will +# automatically be deleted. This helps ensure your disk space usage doesn't +# get out of control when debugging Nagios. + +max_debug_file_size=1000000 + + diff --git a/lib/deprec/templates/nagios/nagios_apache_vhost.conf.erb b/lib/deprec/templates/nagios/nagios_apache_vhost.conf.erb new file mode 100644 index 0000000..84bb89e --- /dev/null +++ b/lib/deprec/templates/nagios/nagios_apache_vhost.conf.erb @@ -0,0 +1,45 @@ + + ServerName <%= domain %> + DocumentRoot "/usr/local/nagios/share" + ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" + Alias /nagios "/usr/local/nagios/share" + + + # SSLRequireSSL + Options ExecCGI + AllowOverride None + Order allow,deny + Allow from all + # Order deny,allow + # Deny from all + # Allow from 127.0.0.1 + AuthName "Nagios Access" + AuthType Basic + AuthUserFile /usr/local/nagios/etc/htpasswd.users + Require valid-user + + + + # SSLRequireSSL + Options None + AllowOverride None + Order allow,deny + Allow from all + # Order deny,allow + # Deny from all + # Allow from 127.0.0.1 + AuthName "Nagios Access" + AuthType Basic + AuthUserFile /usr/local/nagios/etc/htpasswd.users + Require valid-user + + + # Deflate + AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript + BrowserMatch ^Mozilla/4 gzip-only-text/html + BrowserMatch ^Mozilla/4\.0[678] no-gzip + BrowserMatch \bMSIE !no-gzip !gzip-only-text/html + + ErrorLog logs/nagios.sct-error_log + CustomLog logs/nagios.sct-access_log combined + \ No newline at end of file diff --git a/lib/deprec/templates/nagios/nrpe.cfg.erb b/lib/deprec/templates/nagios/nrpe.cfg.erb new file mode 100644 index 0000000..bb7a35f --- /dev/null +++ b/lib/deprec/templates/nagios/nrpe.cfg.erb @@ -0,0 +1,208 @@ +############################################################################# +# Sample NRPE Config File +# Written by: Ethan Galstad (nagios@nagios.org) +# +# Last Modified: 03-09-2007 +# +# NOTES: +# This is a sample configuration file for the NRPE daemon. It needs to be +# located on the remote host that is running the NRPE daemon, not the host +# from which the check_nrpe client is being executed. +############################################################################# + + +# PID FILE +# The name of the file in which the NRPE daemon should write it's process ID +# number. The file is only written if the NRPE daemon is started by the root +# user and is running in standalone mode. + +pid_file=/var/run/nrpe.pid + + + +# PORT NUMBER +# Port number we should wait for connections on. +# NOTE: This must be a non-priviledged port (i.e. > 1024). +# NOTE: This option is ignored if NRPE is running under either inetd or xinetd + +server_port=5666 + + + +# SERVER ADDRESS +# Address that nrpe should bind to in case there are more than one interface +# and you do not want nrpe to bind on all interfaces. +# NOTE: This option is ignored if NRPE is running under either inetd or xinetd + +#server_address=127.0.0.1 + + + +# NRPE USER +# This determines the effective user that the NRPE daemon should run as. +# You can either supply a username or a UID. +# +# NOTE: This option is ignored if NRPE is running under either inetd or xinetd + +nrpe_user=nagios + + + +# NRPE GROUP +# This determines the effective group that the NRPE daemon should run as. +# You can either supply a group name or a GID. +# +# NOTE: This option is ignored if NRPE is running under either inetd or xinetd + +nrpe_group=nagios + + + +# ALLOWED HOST ADDRESSES +# This is an optional comma-delimited list of IP address or hostnames +# that are allowed to talk to the NRPE daemon. +# +# Note: The daemon only does rudimentary checking of the client's IP +# address. I would highly recommend adding entries in your /etc/hosts.allow +# file to allow only the specified host to connect to the port +# you are running this daemon on. +# +# NOTE: This option is ignored if NRPE is running under either inetd or xinetd + +allowed_hosts=127.0.0.1 + + + +# COMMAND ARGUMENT PROCESSING +# This option determines whether or not the NRPE daemon will allow clients +# to specify arguments to commands that are executed. This option only works +# if the daemon was configured with the --enable-command-args configure script +# option. +# +# *** ENABLING THIS OPTION IS A SECURITY RISK! *** +# Read the SECURITY file for information on some of the security implications +# of enabling this variable. +# +# Values: 0=do not allow arguments, 1=allow command arguments + +dont_blame_nrpe=0 + + + +# COMMAND PREFIX +# This option allows you to prefix all commands with a user-defined string. +# A space is automatically added between the specified prefix string and the +# command line from the command definition. +# +# *** THIS EXAMPLE MAY POSE A POTENTIAL SECURITY RISK, SO USE WITH CAUTION! *** +# Usage scenario: +# Execute restricted commmands using sudo. For this to work, you need to add +# the nagios user to your /etc/sudoers. An example entry for alllowing +# execution of the plugins from might be: +# +# nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/ +# +# This lets the nagios user run all commands in that directory (and only them) +# without asking for a password. If you do this, make sure you don't give +# random users write access to that directory or its contents! + +# command_prefix=/usr/bin/sudo + + + +# DEBUGGING OPTION +# This option determines whether or not debugging messages are logged to the +# syslog facility. +# Values: 0=debugging off, 1=debugging on + +debug=0 + + + +# COMMAND TIMEOUT +# This specifies the maximum number of seconds that the NRPE daemon will +# allow plugins to finish executing before killing them off. + +command_timeout=60 + + + +# CONNECTION TIMEOUT +# This specifies the maximum number of seconds that the NRPE daemon will +# wait for a connection to be established before exiting. This is sometimes +# seen where a network problem stops the SSL being established even though +# all network sessions are connected. This causes the nrpe daemons to +# accumulate, eating system resources. Do not set this too low. + +connection_timeout=300 + + + +# WEEK RANDOM SEED OPTION +# This directive allows you to use SSL even if your system does not have +# a /dev/random or /dev/urandom (on purpose or because the necessary patches +# were not applied). The random number generator will be seeded from a file +# which is either a file pointed to by the environment valiable $RANDFILE +# or $HOME/.rnd. If neither exists, the pseudo random number generator will +# be initialized and a warning will be issued. +# Values: 0=only seed from /dev/[u]random, 1=also seed from weak randomness + +#allow_weak_random_seed=1 + + + +# INCLUDE CONFIG FILE +# This directive allows you to include definitions from an external config file. + +#include= + + + +# INCLUDE CONFIG DIRECTORY +# This directive allows you to include definitions from config files (with a +# .cfg extension) in one or more directories (with recursion). + +#include_dir= +#include_dir= + + + +# COMMAND DEFINITIONS +# Command definitions that this daemon will run. Definitions +# are in the following format: +# +# command[]= +# +# When the daemon receives a request to return the results of +# it will execute the command specified by the argument. +# +# Unlike Nagios, the command line cannot contain macros - it must be +# typed exactly as it should be executed. +# +# Note: Any plugins that are used in the command lines must reside +# on the machine that this daemon is running on! The examples below +# assume that you have plugins installed in a /usr/local/nagios/libexec +# directory. Also note that you will have to modify the definitions below +# to match the argument format the plugins expect. Remember, these are +# examples only! + + +# The following examples use hardcoded command arguments... + +command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10 +command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20 +command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1 +command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z +command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 + + +# The following examples allow user-supplied arguments and can +# only be used if the NRPE daemon was compiled with support for +# command arguments *AND* the dont_blame_nrpe directive in this +# config file is set to '1'. This poses a potential security risk, so +# make sure you read the SECURITY file before doing this. + +#command[check_users]=/usr/local/nagios/libexec/check_users -w $ARG1$ -c $ARG2$ +#command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$ +#command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$ +#command[check_procs]=/usr/local/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$ diff --git a/lib/deprec/templates/nagios/nrpe.xinetd.erb b/lib/deprec/templates/nagios/nrpe.xinetd.erb new file mode 100644 index 0000000..a3b51aa --- /dev/null +++ b/lib/deprec/templates/nagios/nrpe.xinetd.erb @@ -0,0 +1,16 @@ +# default: on +# description: NRPE (Nagios Remote Plugin Executor) +service nrpe +{ + flags = REUSE + socket_type = stream + port = 5666 + wait = no + user = nagios + group = nagios + server = /usr/local/nagios/bin/nrpe + server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd + log_on_failure += USERID + disable = no + only_from = 127.0.0.1 <%= nagios_host %> +} \ No newline at end of file diff --git a/lib/deprec/templates/nagios/resource.cfg.erb b/lib/deprec/templates/nagios/resource.cfg.erb new file mode 100644 index 0000000..bee7a78 --- /dev/null +++ b/lib/deprec/templates/nagios/resource.cfg.erb @@ -0,0 +1,34 @@ +########################################################################### +# +# RESOURCE.CFG - Sample Resource File for Nagios 3.0b7 +# +# Last Modified: 09-10-2003 +# +# You can define $USERx$ macros in this file, which can in turn be used +# in command definitions in your host config file(s). $USERx$ macros are +# useful for storing sensitive information such as usernames, passwords, +# etc. They are also handy for specifying the path to plugins and +# event handlers - if you decide to move the plugins or event handlers to +# a different directory in the future, you can just update one or two +# $USERx$ macros, instead of modifying a lot of command definitions. +# +# The CGIs will not attempt to read the contents of resource files, so +# you can set restrictive permissions (600 or 660) on them. +# +# Nagios supports up to 32 $USERx$ macros ($USER1$ through $USER32$) +# +# Resource files may also be used to store configuration directives for +# external data sources like MySQL... +# +########################################################################### + +# Sets $USER1$ to be the path to the plugins +$USER1$=/usr/local/nagios/libexec + +# Sets $USER2$ to be the path to event handlers +#$USER2$=/usr/local/nagios/libexec/eventhandlers + +# Store some usernames and passwords (hidden from the CGIs) +#$USER3$=someuser +#$USER4$=somepassword + diff --git a/lib/deprec/templates/nagios/services.cfg.erb b/lib/deprec/templates/nagios/services.cfg.erb new file mode 100644 index 0000000..5d888ba --- /dev/null +++ b/lib/deprec/templates/nagios/services.cfg.erb @@ -0,0 +1,7 @@ +# define service{ +# use local-service +# service_description HTTP +# check_command check_http +# notifications_enabled 0 +# hostgroup_name web +# } \ No newline at end of file diff --git a/lib/deprec/templates/nagios/templates.cfg.erb b/lib/deprec/templates/nagios/templates.cfg.erb new file mode 100644 index 0000000..16a980d --- /dev/null +++ b/lib/deprec/templates/nagios/templates.cfg.erb @@ -0,0 +1,190 @@ +############################################################################### +# TEMPLATES.CFG - SAMPLE OBJECT TEMPLATES +# +# Last Modified: 10-03-2007 +# +# NOTES: This config file provides you with some example object definition +# templates that are refered by other host, service, contact, etc. +# definitions in other config files. +# +# You don't need to keep these definitions in a separate file from your +# other object definitions. This has been done just to make things +# easier to understand. +# +############################################################################### + + + +############################################################################### +############################################################################### +# +# CONTACT TEMPLATES +# +############################################################################### +############################################################################### + +# Generic contact definition template - This is NOT a real contact, just a template! + +define contact{ + name generic-contact ; The name of this contact template + service_notification_period 24x7 ; service notifications can be sent anytime + host_notification_period 24x7 ; host notifications can be sent anytime + service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events + host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events + service_notification_commands notify-service-by-email ; send service notifications via email + host_notification_commands notify-host-by-email ; send host notifications via email + register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE! + } + + + + +############################################################################### +############################################################################### +# +# HOST TEMPLATES +# +############################################################################### +############################################################################### + +# Generic host definition template - This is NOT a real host, just a template! + +define host{ + name generic-host ; The name of this host template + notifications_enabled 1 ; Host notifications are enabled + event_handler_enabled 1 ; Host event handler is enabled + flap_detection_enabled 1 ; Flap detection is enabled + failure_prediction_enabled 1 ; Failure prediction is enabled + process_perf_data 1 ; Process performance data + retain_status_information 1 ; Retain status information across program restarts + retain_nonstatus_information 1 ; Retain non-status information across program restarts + notification_period 24x7 ; Send host notifications at any time + register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE! + } + + +# Linux host definition template - This is NOT a real host, just a template! + +define host{ + name linux-server ; The name of this host template + use generic-host ; This template inherits other values from the generic-host template + check_period 24x7 ; By default, Linux hosts are checked round the clock + check_interval 5 ; Actively check the host every 5 minutes + retry_interval 1 ; Schedule host check retries at 1 minute intervals + max_check_attempts 10 ; Check each Linux host 10 times (max) + check_command check-host-alive ; Default command to check Linux hosts + notification_period workhours ; Linux admins hate to be woken up, so we only notify during the day + ; Note that the notification_period variable is being overridden from + ; the value that is inherited from the generic-host template! + notification_interval 120 ; Resend notifications every 2 hours + notification_options d,u,r ; Only send notifications for specific host states + contact_groups admins ; Notifications get sent to the admins by default + register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE! + } + + + +# Windows host definition template - This is NOT a real host, just a template! + +define host{ + name windows-server ; The name of this host template + use generic-host ; Inherit default values from the generic-host template + check_period 24x7 ; By default, Windows servers are monitored round the clock + check_interval 5 ; Actively check the server every 5 minutes + retry_interval 1 ; Schedule host check retries at 1 minute intervals + max_check_attempts 10 ; Check each server 10 times (max) + check_command check-host-alive ; Default command to check if servers are "alive" + notification_period 24x7 ; Send notification out at any time - day or night + notification_interval 30 ; Resend notifications every 30 minutes + notification_options d,r ; Only send notifications for specific host states + contact_groups admins ; Notifications get sent to the admins by default + hostgroups windows-servers ; Host groups that Windows servers should be a member of + register 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE + } + + +# We define a generic printer template that can be used for most printers we monitor + +define host{ + name generic-printer ; The name of this host template + use generic-host ; Inherit default values from the generic-host template + check_period 24x7 ; By default, printers are monitored round the clock + check_interval 5 ; Actively check the printer every 5 minutes + retry_interval 1 ; Schedule host check retries at 1 minute intervals + max_check_attempts 10 ; Check each printer 10 times (max) + check_command check-host-alive ; Default command to check if printers are "alive" + notification_period workhours ; Printers are only used during the workday + notification_interval 30 ; Resend notifications every 30 minutes + notification_options d,r ; Only send notifications for specific host states + contact_groups admins ; Notifications get sent to the admins by default + register 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE + } + + +# Define a template for switches that we can reuse +define host{ + name generic-switch ; The name of this host template + use generic-host ; Inherit default values from the generic-host template + check_period 24x7 ; By default, switches are monitored round the clock + check_interval 5 ; Switches are checked every 5 minutes + retry_interval 1 ; Schedule host check retries at 1 minute intervals + max_check_attempts 10 ; Check each switch 10 times (max) + check_command check-host-alive ; Default command to check if routers are "alive" + notification_period 24x7 ; Send notifications at any time + notification_interval 30 ; Resend notifications every 30 minutes + notification_options d,r ; Only send notifications for specific host states + contact_groups admins ; Notifications get sent to the admins by default + register 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE + } + + + + +############################################################################### +############################################################################### +# +# SERVICE TEMPLATES +# +############################################################################### +############################################################################### + +# Generic service definition template - This is NOT a real service, just a template! + +define service{ + name generic-service ; The 'name' of this service template + active_checks_enabled 1 ; Active service checks are enabled + passive_checks_enabled 1 ; Passive service checks are enabled/accepted + parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems) + obsess_over_service 1 ; We should obsess over this service (if necessary) + check_freshness 0 ; Default is to NOT check service 'freshness' + notifications_enabled 1 ; Service notifications are enabled + event_handler_enabled 1 ; Service event handler is enabled + flap_detection_enabled 1 ; Flap detection is enabled + failure_prediction_enabled 1 ; Failure prediction is enabled + process_perf_data 1 ; Process performance data + retain_status_information 1 ; Retain status information across program restarts + retain_nonstatus_information 1 ; Retain non-status information across program restarts + is_volatile 0 ; The service is not volatile + check_period 24x7 ; The service can be checked at any time of the day + max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state + normal_check_interval 10 ; Check the service every 10 minutes under normal conditions + retry_check_interval 2 ; Re-check the service every two minutes until a hard state can be determined + contact_groups admins ; Notifications get sent out to everyone in the 'admins' group + notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events + notification_interval 60 ; Re-notify about service problems every hour + notification_period 24x7 ; Notifications can be sent out at any time + register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE! + } + + +# Local service definition template - This is NOT a real service, just a template! + +define service{ + name local-service ; The name of this service template + use generic-service ; Inherit default values from the generic-service definition + max_check_attempts 4 ; Re-check the service up to 4 times in order to determine its final (hard) state + normal_check_interval 5 ; Check the service every 5 minutes under normal conditions + retry_check_interval 1 ; Re-check the service every minute until a hard state can be determined + register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE! + } + diff --git a/lib/deprec/templates/nagios/timeperiods.cfg.erb b/lib/deprec/templates/nagios/timeperiods.cfg.erb new file mode 100644 index 0000000..f677e57 --- /dev/null +++ b/lib/deprec/templates/nagios/timeperiods.cfg.erb @@ -0,0 +1,94 @@ +############################################################################### +# TIMEPERIODS.CFG - SAMPLE TIMEPERIOD DEFINITIONS +# +# Last Modified: 05-31-2007 +# +# NOTES: This config file provides you with some example timeperiod definitions +# that you can reference in host, service, contact, and dependency +# definitions. +# +# You don't need to keep timeperiods in a separate file from your other +# object definitions. This has been done just to make things easier to +# understand. +# +############################################################################### + + + +############################################################################### +############################################################################### +# +# TIME PERIODS +# +############################################################################### +############################################################################### + +# This defines a timeperiod where all times are valid for checks, +# notifications, etc. The classic "24x7" support nightmare. :-) +define timeperiod{ + timeperiod_name 24x7 + alias 24 Hours A Day, 7 Days A Week + sunday 00:00-24:00 + monday 00:00-24:00 + tuesday 00:00-24:00 + wednesday 00:00-24:00 + thursday 00:00-24:00 + friday 00:00-24:00 + saturday 00:00-24:00 + } + + +# 'workhours' timeperiod definition +define timeperiod{ + timeperiod_name workhours + alias Normal Work Hours + monday 09:00-17:00 + tuesday 09:00-17:00 + wednesday 09:00-17:00 + thursday 09:00-17:00 + friday 09:00-17:00 + } + + +# 'none' timeperiod definition +define timeperiod{ + timeperiod_name none + alias No Time Is A Good Time + } + + +# Some U.S. holidays +# Note: The timeranges for each holiday are meant to *exclude* the holidays from being +# treated as a valid time for notifications, etc. You probably don't want your pager +# going off on New Year's. Although you're employer might... :-) +define timeperiod{ + name us-holidays + timeperiod_name us-holidays + alias U.S. Holidays + + january 1 00:00-00:00 ; New Years + monday -1 may 00:00-00:00 ; Memorial Day (last Monday in May) + july 4 00:00-00:00 ; Independence Day + monday 1 september 00:00-00:00 ; Labor Day (first Monday in September) + thursday -1 november 00:00-00:00 ; Thanksgiving (last Thursday in November) + december 25 00:00-00:00 ; Christmas + } + + +# This defines a modified "24x7" timeperiod that covers every day of the +# year, except for U.S. holidays (defined in the timeperiod above). +define timeperiod{ + timeperiod_name 24x7_sans_holidays + alias 24x7 Sans Holidays + + use us-holidays ; Get holiday exceptions from other timeperiod + + sunday 00:00-24:00 + monday 00:00-24:00 + tuesday 00:00-24:00 + wednesday 00:00-24:00 + thursday 00:00-24:00 + friday 00:00-24:00 + saturday 00:00-24:00 + } + diff --git a/lib/deprec/templates/network/hostname.erb b/lib/deprec/templates/network/hostname.erb new file mode 100644 index 0000000..8c77693 --- /dev/null +++ b/lib/deprec/templates/network/hostname.erb @@ -0,0 +1 @@ +<%= hostname %> \ No newline at end of file diff --git a/lib/deprec/templates/network/hosts.erb b/lib/deprec/templates/network/hosts.erb new file mode 100644 index 0000000..6ef9479 --- /dev/null +++ b/lib/deprec/templates/network/hosts.erb @@ -0,0 +1,2 @@ +127.0.0.1 localhost +127.0.1.1 <%= hostname %> diff --git a/lib/deprec/templates/network/interfaces.erb b/lib/deprec/templates/network/interfaces.erb new file mode 100644 index 0000000..0799376 --- /dev/null +++ b/lib/deprec/templates/network/interfaces.erb @@ -0,0 +1,22 @@ +# This file describes the network interfaces available on your system +# and how to activate them. For more information, see interfaces(5). + +# The loopback network interface +auto lo +iface lo inet loopback + +# The primary network interface +auto eth0 +iface eth0 inet static + address <%= eth0_ip %> + netmask 255.255.254.0 + broadcast 192.168.1.255 + gateway 192.168.0.1 + dns-nameservers 203.8.183.1 4.2.2.1 + +auto eth1 +iface eth1 inet static + address <%= eth1_ip %> + netmask 255.255.255.0 + broadcast 192.168.1.255 + dns-nameservers 203.8.183.1 4.2.2.1 \ No newline at end of file diff --git a/lib/deprec/templates/nginx/mime.types.erb b/lib/deprec/templates/nginx/mime.types.erb new file mode 100644 index 0000000..3031cf6 --- /dev/null +++ b/lib/deprec/templates/nginx/mime.types.erb @@ -0,0 +1,70 @@ + +types { + text/html html htm shtml; + text/css css; + text/xml xml rss; + image/gif gif; + image/jpeg jpeg jpg; + application/x-javascript js; + application/atom+xml atom; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/png png; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + image/svg+xml svg; + + application/java-archive jar war ear; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.ms-excel xls; + application/vnd.ms-powerpoint ppt; + application/vnd.wap.wmlc wmlc; + application/vnd.wap.xhtml+xml xhtml; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream eot; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mpeg mpeg mpg; + video/quicktime mov; + video/x-flv flv; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} diff --git a/lib/deprec/templates/nginx/nginx-init-script b/lib/deprec/templates/nginx/nginx-init-script new file mode 100644 index 0000000..0563eb3 --- /dev/null +++ b/lib/deprec/templates/nginx/nginx-init-script @@ -0,0 +1,62 @@ +#! /bin/sh + +### BEGIN INIT INFO +# Provides: nginx +# Required-Start: $all +# Required-Stop: $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts the nginx web server +# Description: starts nginx using start-stop-daemon +### END INIT INFO + +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +DAEMON=/usr/local/sbin/nginx +NAME=nginx +DESC=nginx + +test -x $DAEMON || exit 0 + +# Include nginx defaults if available +if [ -f /etc/default/nginx ] ; then + . /etc/default/nginx +fi + +set -e + +case "$1" in + start) + echo -n "Starting $DESC: " + start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \ + --exec $DAEMON -- $DAEMON_OPTS + echo "$NAME." + ;; + stop) + echo -n "Stopping $DESC: " + start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \ + --exec $DAEMON + echo "$NAME." + ;; + restart|force-reload) + echo -n "Restarting $DESC: " + start-stop-daemon --stop --quiet --pidfile \ + /usr/local/nginx/logs/$NAME.pid --exec $DAEMON + sleep 1 + start-stop-daemon --start --quiet --pidfile \ + /usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS + echo "$NAME." + ;; + reload) + echo -n "Reloading $DESC configuration: " + start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \ + --exec $DAEMON + echo "$NAME." + ;; + *) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 + exit 1 + ;; + esac + + exit 0 diff --git a/lib/deprec/templates/nginx/nginx.conf.erb b/lib/deprec/templates/nginx/nginx.conf.erb new file mode 100644 index 0000000..e6b9cbf --- /dev/null +++ b/lib/deprec/templates/nginx/nginx.conf.erb @@ -0,0 +1,118 @@ + +#user nobody; +worker_processes 1; + +#error_log logs/error.log; +#error_log logs/error.log notice; +#error_log logs/error.log info; + +#pid logs/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /usr/local/nginx/conf/vhosts/*.conf; + include conf/mime.types; + default_type application/octet-stream; + + #log_format main '$remote_addr - $remote_user [$time_local] $request ' + # '"$status" $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #access_log logs/access.log main; + + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 65; + + #gzip on; + + server { + listen 80; + server_name _ *; + + #charset koi8-r; + + #access_log logs/host.access.log main; + + location / { + root html; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include conf/fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + + + # another virtual host using mix of IP-, name-, and port-based configuration + # + #server { + # listen 8000; + # listen somename:8080; + # server_name somename alias another.alias; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + + + # HTTPS server + # + #server { + # listen 443; + # server_name localhost; + + # ssl on; + # ssl_certificate cert.pem; + # ssl_certificate_key cert.key; + + # ssl_session_timeout 5m; + + # ssl_protocols SSLv2 SSLv3 TLSv1; + # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; + # ssl_prefer_server_ciphers on; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + +} diff --git a/lib/deprec/templates/nginx/nginx.logrotate.d b/lib/deprec/templates/nginx/nginx.logrotate.d new file mode 100644 index 0000000..1bb7012 --- /dev/null +++ b/lib/deprec/templates/nginx/nginx.logrotate.d @@ -0,0 +1,12 @@ +/var/log/engineyard/nginx/*.log { + daily + missingok + rotate 28 + compress + notifempty + sharedscripts + extension gz + postrotate + [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid` + endscript +} \ No newline at end of file diff --git a/lib/deprec/templates/nginx/nothing.conf b/lib/deprec/templates/nginx/nothing.conf new file mode 100644 index 0000000..5679231 --- /dev/null +++ b/lib/deprec/templates/nginx/nothing.conf @@ -0,0 +1 @@ +# This dir is for vhost config files \ No newline at end of file diff --git a/lib/deprec/templates/nginx/rails_nginx_vhost.conf.erb b/lib/deprec/templates/nginx/rails_nginx_vhost.conf.erb new file mode 100644 index 0000000..7635abf --- /dev/null +++ b/lib/deprec/templates/nginx/rails_nginx_vhost.conf.erb @@ -0,0 +1,41 @@ +upstream <%= application %> { +<% mongrel_servers.times do |counter| -%> + <%= "server 127.0.0.1:#{8000+counter};" %> +<% end -%> +} + +server { + listen 80; + server_name <%= domain %> <% 4.times do |counter| %> <%= domain.sub(/.*?\./, "assets#{counter}.") %><% end %>; + root <%= deploy_to %>/current/public; + access_log <%= deploy_to %>/shared/log/<%= domain %>-access.log; + error_log <%= deploy_to %>/shared/log/<%= domain %>-error.log; + client_max_body_size <%= nginx_client_max_body_size %>; + + if (-f $document_root/system/maintenance.html){ + rewrite ^(.*)$ /system/maintenance.html last; + break; + } + location / { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect false; + + if (-f $request_filename/index.html) { + rewrite (.*) $1/index.html break; + } + if (-f $request_filename.html) { + rewrite (.*) $1.html break; + } + if (!-f $request_filename) { + proxy_pass http://<%= application %>; + break; + } + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } +} diff --git a/lib/deprec/templates/ntp/ntp.conf.erb b/lib/deprec/templates/ntp/ntp.conf.erb new file mode 100644 index 0000000..214d226 --- /dev/null +++ b/lib/deprec/templates/ntp/ntp.conf.erb @@ -0,0 +1,42 @@ +# /etc/ntp.conf, configuration for ntpd + +driftfile /var/lib/ntp/ntp.drift + +# Enable this if you want statistics to be logged. +#statsdir /var/log/ntpstats/ + +statistics loopstats peerstats clockstats +filegen loopstats file loopstats type day enable +filegen peerstats file peerstats type day enable +filegen clockstats file clockstats type day enable + + +# You do need to talk to an NTP server or two (or three). +server ntp.ubuntu.com +server 0.pool.ntp.org +server 1.pool.ntp.org +server 2.pool.ntp.org +server pool.ntp.org + +# By default, exchange time with everybody, but don't allow configuration. +# See /usr/share/doc/ntp-doc/html/accopt.html for details. +restrict -4 default kod notrap nomodify nopeer noquery +restrict -6 default kod notrap nomodify nopeer noquery + +# Local users may interrogate the ntp server more closely. +restrict 127.0.0.1 +restrict ::1 + +# Clients from this (example!) subnet have unlimited access, +# but only if cryptographically authenticated +#restrict 192.168.123.0 mask 255.255.255.0 notrust + +# If you want to provide time to your local subnet, change the next line. +# (Again, the address is an example only.) +#broadcast 192.168.123.255 + +# If you want to listen to time broadcasts on your local subnet, +# de-comment the next lines. Please do this only if you trust everybody +# on the network! +#disable auth +#broadcastclient \ No newline at end of file diff --git a/lib/deprec/templates/postfix/aliases.erb b/lib/deprec/templates/postfix/aliases.erb new file mode 100644 index 0000000..eded6fb --- /dev/null +++ b/lib/deprec/templates/postfix/aliases.erb @@ -0,0 +1,3 @@ +# See man 5 aliases for format +postmaster: root + diff --git a/lib/deprec/templates/postfix/dynamicmaps.cf.erb b/lib/deprec/templates/postfix/dynamicmaps.cf.erb new file mode 100644 index 0000000..837c78a --- /dev/null +++ b/lib/deprec/templates/postfix/dynamicmaps.cf.erb @@ -0,0 +1,8 @@ +# Postfix dynamic maps configuration file. +# +# The first match found is the one that is used. Wildcards are not supported +# as of postfix 2.0.2 +# +#type location of .so file open function (mkmap func) +#==== ================================ ============= ============ +tcp /usr/lib/postfix/dict_tcp.so dict_tcp_open diff --git a/lib/deprec/templates/postfix/main.cf.erb b/lib/deprec/templates/postfix/main.cf.erb new file mode 100644 index 0000000..9b45746 --- /dev/null +++ b/lib/deprec/templates/postfix/main.cf.erb @@ -0,0 +1,41 @@ +# See /usr/share/postfix/main.cf.dist for a commented, more complete version + +# Debian specific: Specifying a file name will cause the first +# line of that file to be used as the name. The Debian default +# is /etc/mailname. +#myorigin = /etc/mailname + +smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) +biff = no + +# appending .domain is the MUA's job. +append_dot_mydomain = no + +# Uncomment the next line to generate "delayed mail" warnings +#delay_warning_time = 4h + +# TLS parameters +smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem +smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key +smtpd_use_tls=yes +smtpd_tls_session_cache_database = btree:${queue_directory}/smtpd_scache +smtp_tls_session_cache_database = btree:${queue_directory}/smtp_scache + +# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for +# information on enabling SSL in the smtp client. + +myhostname = dn.blocksglobal.com +alias_maps = hash:/etc/aliases +alias_database = hash:/etc/aliases +myorigin = /etc/mailname + +# deprec - XXX add something like this to template file +# +# mydestination = <%# postfix_destination_domains * ', ' %>, localhost.localdomain, localhost +mydestination = dn.blocksglobal.com, localhost.blocksglobal.com, , localhost + +relayhost = +mynetworks = 127.0.0.0/8 +mailbox_size_limit = 0 +recipient_delimiter = + +inet_interfaces = all diff --git a/lib/deprec/templates/postfix/master.cf.erb b/lib/deprec/templates/postfix/master.cf.erb new file mode 100644 index 0000000..2fb53ad --- /dev/null +++ b/lib/deprec/templates/postfix/master.cf.erb @@ -0,0 +1,77 @@ +# +# Postfix master process configuration file. For details on the format +# of the file, see the master(5) manual page (command: "man 5 master"). +# +# ========================================================================== +# service type private unpriv chroot wakeup maxproc command + args +# (yes) (yes) (yes) (never) (100) +# ========================================================================== +smtp inet n - - - - smtpd +#submission inet n - - - - smtpd +# -o smtpd_enforce_tls=yes +# -o smtpd_sasl_auth_enable=yes +# -o smtpd_client_restrictions=permit_sasl_authenticated,reject +#smtps inet n - - - - smtpd +# -o smtpd_tls_wrappermode=yes +# -o smtpd_sasl_auth_enable=yes +# -o smtpd_client_restrictions=permit_sasl_authenticated,reject +#628 inet n - - - - qmqpd +pickup fifo n - - 60 1 pickup +cleanup unix n - - - 0 cleanup +qmgr fifo n - n 300 1 qmgr +#qmgr fifo n - - 300 1 oqmgr +tlsmgr unix - - - 1000? 1 tlsmgr +rewrite unix - - - - - trivial-rewrite +bounce unix - - - - 0 bounce +defer unix - - - - 0 bounce +trace unix - - - - 0 bounce +verify unix - - - - 1 verify +flush unix n - - 1000? 0 flush +proxymap unix - - n - - proxymap +smtp unix - - - - - smtp +# When relaying mail as backup MX, disable fallback_relay to avoid MX loops +relay unix - - - - - smtp + -o smtp_fallback_relay= +# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5 +showq unix n - - - - showq +error unix - - - - - error +retry unix - - - - - error +discard unix - - - - - discard +local unix - n n - - local +virtual unix - n n - - virtual +lmtp unix - - - - - lmtp +anvil unix - - - - 1 anvil +scache unix - - - - 1 scache +# +# ==================================================================== +# Interfaces to non-Postfix software. Be sure to examine the manual +# pages of the non-Postfix software to find out what options it wants. +# +# Many of the following services use the Postfix pipe(8) delivery +# agent. See the pipe(8) man page for information about ${recipient} +# and other message envelope options. +# ==================================================================== +# +# maildrop. See the Postfix MAILDROP_README file for details. +# Also specify in main.cf: maildrop_destination_recipient_limit=1 +# +maildrop unix - n n - - pipe + flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient} +# +# See the Postfix UUCP_README file for configuration details. +# +uucp unix - n n - - pipe + flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient) +# +# Other external delivery methods. +# +ifmail unix - n n - - pipe + flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient) +bsmtp unix - n n - - pipe + flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient +scalemail-backend unix - n n - 2 pipe + flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension} +mailman unix - n n - - pipe + flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py + ${nexthop} ${user} + diff --git a/lib/deprec/templates/ssh/ssh_config.erb b/lib/deprec/templates/ssh/ssh_config.erb new file mode 100644 index 0000000..34abacc --- /dev/null +++ b/lib/deprec/templates/ssh/ssh_config.erb @@ -0,0 +1,50 @@ + +# This is the ssh client system-wide configuration file. See +# ssh_config(5) for more information. This file provides defaults for +# users, and the values can be changed in per-user configuration files +# or on the command line. + +# Configuration data is parsed as follows: +# 1. command line options +# 2. user-specific file +# 3. system-wide file +# Any configuration value is only changed the first time it is set. +# Thus, host-specific definitions should be at the beginning of the +# configuration file, and defaults at the end. + +# Site-wide defaults for some commonly used options. For a comprehensive +# list of available options, their meanings and defaults, please see the +# ssh_config(5) man page. + +Host * +# ForwardAgent no +# ForwardX11 no +# ForwardX11Trusted yes +# RhostsRSAAuthentication no +# RSAAuthentication yes +# PasswordAuthentication yes +# HostbasedAuthentication no +# GSSAPIAuthentication no +# GSSAPIDelegateCredentials no +# GSSAPIKeyExchange no +# GSSAPITrustDNS no +# BatchMode no +# CheckHostIP yes +# AddressFamily any +# ConnectTimeout 0 +# StrictHostKeyChecking ask +# IdentityFile ~/.ssh/identity +# IdentityFile ~/.ssh/id_rsa +# IdentityFile ~/.ssh/id_dsa +# Port 22 +# Protocol 2,1 +# Cipher 3des +# Ciphers aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc +# EscapeChar ~ +# Tunnel no +# TunnelDevice any:any +# PermitLocalCommand no + SendEnv LANG LC_* + HashKnownHosts yes + GSSAPIAuthentication yes + GSSAPIDelegateCredentials no diff --git a/lib/deprec/templates/ssh/sshd_config.erb b/lib/deprec/templates/ssh/sshd_config.erb new file mode 100644 index 0000000..fe842db --- /dev/null +++ b/lib/deprec/templates/ssh/sshd_config.erb @@ -0,0 +1,78 @@ +# Package generated configuration file +# See the sshd(8) manpage for details + +# What ports, IPs and protocols we listen for +Port 22 +# Use these options to restrict which interfaces/protocols sshd will bind to +#ListenAddress :: +#ListenAddress 0.0.0.0 +Protocol 2 +# HostKeys for protocol version 2 +HostKey /etc/ssh/ssh_host_rsa_key +HostKey /etc/ssh/ssh_host_dsa_key +#Privilege Separation is turned on for security +UsePrivilegeSeparation yes + +# Lifetime and size of ephemeral version 1 server key +KeyRegenerationInterval 3600 +ServerKeyBits 768 + +# Logging +SyslogFacility AUTH +LogLevel INFO + +# Authentication: +LoginGraceTime 120 +PermitRootLogin no +StrictModes yes + +RSAAuthentication yes +PubkeyAuthentication yes +#AuthorizedKeysFile %h/.ssh/authorized_keys + +# Don't read the user's ~/.rhosts and ~/.shosts files +IgnoreRhosts yes +# For this to work you will also need host keys in /etc/ssh_known_hosts +RhostsRSAAuthentication no +# similar for protocol version 2 +HostbasedAuthentication no +# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication +#IgnoreUserKnownHosts yes + +# To enable empty passwords, change to yes (NOT RECOMMENDED) +PermitEmptyPasswords no + +# Change to yes to enable challenge-response passwords (beware issues with +# some PAM modules and threads) +ChallengeResponseAuthentication no + +# Change to no to disable tunnelled clear text passwords +PasswordAuthentication no + +# Kerberos options +#KerberosAuthentication no +#KerberosGetAFSToken no +#KerberosOrLocalPasswd yes +#KerberosTicketCleanup yes + +# GSSAPI options +#GSSAPIAuthentication no +#GSSAPICleanupCredentials yes + +X11Forwarding yes +X11DisplayOffset 10 +PrintMotd no +PrintLastLog yes +TCPKeepAlive yes +#UseLogin no + +#MaxStartups 10:30:60 +#Banner /etc/issue.net + +# Allow client to pass locale environment variables +AcceptEnv LANG LC_* + +Subsystem sftp /usr/lib/openssh/sftp-server + +UsePAM no +UseDNS no \ No newline at end of file diff --git a/lib/deprec/templates/subversion/svn.apache.vhost.erb b/lib/deprec/templates/subversion/svn.apache.vhost.erb new file mode 100644 index 0000000..3ce5467 --- /dev/null +++ b/lib/deprec/templates/subversion/svn.apache.vhost.erb @@ -0,0 +1,43 @@ + + ServerName <%= @username %>.svn.engineyard.com + ServerAdmin admin@engineyard.com + + + DAV svn + + Satisfy Any + Require valid-user + + AuthType Basic + AuthName "Engine Yard SVN Cluster: <%= @username %>" + AuthUserFile /data/svn/<%= @username %>/users + + AuthzSVNAccessFile /data/svn/<%= @username %>/access + + SVNPath /data/svn/<%= @username %>/repo + + + + + ServerName <%= @username %>.svn.engineyard.com + ServerAdmin admin@engineyard.com + + + DAV svn + + Satisfy Any + Require valid-user + + AuthType Basic + AuthName "Engine Yard SVN Cluster: <%= @username %>" + AuthUserFile /data/svn/<%= @username %>/users + + AuthzSVNAccessFile /data/svn/<%= @username %>/access + + SVNPath /data/svn/<%= @username %>/repo + + + SSLEngine on + SSLProtocol all + SSLCipherSuite HIGH:MEDIUM + \ No newline at end of file diff --git a/lib/deprec/templates/trac/apache_vhost.conf.erb b/lib/deprec/templates/trac/apache_vhost.conf.erb new file mode 100644 index 0000000..4e7fb17 --- /dev/null +++ b/lib/deprec/templates/trac/apache_vhost.conf.erb @@ -0,0 +1,24 @@ + + ServerName <%= trac_home_url %> + + # Configure trac_cluster + + BalancerMember http://127.0.0.1:<%= tracd_port %> + + + RewriteEngine On + + # Redirect to the AGR track instance + RewriteRule ^/$ /<%= application %>/ [R] + # Send all traffic to tracd + RewriteRule ^/(.*)$ balancer://trac_cluster%{REQUEST_URI} [P,QSA,L] + + # Deflate + AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript + BrowserMatch ^Mozilla/4 gzip-only-text/html + BrowserMatch ^Mozilla/4\.0[678] no-gzip + BrowserMatch \bMSIE !no-gzip !gzip-only-text/html + + ErrorLog logs/trac.agoodride.tv-error_log + CustomLog logs/trac.agoodride.tv-access_log combined + \ No newline at end of file diff --git a/lib/deprec/templates/trac/trac.ini.erb b/lib/deprec/templates/trac/trac.ini.erb new file mode 100644 index 0000000..08c071c --- /dev/null +++ b/lib/deprec/templates/trac/trac.ini.erb @@ -0,0 +1,106 @@ +# -*- coding: utf-8 -*- + +[attachment] +max_size = 262144 +render_unsafe_content = false + +[browser] +downloadable_paths = /trunk, /branches/*, /tags/* +hide_properties = svk:merge +render_unsafe_content = false + +[changeset] +max_diff_bytes = 10000000 +max_diff_files = 0 +wiki_format_messages = true + +[header_logo] +alt = +height = -1 +link = <%= trac_header_logo_link %> +src = common/trac_banner.png +width = -1 + +[logging] +log_file = trac.log +# log_format = +log_level = DEBUG +log_type = none + +[mimeviewer] +enscript_modes = text/x-dylan:dylan:4 +enscript_path = enscript +max_preview_size = 262144 +mime_map = text/x-dylan:dylan,text/x-idl:ice,text/x-ada:ads:adb +php_path = php +silvercity_modes = +tab_width = 8 + +[notification] +always_notify_owner = <%= trac_always_notify_owner.to_s %> +always_notify_reporter = <%= trac_always_notify_reporter.to_s %> +always_notify_updater = <%= trac_always_notify_updater.to_s %> +mime_encoding = base64 +smtp_always_bcc = <%= trac_smtp_always_bcc %> +smtp_always_cc = <%= trac_smtp_always_cc %> +smtp_default_domain = <%= trac_smtp_default_domain %> +smtp_enabled = <%= trac_smtp_enabled.to_s %> +smtp_from = <%= trac_smtp_from %> +smtp_password = <%= trac_smtp_password %> +smtp_port = <%= trac_smtp_port %> +smtp_replyto = <%= trac_smtp_replyto %> +smtp_server = <%= trac_smtp_server %> +smtp_subject_prefix = <%= trac_smtp_subject_prefix %> +smtp_user = <%= trac_smtp_user %> +use_public_cc = <%= trac_use_public_cc.to_s %> +use_short_addr = <%= trac_use_short_addr.to_s %> +use_tls = <%= trac_use_tls.to_s %> + +[project] +descr = <%= trac_desc %> +footer = Visit the Trac open source project at
http://trac.edgewall.org/ +icon = common/trac.ico +name = <%= application %> +url = http://<%= domain %>/ + +[search] +min_query_length = 3 + +[ticket] +default_component = +default_milestone = +default_priority = major +default_type = defect +default_version = +restrict_owner = false + +[timeline] +changeset_long_messages = false +changeset_show_files = 0 +default_daysback = 30 +ticket_show_details = false + +[trac] +authz_file = +authz_module_name = +base_url = <%= trac_base_url %> +check_auth_ip = true +database = sqlite:db/trac.db +default_charset = iso-8859-15 +default_handler = WikiModule +htdocs_location = +ignore_auth_case = false +mainnav = wiki,timeline,roadmap,browser,tickets,newticket,search +metanav = login,logout,settings,help,about +permission_store = DefaultPermissionStore +repository_dir = <%= repos_root %> +repository_type = svn +# request_filters = +# templates_dir = +timeout = 20 + +[wiki] +ignore_missing_pages = false +render_unsafe_content = false +split_page_names = false + diff --git a/lib/deprec/templates/trac/trac_deprec.png b/lib/deprec/templates/trac/trac_deprec.png new file mode 100644 index 0000000000000000000000000000000000000000..e613b172e00376b8e56f387e6e558cccfcf51fa4 GIT binary patch literal 9743 zcmW+*1yoy27fcJqy|@*3*Wwaf3j}u!Qi?-ycPqu+iWPU4Lh$0n-L1G6```EH$;=5D4}Cf7csO zMiwCmgraH#27mfw?cnO*V(s8aArA&qI66C6*?hJHfxa$fYd|3yhxj6QYuA#B5dlex z4(fPF6zY=E0k{ctOq9r23K5j~i+F0ku%)HpNrv(w;Ns!}V(`>h(4tTl5O*jG;(`k! zqDCG!y$kK;I_~zyUK-~`_baZl>n9L#xF zqix#4gaAuQRAfpdRJS9uCs*SIi^Hbb~hmA#ZwI6Fw>;1>l0j zz2YQ`LE+b2GpJ`A3$+e}ga+bJiwI=|!Fz*DhN!8( zfS=t@)GcX)m}Y+9ml8|ALol}!Z2n%>PC2_GBewL*_|kN6bFGeUHztBSlH`{ z1B4I)>|Y9KPvNbNQ1jgGqOIyM#T!9+hfCU5j{n6*I{#bi;^OYk&Vm9=Qr~n$+xG?9 zYuuy#{Q1F8`04Iuqic&MkjpSo7XE&t_xH6@5$VKtjjiY#?*!ITLvy%WMS3h9*Pg9A z5a_bq;nyDqB)9}esCI!~1iTpup1h2iVl@ActXjQmFb{?9WbgFtaPN@pP+sbzWSfaQ{kYfIVo)EkRUq2M+U40ruuS8U&@9YQ zUoFjtVDrZ7Nmk}JsaLCom%it5%Mcg~#+O$tsw_yJA+{#4zO$)5aBah0O(s`Koz$Kl zJ(N92J%GFRKtm713m%MsG7x1FA`(K0JP51Pl!}RFqKO6}9Q>TeY5VDz=?UMG`Tgl%aH%1lxzOX{&cKCq5&-v zDh>Y$Ep>p1{qWO$jzrMyQ|eO%|4_@THQw$Rpg=Vzs{hJDX@_1O<`&2cqpKZT^l@iu zPkSb7j~4k^mM;M2R^ZmISHDWK5<}chbGpxRRYBfoC`rBYi(11yW87jSDdtgX<+L=g z`FS;s6cN(FAI$yf0wMI7EFySQ z#rD&#h$O#V%A@;B$!S_nmr+2Dl0(UwXXpMuQeXCG$g};wk{ekx9fW!`8iZxEaYEsK zUMB}(GWNmc3pKD|pE$V4G}$zDGbEvPO1N-VCRPSB#%91^n`Ya7zjcKSi#s_I&Y>3=RDVb=6>dU=6bV<-d8=ArqZSsOZmDTy<*+d zrj9S6dIGvdI+}Wh^)i*&m9%s1mF*?iC9NunD&;wI(7u|Brs1ZtW}=$i1%&0QCi^B| zQ>YmMw7I{k?=-P9(YMVv_E`iGJ$wUqwVmDh7?RrHZm;k_@a4b?zv*-Z&Xa4~iJ|5ubJ(p{_^ET$3EGwO zHO)mHKkrP>2t;p1opZNEw}tuFxYl%yfAjY=4>gaf_BrGjhpvPDsb4K#y}W= zpm33a5`p?}AMd?lRNWV)9xg@Fe1cDuZ@^RZ?0H{ry%+dAFZ7o-l5M z5&FsRU~Ur8bk8)p&kv10G(1#0Of1eZLWg*YGnLn4Y6a}FF7;0;MQSY*%Bd<)&8oo5 zB>I!hR(OfOji*g)fXzzx_pDB~j{IjuQUNxmD!wnDyVjphuEMvnw@|me3DVey3>`i5 z$9u0sOYqCsa99LW#FZjcJ|>+@U@?{A$IxEB_n?hK@$4n*g;KFk@l8c6fDM?)RW9Y2 zl)b+HP3YkDr0M4_V%cpCp)dQ^p@goqnkkrrpW#kn&m|(*$r=1T;hU4>PfF#)Cg>4# z&&qwY!ZNh(rT!)w~BYVtSC*A#Rm{QhIuB$I;f?#Rrgrrh(Jnt4)fT_ z@A{GDZ~R$jxvwWUy*QiSn~K5|wOPq@_BtzU1?q&IJeN_n@!m0qX(3byw?s8D+0Uw$ zpJ=C6`E}BHDcc1a{Td1S)%eEl7*!KxH`ModW&XraRfk=7z0vevST>0$USw1i?lM6t zp8o>F%GX_zaEFoZ^p&KBvT|6f#e~(g)#2V6YmPof%FoojRE#g^i%SjY>sk#bH@DKu z?5Sf6%k9BU;MT%!;g$}|lHu_&Au-4g$Tj32gzt2Ewb69`{>#)UiFd~>&)?Z){f@h5 z(c!LT%{Q9LvsSZ~kMfW8cVbnMKM(Iy9_TLA3x;rGv;U8bU?)1FCf1R7n5fEAJyz+9m>%Y5M$6xhxrhgtEZC~`D zKdtOg?J&L;Kap4juZGWx>A$QjoUQoV_ITu7O|8h@A%q4`yd>PjV}jqsr^k6;IsSP&mPZ@Po+)er(UKecH8?DJssFn!aQ<%%CD}z8@v>;GGFbMSU3XF#!kQ)aGbYubo38sNS1Pm3CP!_zuDe8klB}4V;9q~M=~i+2`o+r3fl}kEG_!Rpg+}~T$pC`&x?t= z*(#obCAgQab#V!z>8o9`YNOZQl8oGqkO8hUB-{M_j|>|T1_-T~-1YwclS*i4edKIK z0%!Z1o@tHqMs_ESciz6D$MwLQCWr#*<3<3S2+Co#rrJs5dxOQ6si|#@j}fzp3{S_# z0^Htw(EV|@>ozzHvm5v$mFxoB333pR-Mk=8>i@sWU^A?{_x-Xd=~`42x8~6!QE}Sy zN#E{5zj{_ZGt=A9LrF~ydvG#WD>ayxDdXF*2g?^0@w5XY%VU z6%`c{Iy$YG*!o52$4S~D|5ycKnRvRbY>#`J7atIfib@L_`BSFoS1=fE-S>`c-RBD3 z`}Xf9Eb={Jtjr+6W=}P^Vy})X>*-lyNn~@*V@>#*T+4m6KX%ghAUlg4hkqNQqM|&! zyaHVyM6Y)^`lzsfKbhjBq&E1>;QN~F!Kb@7kDiW^KW2mxG082S?l0o1VSzc>=E+sM zU>E6kOMgF)v+Dgh84205V)8hVtaoSC=65J=t@wR`K-%&E`L$QBJ@#rmJVbGxAbXz8 zQ>KV#Ggk?Iz8vMjBY36a-El_nKYt^^$QZ}J*)v96yJQ<_Xt>aMedh1NN829+0RCIw`YZz_%}i4jYf%jopVuW zNNxL7wPB(4p?an#+tc%zoT0(N>)-m$+dLA!&pjq3k*}ld-8;Y2xwWdt(z(N*o_sJq zh^}lt!y#hOu(6F(jal=2Pfs5X|KK-Nrcu)3^S}ktC{{9kygfM?nY3;6c|2*}+1dG) zmr+cSOE2$FL^!y*BWMhBU13SCWa{XqM{g+FEeCtK7{FlGFYIvk%0_wQ6brPRS zirjSKtX2i{eI9R*qjWy_UMGwRUtC=5{j0C5`}`dyRS^>tgE2g>8N{kvC&fV=Tkv>v zeK^y*Go09N*qoS{_{rG#j6zG+nuQHNZrwfe9r7)6a*$OYLgpP&W`&5o8JZhnzRwC)NfXCbaOjN5LBM<=PsDhT;GdAaW*$E6L5w(S55wbr7za2bzdqB z+DW^Q4`1uCHhOxVOpo$?`BC-*-q40oTkP>~n_6MALebbUFE1}rP|wwbm_rVxTi9?S z{hflo*z>i9k?)OWX4ubnsQ4VvanhsXWA7j1nV#r18fJ!iU0DOYy%^O5o&T72mz&%^ zwc$#!!1R1#v|`@4m8ia&H5s?xwjBzGN=`A>^4TxJfLWze1+0D(zJ-JHF6y+gu_3kL z7SA{zVXi)3^FF(=_HADGYwu&SMsH)*X3*_yn~`Mex+Q**m!B(2Q3|7QZa}d9=-*|i zr%}#Ix8(acnVeE^Fn`vTsYmJ)AeY8tgF{3_gl|JhNr^@-oHjHhhk!}0 zq@zQaoSd8`=ATm!odA+yu`D`e%G#no3h(n;$0C*Q_CPF)epAKZ z)F)KiIPxNZ3w`KRJ{t$d$M;LRKpioVYkyKTP3unD@VLJ}&JQQA(_tSO89BPnSy<5V z@$qS6sdW`3qot*F?@j{NoS2XxVPZnzvOjLQ*5Qdp`f>7h!~KHlYJURY+-$xpODijN zEiJ2*D80&*P*j4Y)l`o)Px`(vbn}H8)30B@=1p0*IPap^HfEeG|A(#_^SzgKvf3&# zVTQK6@=Shx+7yq^6^2(-`{(EGHos5_)Em9|K`$C5TcWl}tC($;qbcs+^SN1!yH@r} zm(yWKNT#NyXk>y(fpCahJ3FxcXaZyu6fWcLv#!U52AlU9B`POL9du}f90AIieAq-p z^6BW>oSjA!hchMea&n-JSpGHfWv`98KuT~}jn|FsRcGbq@$u+nKKPBCynLLT{M^v-hIWy)wY3%ByVVm&XA=Vh0|g~z;L(w-R;3=TUeuS>HqC49Q421_ zTES04CrhH$Gu8~cjZyk9|K{CcIH>W0vhj36 zLL?p@cVA|8b#;e-%s}82^`C zjuck+Rs!qWC}P`QXsVh}nFVA*q;O$8uL7otf{$Zfe10wO(Ts zz-@vHW{843&59OWZ=t_y$~iiH{KG^5uCSrcm0n z2JG!YV%Fz7!9U3{Xx3MkU=0nY_{dsM<4+1GsOPkg-~#AqjES zqY4HR5>|F|P0hEdLfL3NjDu4H<=^h{*wiu~b*9P840XG63bc)P9d!uj^*qJUbUIq3 zofiY6*t@J#_qe`tV3%v_CkL30rZ&T7twXgXWa+5;*)o}*?dC@ov;4sq}fDOrb2jioeR1f-B>$~@?4ULS(|J@u*%Xe#* zYh8pS|3d2N@0W)7=H%osB#)@9<|!yBun6;#0;KJ^>RD2xH$8GO%i?4;VRe16&FaMd zIRyOvJpmXmfXl)X%atfZ<5z(WO12j!5T81nBHEP2r|Fz}PlG99{{ zIEu<)m#PX}iVUFU1nNrvpA?%(K?==kLGj2J3v6do!^n=WXo%Qd3nI? z?cPjMgw;yOm@w=Z8F8RaMyZwMyIj!B>Qbo&f&8)gkEoYzYbhdf%-;y#Zv+=yYC<3! z<^yQql!fK6x8JjNe)Qi5OvUkETXNuK2%-)HOWe(ORP}|&l&UW$VW3{Foxvcvd zVo))K>9o6_;GATi+m&VmgkJCI3lx>V3$wCD$O5+IJ%=M2e$OIITWXn@gFh1vz_XBk zbPN!xxK}t`YK%@b@{)%b7JH@vzXk%k*H2)K>t<|ZM1HsC&7Mf7Z1(T^P)bGysGX73 z)$Dk9c-B0`QPI(h?H=qx?te{yHLdu+KJ(Mp3og|gH+g8xsd6nJw(Sx}u z6vEV)@$&DuTFA_(L3&r)*iCqgm*;#thKNTSvOrFBd^{W*Tl6MBgPw(Lm8q{^M)>Hy8zk}6Nkz&k3YhqfVERnH+(tQ-3yAYy&-*;L?sdkc^CfHk@ zdMor7dxQ4Bq2b}-rTr^&>Zm4j6}lDr%^1xXPXg^hfH0a~SU8|a(Pe57@SVc{qnM&2 zati@kyqlYOciv*>L5w&wBFRJVGu_g-C{f?@=e`f;gxoR>{h!c+f`fJIEFxE_-5k=h z;oiO-8X7uq*4gXn5wEMSmp`JYQH5#^i9H{x0vR8ZKvrS8gc|&d!ghOi49w!aM=nD> ztJUPdgO9(2mtEEvrCVe2CY+jz!E>Jsjmo{n9T5O5P_{FXgy#CZ6wM??@$WzQKP5;B z5iFJ{XAW%kg#*ceEgjQ@Ga3SjlK%w1=*zvij2mTBM5voK-L`sW@Tvp8j^(%C{qIV8 z#HZTB(Y2@q7T>cMQU_)0w_x3jvd;j$q@@RFsei3{9Y*p$SQ# zmgO>oA(49>P!7bBKsljD6^2c7)jQ4t@uL42{<{z{NH>nFyRBYdo=F8=BM?ZIT@4Hj z4wjqQfqvt^d|UB8>-_5Ny`BU+I+q&kB{1HZCUJ;h+L?aglN zlJLc(nGd#EA~zrc-PrD*G7UKzoTumKF@F{J(qWOvfB(Exaz$f}s-gGio87~V0o&xCT==To~*jQNNz^i%Na|IV>%fPT9XYoV1JQukTgS5w`7e2b-Nw=Qi zaVL@7{`1aKBm7wU_E)=3v`(XqKZ{njw(xW@npCL*|9;5s>44a}tBtI@@13|JC?sC1uANJ*g^p=@S#c5xY-D4MlpU0P~WE)YdwWXRUb^2)pk z3Z@mY?65|^OCvOkBi(dWS8snWYe7za?R~@;-QY4I48943>zrO_I_ zHAe|mwOVpj4`iWRKJ|Hu^Mk&s7~*2_WytXG&+Qgw;RpFgYV4e5t|fnAZ-s8E<}IXP zVTaw*F8>~lsVyl(b^iq4A|XZxChDa-KDz5jSxU_(zsPs2%O4Bw&h|&b&<$SB!AB}N zQm4nG-(t{K!qB<*XDak%58Kaf6~LWl=1yc>KV%^i0XsVuTwGk|x3@BtT8RK)0h9w; z8)*9L>gpDn>`4IZNy*A)YBm7dv9-N@ad}C_%pAS4VgTI8D=E?N@IaD&La8L}qSFDgX&kMgEUtjZ`g-2SJM>fLAVLpd79A5TJ6JV{*iTk;KK$sLc|nOWrm(MnY2 z4u{%*_~y@h0&MtMYJU`PGbLX?U*$#$_@uQH6Ss8!fY0?leUN_l=a9kYvhs zDTE2al>E>Gs?<`Hlnhe7V@g)&Uv}t5?`g7MmQz#&-&`%_%g_E*TGc3n{3tFiP%lHm z#BA1~sH)<;{57B#79w;pJNQO8{coHEdjN=58?9nleK7Bn0Alw+-(~k>&7C-PxXOW} zJ3^!0M8J!)=+~LlBL9mmxwyCq4}MBbo*9$UzKP-7ZrRRp&|RPfzOQ7%I^kOGIV0u@ zSGGAGqJXhWN}uJrQ`a5~HzM8D(LpoO(fiQi+7J>V5qyQFr>hAew~@x^3k6#8?SV}p z8=OFH=oX74vFkfkv1cBjd{-E>e&5gW9)C*k^7hu3!<(U8RZL;2y|v3iTVZuX3M&8-oO}{c^MBg}O z&955~SILQc@wII6lJk6u|FYti$=!^hUbFdnB;Z$3S64HsWQlE93G^@hc+Q`8X~M-OX^P%s_N1}TiY??ou+nZs1_sKy=nGx^F$m~@VRaNQf=)yum;BQY??KExE(cpnd zSPfgE(kU7*Ckg`PZ#kiX^}oykAW*4Qs9yG)DPNuzuP~^Ij6$!lSWDaiB(|P1@oQK< zsJlAmNKZsLmLgT*qqF2-P`9SKh8=7|RskkXG;a%UkkvB-M!`A1O4vH4F6vqnuU`u= zVCtJ_r7boq>>`IBD*LEpI;ILaZn$7t7W1rJZs^|kBXc($T~0*Zd~7yDG`?nv@~+btc9kBx&vHS&Fb zcXw7LDk3lvjjpWGdWuS2U43YLyonI2O}OQ&{3k(q24?;z;eDLaN#bt`5^RWtY9?kC zs1qWaZ{9NCV(}{d8kjgL>#)lEm+=O^MT`1V8SfUKRG0zVFNOg4;RzQEWcA1-WZ$h; z_It{s47+pZOBqU+J(F~l$|{`f{C=_PB)(KD@Ow_bZNFC+7S51EG(U}Ej;fk(zs|b- zSHF*h0Gzf4s7=w=CzmUq;+qZ&U;#Ar^z|0QIBGa>dXlo?At7nAybcZyz*Y=5ZoyXY z)zs9iYyhDv?dHY{I7ZnDLYzqF$xezjS=G0*SF2NWb?*E%-0j%L4veOhD)$cx0v`G4 z`a!$6$w!_Kv9_0}u3x?79ltB+)_2AA2`G28zYr5BUdIp}!sEP=;4s708zMfKCQxmq zC$K}gNb*+yS{cwN)~T47pFr5{ggc90XMDvgruo_<`@p=Ymen5{Lr$Ht5~i9al}{lo zlD)ayY)l}V6;-=ZR9p` zk<|;-NZ|E8HHDKJk49NN&+hxAg|!ru%>%4gm^zJ6IMf_3{OeQuVMpdGg7N@e5*L&X zet;Wh2cL`U2V0M0mooIuaeDDsnS_03HEeUWQN{i7cRlyAQh(XA;gOz>>v~4DoeZav z9vetAt^9(*!ZDmd8i}Z=D8M=CU0%-QwVT5tCRX_L2`e@>HcP-I>|%THYKS@>@XG*C zo5iRj4UmFqqa$NuML-Z>Fex5lbihOtaM}Bol@+5`2^7EgA3mu1_y_|Lfej7nGU|6U>pet5j_`Yiol4;Div|lbA9R;86%jW9Vx4Bl7!F8j< zzsYcYs}Kqw`D3@)raWT`sm~_F^2Xn% wXw*N-VsZizyTIubW?3OBsbk*$#VaC6M9{HOxKW7&IAH_HORGp#Nty)x4{Foz +trac_port=<%= tracd_port %> +trac_pidfile=<%= tracd_pidfile %> +trac_parent_dir=<%= tracd_parent_dir %> + +function usage +{ + echo " +Usage: $0 {start|stop} +" + exit 1 +} + +case "$1" in + start) + echo "Starting tracd" + for dir in `ls $trac_parent_dir`; do + project="`basename $dir`" + passwords="$trac_parent_dir/${dir}/conf/users.htdigest" + auth_string="$auth_string --auth=${project},${passwords},${project}" + done + cmd="$tracd_cmd $auth_string --env-parent-dir=$trac_parent_dir \ + --port=$trac_port --pidfile=$trac_pidfile --daemonize" + + $cmd + ;; + + stop) + echo "Stopping tracd" + kill `cat $trac_pidfile` >/dev/null 2>&1 + rm -f $trac_pidfile + ;; + + *) + usage +esac diff --git a/lib/deprec/templates/xen/15-disable-hwclock b/lib/deprec/templates/xen/15-disable-hwclock new file mode 100644 index 0000000..e2fc25c --- /dev/null +++ b/lib/deprec/templates/xen/15-disable-hwclock @@ -0,0 +1,40 @@ +#!/bin/sh +# +# This script disables the hardware clock. +# +# Steve +# -- +# http://www.steve.org.uk/ + + +prefix=$1 + + +# +# Source our common functions +# +if [ -e /usr/lib/xen-tools/common.sh ]; then + . /usr/lib/xen-tools/common.sh +else + . ./hooks/common.sh +fi + + +# +# Log our start +# +logMessage Script $0 starting + + +# +# Disable the startup scripts from all runlevels. +# +chroot ${prefix} /usr/sbin/update-rc.d -f hwclock.sh remove +chroot ${prefix} /usr/sbin/update-rc.d -f hwclockfirst.sh remove +rm -f ${prefix}/etc/init.d/hwclock.sh ${prefix}/etc/init.d/hwclockfirst.sh ${prefix}/etc/udev/rules.d/85-hwclock.rules + +# +# Log our finish +# +logMessage Script $0 finished. + diff --git a/lib/deprec/templates/xen/network-bridge-wrapper b/lib/deprec/templates/xen/network-bridge-wrapper new file mode 100644 index 0000000..bd6ab98 --- /dev/null +++ b/lib/deprec/templates/xen/network-bridge-wrapper @@ -0,0 +1,3 @@ +#!/bin/sh +/etc/xen/scripts/network-bridge $1 netdev=eth0 bridge=xenbr0 vifnum=0 antispoof=no +/etc/xen/scripts/network-bridge $1 netdev=eth1 bridge=xenbr1 vifnum=1 antispoof=no diff --git a/lib/deprec/templates/xen/xen-tools.conf.erb b/lib/deprec/templates/xen/xen-tools.conf.erb new file mode 100644 index 0000000..659f922 --- /dev/null +++ b/lib/deprec/templates/xen/xen-tools.conf.erb @@ -0,0 +1,220 @@ +# +# /etc/xen-tools/xen-tools.conf +# +# Global configuration file for the scripts included with Xen-tools. +# +# Values may be set here so they don't need to be specified upon the +# command line. +# +# Steve +# -- +# + + + +# +## +# Output directory for storing loopback images. +# +# If you choose to use loopback images, which are simple to manage but +# slower than LVM partitions, then specify a directory here and uncomment +# the line. +# +# New instances will be stored in subdirectories named after their +# hostnames. +# +## +# dir = /home/xen +# dir = /var/vm +# + +# +## +# +# If you don't wish to use loopback images then you may specify an +# LVM volume group here instead +# +## +# lvm = skx-vg +lvm = vm_local + + +# +## +# +# Installation method. +# +# There are four distinct methods which you may to install a new copy +# of Linux to use in your Xen guest domain: +# +# - Installation via the debootstrap command. +# - Installation via the rpmstrap command. +# - Installation by copying a directory containing a previous installation. +# - Installation by untarring a previously archived image. +# +# NOTE That if you use the "untar", or "copy" options you should ensure +# that the image you're left with matches the 'dist' setting later in +# this file. +# +# +## +# +# +# install-method = [ debootstrap | rpmstrap | copy | tar ] +# +# +install-method = debootstrap + +# +# If you're using "copy", or "tar" you will need to specify the +# source location to copy from, or the source .tar file to unpack. +# +# You may specify that with a line such as: +# +# install-source = /path/to/copy +# install-source = /some/path/img.tar +# +# + +# +## +# Command definitions. +## +# +# The "debootstrap" and "rpmstrap" commands are hardwired into the +# script, but if you wish to modify the commands which are executed +# when installing new systems by a "copy" or "tar" method you can +# do so here: +# +# install-method=copy: +# copy-cmd = /bin/cp -a $src/* $dest +# +# install-method=tar: +# tar-cmd = /bin/tar --numeric-owner -xvf $src +# +# + + + +# +## +# Disk and Sizing options. +## +# +size = 10Gb # Disk image size. +memory = 256Mb # Memory size +swap = 512Mb # Swap size +# noswap = 1 # Don't use swap at all for the new system. +fs = ext3 # use the EXT3 filesystem for the disk image. +dist = gutsy # Default distribution to install. +image = full # Specify sparse vs. full disk images. + +# +# Currently supported and tested distributions include: +# +# sid - Debian +# sarge - Debian +# etch - Debian +# dapper - Ubuntu +# centos4 - CentOS 4 +# fedora-core4 - Fedora Core 4 (codname stentz) +# + + + +## +# Networking setup values. +## + +# +# Uncomment and adjust these network settings if you wish to give your +# new instances static IP addresses. +# +gateway = 192.168.1.1 +netmask = 255.255.255.0 +broadcast = 192.168.1.255 +# +# Uncomment this if you wish the images to use DHCP +# +# dhcp = 1 + + +## +# Misc options +## + +# +# Uncomment the following line if you wish to disable the caching +# of downloaded .deb files when using debootstrap to install images. +# +# cache = no +# + +# +# Uncomment the following line if you wish to interactively setup +# a new root password for images. +# +passwd = 1 + +# +# If you'd like all accounts on your host system which are not present +# on the guest system to be copied over then uncomment the following line. +# +# accounts = 1 +# + +# +# Default kernel and ramdisk to use for the virtual servers +# +kernel = /boot/vmlinuz-`uname -r` +initrd = /boot/initrd.img-`uname -r` + +# +# The architecture to use when using debootstrap or rpmstrap. +# +# This is most useful on 64 bit host machines, for other systems it +# doesn't need to be used. +# +# arch=i386 +# + +# +# The default mirror for debootstrap to install Debian-derived distributions +# +# mirror = http://ftp.us.debian.org/debian/ + +# +# A mirror suitable for use when installing the Dapper release of Ubuntu. +# +# mirror = http://gb.archive.ubuntu.com/ubuntu/ + +# +# If you like you could use per-distribution mirrors, which will +# be more useful if you're working in an environment where you want +# to regularly use multiple distributions: +# +# mirror_sid=http://ftp.us.debian.org/debian +# mirror_sarge=http://ftp.us.debian.org/debian +# mirror_etch=http://ftp.us.debian.org/debian +# mirror_dapper=http://archive.ubuntu.com/ubuntu +# mirror_edgy=http://archive.ubuntu.com/ubuntu +# mirror_feisty=http://archive.ubuntu.com/ubuntu +mirror_gutsy=http://archive.ubuntu.com/ubuntu + + +# +# Uncomment if you wish newly created images to boot once they've been +# created. +# +# boot = 1 +# + +# If you're using a newer version of the Xen guest kernel you will +# need to make sure that you use 'xvc0' for the guest serial device, +# and 'xvdX' instead of 'sdX' for serial devices. +# +# serial_device = tty1 #default +# serial_device = xvc0 +# +# disk_device = sda #default +# disk_device = xvda diff --git a/lib/deprec/templates/xen/xend-config.sxp.erb b/lib/deprec/templates/xen/xend-config.sxp.erb new file mode 100644 index 0000000..d734aa8 --- /dev/null +++ b/lib/deprec/templates/xen/xend-config.sxp.erb @@ -0,0 +1,195 @@ +# -*- sh -*- + +# +# Xend configuration file. +# + +# This example configuration is appropriate for an installation that +# utilizes a bridged network configuration. Access to xend via http +# is disabled. + +# Commented out entries show the default for that entry, unless otherwise +# specified. + +#(logfile /var/log/xen/xend.log) +#(loglevel DEBUG) + + +# The Xen-API server configuration. (Please note that this server is +# available as an UNSUPPORTED PREVIEW in Xen 3.0.4, and should not be relied +# upon). +# +# This value configures the ports, interfaces, and access controls for the +# Xen-API server. Each entry in the list starts with either unix, a port +# number, or an address:port pair. If this is "unix", then a UDP socket is +# opened, and this entry applies to that. If it is a port, then Xend will +# listen on all interfaces on that TCP port, and if it is an address:port +# pair, then Xend will listen on the specified port, using the interface with +# the specified address. +# +# The subsequent string configures the user-based access control for the +# listener in question. This can be one of "none" or "pam", indicating either +# that users should be allowed access unconditionally, or that the local +# Pluggable Authentication Modules configuration should be used. If this +# string is missing or empty, then "pam" is used. +# +# The final string gives the host-based access control for that listener. If +# this is missing or empty, then all connections are accepted. Otherwise, +# this should be a space-separated sequence of regular expressions; any host +# with a fully-qualified domain name or an IP address that matches one of +# these regular expressions will be accepted. +# +# Example: listen on TCP port 9363 on all interfaces, accepting connections +# only from machines in example.com or localhost, and allow access through +# the unix domain socket unconditionally: +# +# (xen-api-server ((9363 pam '^localhost$ example\\.com$') +# (unix none))) +# +# Optionally, the TCP Xen-API server can use SSL by specifying the private +# key and certificate location: +# +# (9367 pam '' /etc/xen/xen-api.key /etc/xen/xen-api.crt) +# +# Default: +# (xen-api-server ((unix))) + + +#(xend-http-server no) +#(xend-unix-server no) +#(xend-tcp-xmlrpc-server no) +#(xend-unix-xmlrpc-server yes) +#(xend-relocation-server no) +(xend-relocation-server yes) + +#(xend-unix-path /var/lib/xend/xend-socket) + + +# Address and port xend should use for the legacy TCP XMLRPC interface, +# if xen-tcp-xmlrpc-server is set. +#(xen-tcp-xmlrpc-server-address 'localhost') +#(xen-tcp-xmlrpc-server-port 8006) + +# SSL key and certificate to use for the legacy TCP XMLRPC interface. +# Setting these will mean that this port serves only SSL connections as +# opposed to plaintext ones. +#(xend-tcp-xmlrpc-server-ssl-key-file /etc/xen/xmlrpc.key) +#(xend-tcp-xmlrpc-server-ssl-cert-file /etc/xen/xmlrpc.crt) + + +# Port xend should use for the HTTP interface, if xend-http-server is set. +#(xend-port 8000) + +# Port xend should use for the relocation interface, if xend-relocation-server +# is set. +#(xend-relocation-port 8002) + +# Address xend should listen on for HTTP connections, if xend-http-server is +# set. +# Specifying 'localhost' prevents remote connections. +# Specifying the empty string '' (the default) allows all connections. +#(xend-address '') +#(xend-address localhost) + +# Address xend should listen on for relocation-socket connections, if +# xend-relocation-server is set. +# Meaning and default as for xend-address above. +#(xend-relocation-address '') + +# The hosts allowed to talk to the relocation port. If this is empty (the +# default), then all connections are allowed (assuming that the connection +# arrives on a port and interface on which we are listening; see +# xend-relocation-port and xend-relocation-address above). Otherwise, this +# should be a space-separated sequence of regular expressions. Any host with +# a fully-qualified domain name or an IP address that matches one of these +# regular expressions will be accepted. +# +# For example: +# (xend-relocation-hosts-allow '^localhost$ ^.*\\.example\\.org$') +# +#(xend-relocation-hosts-allow '') +(xend-relocation-hosts-allow '^localhost$ ^localhost\\.localdomain$') + +# The limit (in kilobytes) on the size of the console buffer +#(console-limit 1024) + +## +# To bridge network traffic, like this: +# +# dom0: fake eth0 -> vif0.0 -+ +# | +# bridge -> real eth0 -> the network +# | +# domU: fake eth0 -> vifN.0 -+ +# +# use +# +(network-script network-bridge-wrapper) +# +# Your default ethernet device is used as the outgoing interface, by default. +# To use a different one (e.g. eth1) use +# +# (network-script 'network-bridge netdev=eth1') +# +# The bridge is named xenbr0, by default. To rename the bridge, use +# +# (network-script 'network-bridge bridge=') +# +# It is possible to use the network-bridge script in more complicated +# scenarios, such as having two outgoing interfaces, with two bridges, and +# two fake interfaces per guest domain. To do things like this, write +# yourself a wrapper script, and call network-bridge from it, as appropriate. +# +# (network-script network-dummy) + +# The script used to control virtual interfaces. This can be overridden on a +# per-vif basis when creating a domain or a configuring a new vif. The +# vif-bridge script is designed for use with the network-bridge script, or +# similar configurations. +# +# If you have overridden the bridge name using +# (network-script 'network-bridge bridge=') then you may wish to do the +# same here. The bridge name can also be set when creating a domain or +# configuring a new vif, but a value specified here would act as a default. +# +# If you are using only one bridge, the vif-bridge script will discover that, +# so there is no need to specify it explicitly. +# +(vif-script vif-bridge) + + +## Use the following if network traffic is routed, as an alternative to the +# settings for bridged networking given above. +#(network-script network-route) +#(vif-script vif-route) + + +## Use the following if network traffic is routed with NAT, as an alternative +# to the settings for bridged networking given above. +#(network-script network-nat) +#(vif-script vif-nat) + + +# Dom0 will balloon out when needed to free memory for domU. +# dom0-min-mem is the lowest memory level (in MB) dom0 will get down to. +# If dom0-min-mem=0, dom0 will never balloon out. +(dom0-min-mem 196) + +# In SMP system, dom0 will use dom0-cpus # of CPUS +# If dom0-cpus = 0, dom0 will take all cpus available +(dom0-cpus 0) + +# Whether to enable core-dumps when domains crash. +#(enable-dump no) + +# The tool used for initiating virtual TPM migration +#(external-migration-tool '') + +# The interface for VNC servers to listen on. Defaults +# to 127.0.0.1 To restore old 'listen everywhere' behaviour +# set this to 0.0.0.0 +#(vnc-listen '127.0.0.1') + +# The default password for VNC console on HVM domain. +# Empty string is no authentication. +(vncpasswd '') diff --git a/lib/deprec/templates/xen/xend-init.erb b/lib/deprec/templates/xen/xend-init.erb new file mode 100644 index 0000000..3091420 --- /dev/null +++ b/lib/deprec/templates/xen/xend-init.erb @@ -0,0 +1,69 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: xend +# Required-Start: $local_fs +# Required-Stop: $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: S 0 1 6 +# Short-Description: XEN control daemon +# Description: XEN control daemon +### END INIT INFO + +if ! grep -q "control_d" /proc/xen/capabilities ; then + exit 0 +fi + +# Wait for Xend to be up +function await_daemons_up +{ + i=1 + rets=10 + xend status + while [ $? -ne 0 -a $i -lt $rets ]; do + sleep 1 + echo -n . + i=$(($i + 1)) + xend status + done +} + +# Rules for ip forwarding and NAT +# echo 1 >/proc/sys/net/ipv4/ip_forward +# echo 1 >/proc/sys/net/ipv4/conf/eth0/proxy_arp +# echo 1 >/proc/sys/net/ipv4/conf/eth1/proxy_arp +# IPTABLES=/sbin/iptables +# EXTIF=eth0 +# INTIF=eth1 +# $IPTABLES -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT +# $IPTABLES -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT +# $IPTABLES -t nat -A POSTROUTING -o $EXTIF -s 192.168.1.0/24 -j MASQUERADE + + +case "$1" in + start) + xend start + await_daemons_up + ;; + stop) + /etc/init.d/xendomains stop # make sure domains are shut down + xend stop + ;; + status) + xend status + ;; + reload) + xend reload + ;; + restart|force-reload) + xend restart + await_daemons_up + ;; + *) + # do not advertise unreasonable commands that there is no reason + # to use with this device + echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}" + exit 1 +esac + +exit $? + diff --git a/lib/deprec/templates/xen/xendomains.erb b/lib/deprec/templates/xen/xendomains.erb new file mode 100644 index 0000000..0263cd7 --- /dev/null +++ b/lib/deprec/templates/xen/xendomains.erb @@ -0,0 +1,137 @@ +## Path: System/xen +## Description: xen domain start/stop on boot +## Type: string +## Default: +# +# The xendomains script can send SysRq requests to domains on shutdown. +# If you don't want to MIGRATE, SAVE, or SHUTDOWN, this may be a possibility +# to do a quick and dirty shutdown ("s e i u o") or at least sync the disks +# of the domains ("s"). +# +XENDOMAINS_SYSRQ="" + +## Type: integer +## Default: 100000 +# +# If XENDOMAINS_SYSRQ is set, this variable determines how long to wait +# (in microseconds) after each SysRq, so the domain has a chance to react. +# If you want to a quick'n'dirty shutdown via SysRq, you may want to set +# it to a relatively high value (1200000). +# +XENDOMAINS_USLEEP=100000 + +## Type: integer +## Default: 5000000 +# +# When creating a guest domain, it is sensible to allow a little time for it +# to get started before creating another domain or proceeding through the +# boot process. Without this, the booting guests will thrash the disk as they +# start up. This timeout (in microseconds) specifies the delay after guest +# domain creation. +# +XENDOMAINS_CREATE_USLEEP=5000000 + +## Type: string +## Default: "" +# +# Set this to a non-empty string if you want to migrate virtual machines +# on shutdown. The string will be passed to the xm migrate DOMID command +# as is: It should contain the target IP address of the physical machine +# to migrate to and optionally parameters like --live. Leave empty if +# you don't want to try virtual machine relocation on shutdown. +# If migration succeeds, neither SAVE nor SHUTDOWN will be executed for +# that domain. +# +XENDOMAINS_MIGRATE="" + +## Type: string +## Default: /var/lib/xen/save +# +# Directory to save running domains to when the system (dom0) is +# shut down. Will also be used to restore domains from if # XENDOMAINS_RESTORE +# is set (see below). Leave empty to disable domain saving on shutdown +# (e.g. because you rather shut domains down). +# If domain saving does succeed, SHUTDOWN will not be executed. +# +# XENDOMAINS_SAVE=/var/lib/xen/save + +## Type: string +## Default: "--halt --wait" +# +# If neither MIGRATE nor SAVE were enabled or if they failed, you can +# try to shut down a domain by sending it a shutdown request. To do this, +# set this to "--halt --wait". Omit the "--wait" flag to avoid waiting +# for the domain to be really down. Leave empty to skip domain shutdown. +# +XENDOMAINS_SHUTDOWN="--halt --wait" + +## Type: string +## Default: "--all --halt --wait" +# +# After we have gone over all virtual machines (resp. all automatically +# started ones, see XENDOMAINS_AUTO_ONLY below) in a loop and sent SysRq, +# migrated, saved and/or shutdown according to the settings above, we +# might want to shutdown the virtual machines that are still running +# for some reason or another. To do this, set this variable to +# "--all --halt --wait", it will be passed to xm shutdown. +# Leave it empty not to do anything special here. +# (Note: This will hit all virtual machines, even if XENDOMAINS_AUTO_ONLY +# is set.) +# +XENDOMAINS_SHUTDOWN_ALL="--all --halt --wait" + +## Type: boolean +## Default: true +# +# This variable determines whether saved domains from XENDOMAINS_SAVE +# will be restored on system startup. +# +XENDOMAINS_RESTORE=true + +## Type: string +## Default: /etc/xen/auto +# +# This variable sets the directory where domains configurations +# are stored that should be started on system startup automatically. +# Leave empty if you don't want to start domains automatically +# (or just don't place any xen domain config files in that dir). +# Note that the script tries to be clever if both RESTORE and AUTO are +# set: It will first restore saved domains and then only start domains +# in AUTO which are not running yet. +# Note that the name matching is somewhat fuzzy. +# +XENDOMAINS_AUTO=/etc/xen/auto + +## Type: boolean +## Default: false +# +# If this variable is set to "true", only the domains started via config +# files in XENDOMAINS_AUTO will be treated according to XENDOMAINS_SYSRQ, +# XENDOMAINS_MIGRATE, XENDOMAINS_SAVE, XENDMAINS_SHUTDOWN; otherwise +# all running domains will be. +# Note that the name matching is somewhat fuzzy. +# +XENDOMAINS_AUTO_ONLY=false + +## Type: integer +## Default: 300 +# +# On xendomains stop, a number of xm commands (xm migrate, save, shutdown, +# shutdown --all) may be executed. In the worst case, these commands may +# stall forever, which will prevent a successful shutdown of the machine. +# If this variable is non-zero, the script will set up a watchdog timer +# for every of these xm commands and time it out after the number of seconds +# specified by this variable. +# Note that SHUTDOWN_ALL will not be called if no virtual machines or only +# zombies are still running, so you don't need to enable this timeout just +# for the zombie case. +# The setting should be large enough to make sure that migrate/save/shutdown +# can succeed. If you do live migrations, keep in mind that live migration +# of a 1GB machine over Gigabit ethernet may actually take something like +# 100s (assuming that live migration uses 10% of the network # bandwidth). +# Depending on the virtual machine, a shutdown may also require a significant +# amount of time. So better setup this variable to a huge number and hope the +# watchdog never fires. +# +XENDOMAINS_STOP_MAXWAIT=300 + diff --git a/lib/deprec/templates/xen/xm.tmpl.erb b/lib/deprec/templates/xen/xm.tmpl.erb new file mode 100644 index 0000000..16648a3 --- /dev/null +++ b/lib/deprec/templates/xen/xm.tmpl.erb @@ -0,0 +1,85 @@ +# +# Configuration file for the Xen instance {$hostname}, created +# by xen-tools {$xen_tools_version} on { scalar localtime }. +# + +# +# Kernel + memory size +# +{ if ( $kernel ) + { + $OUT.= "kernel = '$kernel'"; + } +} +{ if ( $initrd ) + { + $OUT.= "ramdisk = '$initrd'"; + } +} +memory = '{$memory}' + +# +# Disk device(s). +# +root = '/dev/{$device}1 ro' +{ if ( $noswap ) + { + $OUT .= "disk = [ '$image_vbd,$device" . "1,w' ]"; + } + else + { + $OUT .= "disk = [ '$image_vbd,$device" . "1,w', '$swap_vbd,$device" . "2,w' ]"; + } +} + +# +# Hostname +# +name = '{$hostname}' + +# +# Networking +# +{ if ( $dhcp ) + { + $OUT .= "dhcp = 'dhcp'\n"; + + # Setup the mac address, if present. + my $m = ''; + if ( $mac ) + { + $m = "mac=$mac" + } + + $OUT .= "vif = [ '$m' ]"; + } + else + { + # + # Setup the mac address, if present. + # + my $m = ''; + if ( $mac ) + { + $m = ",mac=$mac" + } + + $OUT .= "vif = [ 'ip=$ip1"; + $OUT .= "$m' ]"; + } +} + +# +# Behaviour +# +on_poweroff = 'destroy' +on_reboot = 'restart' +on_crash = 'restart' + + +{ if ( $admins ) + { + $OUT .= "xen_shell = '$admins'\n"; + } +} +extra = ' TERM=xterm xencons=tty console=tty1' diff --git a/lib/vmbuilder_plugins/all.rb b/lib/vmbuilder_plugins/all.rb new file mode 100644 index 0000000..a530855 --- /dev/null +++ b/lib/vmbuilder_plugins/all.rb @@ -0,0 +1,20 @@ +# =all.rb: Load all the Capistrano Plugins in the directory. +# +# Require all other ruby files in the directory. +# +# ---- +# Copyright (c) 2007 Neil Wilson, Aldur Systems Ltd +# +# Licensed under the GNU Public License v2. No warranty is provided. +# ---- +# = Usage +# +# require 'vmbuilder_plugins/all' + +# Splitting and joining __FILE__ deals with the current directory case +# properly +Dir[File.join( File.dirname(__FILE__), '*.rb')].each do |plugin_name| + unless plugin_name == File.join(File.dirname(__FILE__), File.basename(__FILE__)) + require plugin_name + end +end diff --git a/lib/vmbuilder_plugins/apt.rb b/lib/vmbuilder_plugins/apt.rb new file mode 100644 index 0000000..58a8846 --- /dev/null +++ b/lib/vmbuilder_plugins/apt.rb @@ -0,0 +1,93 @@ +# =apt.rb: Debian 'apt' Installer library +# Capistrano plugin module to install and manage apt packages +# +# ---- +# Copyright (c) 2007 Neil Wilson, Aldur Systems Ltd +# +# Licensed under the GNU Public License v2. No warranty is provided. + +require 'capistrano' + +# = Purpose +# Apt is a Capistrano plugin module providing a set of methods +# that invoke the *apt* package manager (as used in Debian and Ubuntu) +# +# Installs within Capistrano as the plugin _apt_. +# +# =Usage +# +# require 'vmbuilder_plugins/apt' +# +# Prefix all calls to the library with apt. +# +module Apt + + # Default apt-get command - reduces any interactivity to the minimum. + #APT_GET="DEBCONF_TERSE='yes' DEBIAN_PRIORITY='critical' DEBIAN_FRONTEND=noninteractive apt-get" + APT_GET="yum -y" + + # Run the apt install program across the package list in 'packages'. + # Select those packages referenced by :base and the +version+ + # of the distribution you want to use. + def install(packages, version, options={}) + #special_options="--allow-unauthenticated" if version != :stable + #sh -c "#{APT_GET} -qyu --force-yes #{special_options.to_s} install #{package_list(packages, version)}" + special_options = options[:repositories].collect { |repository| " --enablerepo=#{repository}"} if (options && options[:repositories].is_a?(Array)) + send(run_method, %{ + sh -c "#{APT_GET} #{special_options.to_s} install #{package_list(packages, version)}" + }, options) + end + + # Run an apt clean + def clean(options={}) + send(run_method, %{sh -c "#{APT_GET} -qy clean"}, options) + end + + # Run an apt autoclean + def autoclean(options={}) + send(run_method, %{sh -c "#{APT_GET} -qy autoclean"}, options) + end + + # Run an apt distribution upgrade + def dist_upgrade(options={}) + send(run_method, %{sh -c "#{APT_GET} -qy dist-upgrade"}, options) + end + + # Run an apt upgrade. Use dist_upgrade instead if you want to upgrade + # the critical base packages. + def upgrade(options={}) + send(run_method, %{sh -c "#{APT_GET} -qy upgrade"}, options) + end + + # Run an apt update. + def update(options={}) + send(run_method, %{sh -c "#{APT_GET} -qy update"}, options) + end + + # RPM package install via alien + def rpm_install(packages, options={}) + install({:base => %w(wget alien) }, :base) + send(run_method, "wget -Ncq #{packages.join(' ')}", options) + files=packages.collect { |package| File.basename(package) } + send(run_method, "alien -i #{files.join(' ')}", options) + end + + # Clear the source list and package cache + def clear_cache(options={}) + clean + cmd="rm -f /var/cache/apt/*.bin /var/lib/apt/lists/*_* /var/lib/apt/lists/partial/*" + send(run_method, cmd, options) + end + +private + + # Provides a string containing all the package names in the base + #list plus those in +version+. + def package_list(packages, version) + packages[:base].to_a.join(' ') + ' ' + packages[version].to_a.join(' ') + end + +end + +Capistrano.plugin :apt, Apt +# vim: nowrap sw=2 sts=2 ts=8 ff=unix ft=ruby: diff --git a/lib/vmbuilder_plugins/emerge.rb b/lib/vmbuilder_plugins/emerge.rb new file mode 100644 index 0000000..83129d2 --- /dev/null +++ b/lib/vmbuilder_plugins/emerge.rb @@ -0,0 +1,76 @@ +# =emerge.rb: Gentoo 'emerge' Installer library +# Capistrano task library to install and manage portage packages +# +# Copyright (c) 2007 monki(Wesley Beary) +# +# inspiration: vmbuilder by Neil Wilson, Aldur Systems Ltd +# +# Licenced under the GNU Public License v2. No warranty is provided. + +require 'capistrano' + +# =Purpose +# emerge is a Capistrano plugin module providing a set of methods +# that invoke the portage package manage (as used in Gentoo) +# +# Installs within Capistrano as the plugin _emerge_. +# +# =Usage +# +# require 'marshall/plugins/emerge' +# +# Prefix all calls to the library with emerge. +# +module Emerge + # Default emerge command - reduce interactivity to the minimum + EMERGE="emerge -q" + + # Emerge a new package or packages + def install(packages, options={}) + cmd = <<-CMD + sh -c "#{EMERGE} #{packages.join(" ")}" + CMD + sudo(cmd, options) + end + + # Run clean old/unused packages + def clean(options={}) + cmd = <<-CMD + sh -c "#{EMERGE} -clean" + CMD + sudo(cmd, options) + end + + # Upgrade installed package list + def upgrade(options={}) + cmd = <<-CMD + sh -c "#{EMERGE} --sync" + CMD + sudo(cmd, options) + end + + # Update portage + def update_system(options={}) + cmd = <<-CMD + sh -c "#{EMERGE} portage" + CMD + sudo(cmd, options) + end + + # Update all installed packages + def update(options={}) + cmd = <<-CMD + sh -c "#{EMERGE} --update --deep --newuse world" + CMD + sudo(cmd, options) + end + + # Boot script manipulation command + def rc_update(packages, setting) + packages.each do |service| + sudo "rc_update add #{service} #{setting}" + end + end +end + +Capistrano.plugin :emerge, Emerge diff --git a/lib/vmbuilder_plugins/gem.rb b/lib/vmbuilder_plugins/gem.rb new file mode 100644 index 0000000..dc161fe --- /dev/null +++ b/lib/vmbuilder_plugins/gem.rb @@ -0,0 +1,90 @@ +# =gem.rb: Gem Installer library +# Capistrano library to install and manage Ruby Gems. +# +# ---- +# Copyright (c) 2007 Neil Wilson, Aldur Systems Ltd +# +# Licensed under the GNU Public License v2. No warranty is provided. + +require 'capistrano' + +# = Purpose +# Gem is a Capistrano plugin module providing a set of methods +# that invoke the *gem* package manager. +# +# Installs within Capistrano as the plugin _gem_. +# +# =Usage +# +# require 'vmbuilder_plugins/gem' +# +# Prefix all calls to the library with gem. +# +module Gem + + # Default install command + # + # * doesn't install documentation + # * installs all required dependencies automatically. + # + GEM_INSTALL="gem install --no-rdoc --no-ri" + GEM_UPDATE=GEM_INSTALL.sub("install", "update") + + # Upgrade the *gem* system to the latest version. Runs via *sudo* + def update_system + send(run_method, "#{GEM_UPDATE} --system") + end + + # Updates all the installed gems to the latest version. Runs via *sudo*. + # Don't use this command if any of the gems require a version selection. + def upgrade + send(run_method, GEM_UPDATE) + end + + # Removes old versions of gems from installation area. + def cleanup + send(run_method, "gem cleanup") + end + + # Installs the gems detailed in +packages+, selecting version +version+ if + # specified. + # + # +packages+ can be a single string or an array of strings. + # + def install(packages, version=nil) + send(run_method,"#{GEM_INSTALL} #{if version then '-v '+version.to_s end} #{packages.to_a.join(' ')}") + end + + # Auto selects a gem from a list and installs it. + # + # *gem* has no mechanism on the command line of disambiguating builds for + # different platforms, and instead asks the user. This method has the necessary + # conversation to select the +version+ relevant to +platform+ (or the one nearest + # the top of the list if you don't specify +version+). + def select(package, version=nil, platform='ruby') + selections={} + cmd="#{GEM_INSTALL} #{if version then '-v '+version.to_s end} #{package}" + send run_method, cmd do |channel, stream, data| + data.each_line do | line | + case line + when /\s(\d+).*\(#{platform}\)/ + if selections[channel[:host]].nil? + selections[channel[:host]]=$1.dup+"\n" + logger.info "Selecting #$&", "#{stream} :: #{channel[:host]}" + end + when /\s\d+\./ + # Discard other selections from data stream + when /^>/ + channel.send_data selections[channel[:host]] + logger.debug line, "#{stream} :: #{channel[:host]}" + else + logger.info line, "#{stream} :: #{channel[:host]}" + end + end + end + end + +end + +Capistrano.plugin :gem2, Gem +# vim: nowrap sw=2 sts=2 ts=8 ff=unix ft=ruby: diff --git a/lib/vmbuilder_plugins/std.rb b/lib/vmbuilder_plugins/std.rb new file mode 100644 index 0000000..0474807 --- /dev/null +++ b/lib/vmbuilder_plugins/std.rb @@ -0,0 +1,203 @@ +# =std.rb: Capistrano Standard Methods +# Standard library of procedures and functions that you can use with Capistrano. +# +# ---- +# Copyright (c) 2007 Neil Wilson, Aldur Systems Ltd +# +# Licensed under the GNU Public License v2. No warranty is provided. + +require 'capistrano' + +# = Purpose +# Std is a Capistrano plugin that provides a set of standard methods refactored +# out of several Capistrano task libraries. +# +# Installs within Capistrano as the plugin _std_ +# +# = Usage +# +# require 'vmbuilder_plugins/std' +# +# Prefix all calls to the library with std. +module Std + + begin + # Use the Mmap class if it is available + # http://moulon.inra.fr/ruby/mmap.html + require 'mmap' + MMAP=true #:nodoc: + rescue LoadError + # no MMAP class, use normal reads instead + MMAP=false #:nodoc: + end + + # Copies the files specified by +file_pattern+ to +destination+ + # + # Error checking is minimal - a pattern onto a single file will result in +destination+ + # containing the data from the last file only. + # + # Installs via *sudo*, +options+ are as for *put*. + def fput(file_pattern, destination, options={}) + logger.info file_pattern + Dir.glob(file_pattern) do |fname| + if File.readable?(fname) then + if MMAP + logger.debug "Using Memory Mapped File Upload" + fdata=Mmap.new(fname,"r", Mmap::MAP_SHARED, :advice => Mmap::MADV_SEQUENTIAL) + else + fdata=File.open(fname).read + end + su_put(fdata, destination, File.join('/tmp',File.basename(fname)), options) + else + logger.error "Unable to read file #{fname}" + end + end + end + + # Upload +data+ to +temporary_area+ before installing it in + # +destination+ using sudo. + # + # +options+ are as for *put* + # + def su_put(data, destination, temporary_area='/tmp', options={}) + temporary_area = File.join(temporary_area,File.basename(destination)) + put(data, temporary_area, options) + send run_method, <<-CMD + sh -c "install -m#{sprintf("%3o",options[:mode]||0755)} #{temporary_area} #{destination} && + rm -f #{temporary_area}" + CMD + end + + # Copies the +file_pattern+, which is assumed to be a tar + # file of some description (gzipped or plain), and unpacks it into + # +destination+. + def unzip(file_pattern, destination, options={}) + Dir.glob(file_pattern) do |fname| + if File.readable?(fname) then + target="/tmp/#{File.basename(fname)}" + if MMAP + logger.debug "Using Memory Mapped File Upload" + fdata=Mmap.new(fname,"r", Mmap::MAP_SHARED, :advice => Mmap::MADV_SEQUENTIAL) + else + fdata=File.open(fname).read + end + put(fdata, target, options) + send run_method, <<-CMD + sh -c "cd #{destination} && + zcat -f #{target} | tar xvf - && + rm -f #{target}" + CMD + end + end + end + + # Wrap this around your task calls to catch the no servers error and + # ignore it + # + # std.ignore_no_servers_error do + # activate_mysql + # end + # + def ignore_no_servers_error (&block) + begin + yield + rescue RuntimeError => failure + if failure.message =~ /no servers matched/ + logger.debug "Ignoring 'no servers matched' error in task #{current_task.name}" + else + raise + end + end + end + + # Wrap this around your task to force a connection as root. + # Flushes the session cache before and after the connection. + # + # std.connect_as_root do + # install_sudo + # end + # + def connect_as_root (&block) + begin + tempuser = user + set :user, "root" + actor.sessions.delete_if { true } + yield tempuser + ensure + set :user, tempuser if tempuser + actor.sessions.delete_if { true } + end + end + + #Returns a random string of alphanumeric characters of size +size+ + #Useful for passwords, usernames and the like. + def random_string(size=10) + s = "" + size.times { s << (i = rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr } + s + end + + + # Return a relative path from the destination directory +from_str+ + # to the target file/directory +to_str+. Used to create relative + # symbolic link paths. + def relative_path (from_str, to_str) + require 'pathname' + Pathname.new(to_str).relative_path_from(Pathname.new(from_str)).to_s + end + + # Run a ruby command file on the servers + # + def ruby(cmd, options={}, &block) + temp_name = random_string + ".rb" + begin + put(cmd, temp_name, :mode => 0700) + send(run_method, "ruby #{temp_name}", options, &block) + ensure + delete temp_name + end + end + + # Run a patchfile on the servers + # Ignores reverses and rejects. + # + def patch(patchfile, level = '0', where = '/') + temp_name = random_string + begin + fput(patchfile, temp_name, :mode => 0600) + send(run_method, %{ + patch -p#{level} -tNd #{where} -r /dev/null < #{temp_name} || true + }) + ensure + delete temp_name + end + end + + # Deletes the given file(s) from all servers targetted by the current + # task, but runs the +delete+ command according to the current setting + # of :use_sudo. + # + # If :recursive => true is specified, it may be used to remove + # directories. + def su_delete(path, options={}) + cmd = "rm -%sf #{path}" % (options[:recursive] ? "r" : "") + send(run_method, cmd, options) + end + + # Render a template file and upload it to the servers + # + def put_template(template, destination, options={}) + if MMAP + logger.debug "Using Memory Mapped File Upload" + fdata=Mmap.new(template,"r", Mmap::MAP_SHARED, :advice => Mmap::MADV_SEQUENTIAL) + else + fdata=File.read(template) + end + put(render(:template => fdata), destination, options) + end + +end + +Capistrano.plugin :std, Std +# +# vim: nowrap sw=2 sts=2 ts=8 ff=unix ft=ruby: