deprec http://deprec.org deployment recipes for Capistrano Thu, 28 Jul 2011 07:31:55 +0000 en-US hourly 1 http://wordpress.org/?v=4.2.5 Rake http://deprec.org/recipes/rake/?utm_source=rss&utm_medium=rss&utm_campaign=rake http://deprec.org/recipes/rake/#comments Thu, 14 Jul 2011 15:25:59 +0000 http://deprec.org/?p=457 I woke up this morning with a great idea. What if deprec could include rake tasks as well as cap tasks?

This would be handy when working on your dev box as you could run tasks the same tasks locally (with Rake) that you can run on remote servers with Capistrano.

It would also allow us to simplify many cap tasks. They would simply call rake tasks with the same name.

I actually envisaged this almost four years ago but the sticking point was how to distribute and maintain the rake tasks on remote servers.

Bundler is the final piece that makes it all incredibly simple.

Check this out!

# Gemfile

gem 'deprec', '>=3.1.0.rc13'

Simply run ‘bundle’ and that’s all you need to have deprec’s rake tasks available to you.

$ rake -T deprec:db

rake deprec:db:backup # Backup the database to a file.

rake deprec:db:restore # Restore database [pending]

The same task is also available as a cap task! ‘cap deprec:db:backup’

$ cap -T deprec:db

cap deprec:db:activate   # Enable startup script for db server
cap deprec:db:backup     # Backup data for db server
cap deprec:db:config     # Deploy configuration files(s) for db server
cap deprec:db:config_gen # Generate config file(s) for db server
cap deprec:db:deactivate # Disable startup script for db server
cap deprec:db:install    # Install Db server
cap deprec:db:restart    # Stop db server
cap deprec:db:restore    # Restore data for db server from backup
cap deprec:db:start      # Start db server
cap deprec:db:stop       # Stop db server

Thanks to Craig Ambrose for the database backup task.

Expect to see more tasks becoming available on http://deprec.org

]]>
http://deprec.org/recipes/rake/feed/ 0
Ruby on Rails Stack http://deprec.org/recipes/ruby-on-rails-stack/?utm_source=rss&utm_medium=rss&utm_campaign=ruby-on-rails-stack http://deprec.org/recipes/ruby-on-rails-stack/#comments Sun, 26 Jun 2011 10:27:55 +0000 http://deprec.org/?p=417 While deprec was originally created for this purpose, installing a Ruby On Rails stack has become a helluva lot easier since Phusion Passenger came on the scene. I still find it convenient to use a couple of standard deprec tasks to install a Ruby on Rails stack though.

$ cap deprec:rack:install_stack
$ cap deprec:db:install

If you get the error “the task `deprec:rack:install_stack’ does not exist” it’s probably because you have required ‘deprec_minus_rails’ instead of ‘deprec’.

deprec:rack namespace
deprec’s rails recipes are in the process of being simplified. To preserve backward compatibility for existing deprec users and acknowledging the awesomeness that is Rack I’m doing all the new stuff in the new deprec:rack namespace. deprec:rails:install_stack now points at the task in deprec:rack

deprec:rails:install_stack calls the following tasks defined in recipes/rails.rb

deprec sets default for the ruby interpreter, webserver, app server and database. You can override them by setting them again in your deploy.rb (or elsewhere).

]]>
http://deprec.org/recipes/ruby-on-rails-stack/feed/ 0
Ruby http://deprec.org/recipes/ruby/?utm_source=rss&utm_medium=rss&utm_campaign=ruby http://deprec.org/recipes/ruby/#comments Wed, 25 May 2011 13:59:07 +0000 http://deprec.org/?p=287 While Ubuntu ships with Ruby, it’s such a fast moving target that the packages date quickly. Installing an REE deb package with deprec is the quickest way to get more up to date. It’s the default version installed when you call the generic command:

cap deprec:ruby:install HOSTS=lucid

Install Ruby Enterprise Edition

My current preferred option is to install Phusion’s deb package. It’s Ruby 1.8.7 with some improvements to get better memory usage.

$ cap deprec:ree:install HOSTS=lucid
    triggering load callbacks
  * executing `deprec:connect_canonical_tasks'
  * executing `deprec:ree:install'
1. ree_lucid32
2. ree_src
3. ree_lucid
?  3

Advanced Tip

You can avoid being prompted by setting :ree_src_package to one of the listed values.

set :ree_src_package, 'ree_lucid'

Install MRI Ruby

If you’re after Ruby 1.9.x or just like waiting for things to compile then install the “official” version.

$ cap deprec:mri:install HOSTS=lucid
    triggering load callbacks
  * executing `deprec:connect_canonical_tasks'
  * executing `deprec:mri:install'
1. mri_1_8_7
2. mri_1_9_2
?  2

Advanced Tip

You can avoid bring prompted by setting :mri_src_package to one of the listed values.

set :mri_src_package, 'mri_1_9_2'
]]>
http://deprec.org/recipes/ruby/feed/ 0
Network http://deprec.org/recipes/network/?utm_source=rss&utm_medium=rss&utm_campaign=network http://deprec.org/recipes/network/#comments Wed, 25 May 2011 13:50:51 +0000 http://deprec.org/?p=282 When I spin up new virtual machines in the lab they come into the world with the same IP (.69) and the hostname of ‘template’. The following recipe makes updating the hostname and networking details a breeze. If the my workstation can resolve the new hostname to an IP (DNS or /etc/hosts) deprec will make sensible suggestions for network addresses.

$ cap deprec:network:config HOSTS=lucid
    triggering load callbacks
  * executing `deprec:connect_canonical_tasks'
  * executing `deprec:network:config'
  * executing `deprec:network:hostname'
Enter the hostname for the server
lucid2
<...lines removed for clarity...>
Number of network interfaces  |1|

address  |192.168.56.105|

netmask  |255.255.255.0|

broadcast  |192.168.56.255|

default gateway  |192.168.56.1|

<...lines removed for clarity...>

About to restart networking on lucid
Are you 'down with that'?  |y|
y
  * executing "sudo -p 'sudo password: ' /etc/init.d/networking restart"
    servers: ["lucid"]
    [lucid] executing command
 ** [out :: lucid] * Reconfiguring network interfaces...
 ** [out :: lucid]

Advanced Tip
I set the following in ~/.caprc so I don’t get prompted for DNS servers and search path.

set :network_dns_nameservers, '192.231.203.132 192.231.203.3'
set :network_dns_search_path, 'failmode.com'
]]>
http://deprec.org/recipes/network/feed/ 0
SSH http://deprec.org/recipes/ssh/?utm_source=rss&utm_medium=rss&utm_campaign=ssh http://deprec.org/recipes/ssh/#comments Wed, 25 May 2011 13:38:05 +0000 http://deprec.org/?p=278 You want to disable password based access to servers so you need a painless way to manage users ssh pubkeys. These recipes help you do both.

Setup a user’s SSH public keys

If you’re setting up keys for yourself  you can just hit enter. deprec looks in your homedir for your public key.

If you’re pushing out keys for another user, deprec looks for their key and alerts you if it can’t be found.

$ cap deprec:ssh:setup_keys HOSTS=lucid
    triggering load callbacks
  * executing `deprec:connect_canonical_tasks'
  * executing `deprec:ssh:setup_keys'
Setup keys for which user?  |mbailey|
fred

          Could not find ssh public key(s) for user fred

          Please create file containing ssh public keys in:

          config/ssh/authorized_keys/fred

Push out some smarter SSH configs

While you *could* just push out my version of sshd_config without reading through it that would be placing blind faith in me and rubygems.org. We’re going to generate the configs locally and then push them out instead

Generate a copy of SSH configs to keep under source control

$ cap deprec:ssh:config_gen
    triggering load callbacks
  * executing `deprec:connect_canonical_tasks'
  * executing `deprec:ssh:config_gen'

File exists (config/ssh/etc/ssh/sshd_config).
    Overwrite? ([y]es, [n]o, [d]iff)  |n|
y
[done] config/ssh/etc/ssh/sshd_config written
[skip] Identical file exists (config/ssh/etc/ssh/ssh_config).

Finally push out some smarter SSH configs

deprec’s :config tasks always push out local copies of config files in preference to generating them.

cap deprec:ssh:config HOSTS=lucid
]]>
http://deprec.org/recipes/ssh/feed/ 0
Users http://deprec.org/recipes/users/?utm_source=rss&utm_medium=rss&utm_campaign=users http://deprec.org/recipes/users/#comments Wed, 25 May 2011 13:34:25 +0000 http://deprec.org/?p=274 Create user accounts on remote servers complete with public key access and sudo access if desired. This is handy when you’re given the root account of a new VPS and want to create an account for yourself. It’s also great for adding a new user to multiple accounts in parallel.

Change root password

I run this when I’m given the root account of a new VPS.

$ cap deprec:users:passwd HOSTS=lucid1 USER=root
triggering load callbacks 
* executing `deprec:connect_canonical_tasks' 
* executing `deprec:users:passwd' 
Enter userid |root|
Enter new password for root ********

Create a new user account

$ cap deprec:users:add HOSTS=lucid 
triggering load callbacks 
* executing `deprec:connect_canonical_tasks' 
* executing `deprec:users:add' 
Enter userid |mbailey| 
Should this be an admin account? |no| 
yes 
Enter new password for mbailey ******** 
Re-enter new password for mbailey ********

Change other user’s password

This can be a lot quicker than SSH’ing into a number of hosts to change a user’s password.

$ cap deprec:users:passwd HOSTS=lucid1,lucid2,lucid3,lucid4 
triggering load callbacks 
* executing `deprec:connect_canonical_tasks' 
* executing `deprec:users:passwd' 
Enter userid |mbailey| 
Enter new password for mbailey ********
]]>
http://deprec.org/recipes/users/feed/ 0
Nagios http://deprec.org/recipes/nagios/?utm_source=rss&utm_medium=rss&utm_campaign=nagios http://deprec.org/recipes/nagios/#comments Wed, 25 May 2011 13:12:55 +0000 http://deprec.org/?p=260

Nagios is a powerful monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes.

First launched in 1999, Nagios has grown to include thousands of projects developed by the worldwide Nagios community. Nagios is officially sponsored by Nagios Enterprises, which supports the community in a number of different ways through sales of its commercial products and services.

http://www.nagios.org/about

 

For each command, append HOSTS=target.host.name

Install Nagios server

cap deprec:nagios:install
cap deprec:nagios:gen_host # One way to add hosts to monitor
cap deprec:nagios:config

Configure clients to accept requests

cap deprec:nrpe:install
cap deprec:nrpe:test_local  # does nrpe query from local host
cap deprec:nrpe:test_remote # does nrpe query from nagios server
]]>
http://deprec.org/recipes/nagios/feed/ 0