Simple and efficient cron management

Posted by Ryan Uber | MySQL,Puppet | Thursday 29 April 2010 1:57 am

Keeping track of scheduled cron jobs is not always the easiest thing to do with Puppet — especially if you are managing systems that other people may have added their own cron jobs to, whether that be within the cron configuration files or in an individual user’s crontab.

Equally difficult is managing a plethora of servers and being responsible for performing and maintaining the backups for all of them. A small part of this includes dumping MySQL databases into a portable format on a regular basis.

Puppet makes both of these tasks easy. So, in order to get the backups running via cron, let’s explore some options.

Managing cron jobs
Keeping tabs on your cron jobs (no pun intended) is actually a lot simpler than one would think with Puppet. However it took me a few go’s at implementation before I came to a sound solution.

The first thing I tried was using Puppet’s built-in cron class, like this:

cron { "dbdump":
    command => "/usr/local/sbin/dbdump",
    user    => "root",
    hour    => 0,
    minute  => 0
}

As you see, I created a script called dbdump to be run by this cron entry. It is a simple bash script that performs a “SHOW DATABASES;”, loops through them, and dumps them all to flat text files utilizing mysqldump.
(more…)

Screenshot sharing made easy from your desktop

Posted by Ryan Uber | Apache,Bourne-Again Shell (bash),Linux | Monday 19 April 2010 4:39 pm

As a person who does a lot of collaborative development, I constantly find the need to display a screenshot of exactly what I am seeing to another developer. I came up with this stupid little script that will do just that.

On invocation, it presents you with a “select area” cursor on your mouse pointer so that you can drag out the area you want to screenshot. It does this using the “import” utility from ImageMagick. Naturally, this means that ImageMagick is required for this script to work.

Here is the script, explanation shall follow:

#!/bin/bash
# SCREENSHOT UTILITY
MY_IPADDRESS=$(/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | awk -F: '{print $2}')
SCREENSHOT_COUNT=$(ls ~/www | wc -l)
let SCREENSHOT_NUM=${SCREENSHOT_COUNT}+1
FILE="~/www/screenshot_${SCREENSHOT_NUM}"
import ${FILE}.gif
mogrify -quality 100 -border 2x2 -bordercolor '#FFFFFF' ${FILE}.gif
mogrify -quality 100 -border 1x1 -bordercolor '#000000' ${FILE}.gif
mogrify -quality 100 -border 5x15 -bordercolor '#CCCCCC' ${FILE}.gif
convert -quality 100 -border 1x1 -bordercolor '#000000' ${FILE}.gif ${FILE}.jpg
mogrify -quality 100 -pointsize 9 -fill '#555555' -font helvetica -gravity SouthEast -annotate +20+3 "$(whoami)@$(hostname), $(date +%x\ %X)" ${FILE}.jpg
rm -f ${FILE}.gif
xmessage "http://${MY_IPADDRESS}/screenshot_${SCREENSHOT_NUM}.jpg" &
echo "http://${MY_IPADDRESS}/screenshot_${SCREENSHOT_NUM}.jpg" | xsel -i

(more…)

Conditionally create a file within a puppet manifest

Posted by Ryan Uber | Bourne-Again Shell (bash),Puppet | Saturday 17 April 2010 4:40 pm

I came up with this solution to conditionally create / initialize a configuration file using Puppet. What I wanted to do was create the file if it did not exist or if it was empty, add my header comments to it. As far as I know, and after an hour or so of poking around Puppet’s documentation,  I could not find an integrated way of doing this. I like to avoid using rickity methods of accomplishing something wherever possible, so I was about to scrap the idea altogether. However, I came up with a moderately elegant solution that I was satisfied with to accomplish just this, using an “unless” requirement. Here is the actual code, modified for this post:

class httpd {
    $httpd_extras_file = "/etc/httpd/conf.d/zz_extras.conf"
    $httpd_extras_text = "# ADDITONAL APACHE CONFIGURATION FILE"
    exec { "c_zzhttpdextras":
        command     => "/bin/echo '$httpd_extras_text' > $httpd_extras_file",
        unless      => "/usr/bin/test -s $httpd_extras_file",
        require     => [
                        File["dir_httpd_confd"],
                        Package["httpd"]
                       ];
    }
}

(more…)

Next Page »