| 1 | # -*- perl -*- | ||
| 2 | |||
| 3 | # Copyright (c) 2010 AdCopy | ||
| 4 | # Author: Jeff Weisberg | ||
| 5 | # Created: 2010-Jan-18 18:10 (EST) | ||
| 6 | # Function: stub for customization | ||
| 7 | # | ||
| 8 | # $Id: MySelf.pm,v 1.1 2010/11/01 18:41:43 jaw Exp $ | ||
| 9 | |||
| 10 | package AC::MrGamoo::MySelf; | ||
| 11 | use AC::MrGamoo::Customize; | ||
| 12 | use AC::Import; | ||
| 13 | use strict; | ||
| 14 | |||
| 15 | our @ISA = 'AC::MrGamoo::Customize'; | ||
| 16 | our @EXPORT = qw(my_server_id my_network_info my_datacenter); | ||
| 17 | our @CUSTOM = (@EXPORT, 'init'); | ||
| 18 | |||
| 19 | |||
| 20 | 1; | ||
| 21 | |||
| 22 | =head1 NAME | ||
| 23 | |||
| 24 | AC::MrGamoo::MySelf - customize mrgamoo to your own environment | ||
| 25 | |||
| 26 | =head1 SYNOPSIS | ||
| 27 | |||
| 28 | emacs /myperldir/Local/MrGamoo/MySelf.pm | ||
| 29 | copy. paste. edit. | ||
| 30 | |||
| 31 | use lib '/myperldir'; | ||
| 32 | my $m = AC::MrGamoo::D->new( | ||
| 33 | class_myself => 'Local::MrGamoo::MySelf', | ||
| 34 | ); | ||
| 35 | |||
| 36 | =head1 DESCRIPTION | ||
| 37 | |||
| 38 | provide functions to override default behavior. you may define | ||
| 39 | any or all of the following functions. | ||
| 40 | |||
| 41 | =head2 my_server_id | ||
| 42 | |||
| 43 | return a unique identity for this mrgamoo instance. typically, | ||
| 44 | something similar to the server hostname. | ||
| 45 | |||
| 46 | sub my_server_id { | ||
| 47 | return 'mrm@' . hostname(); | ||
| 48 | } | ||
| 49 | |||
| 50 | =head2 my_datacenter | ||
| 51 | |||
| 52 | return the name of the local datacenter. mrgamoo will use this | ||
| 53 | to determine which systems are local (same datacenter) and | ||
| 54 | which are remote (different datacenter), and will tune various | ||
| 55 | behaviors accordingly. | ||
| 56 | |||
| 57 | sub my_datacenter { | ||
| 58 | my($domain) = hostname() =~ /^[\.]+\.(.*)/; | ||
| 59 | return $domain; | ||
| 60 | } | ||
| 61 | |||
| 62 | Note: map/reduce jobs are extremely network intensive. it is not | ||
| 63 | recommended to spread your servers out. you really want them all | ||
| 64 | plugged into one big switch. one big fast switch. | ||
| 65 | |||
| 66 | =head2 my_network_info | ||
| 67 | |||
| 68 | return information about the various networks this server has. | ||
| 69 | |||
| 70 | sub my_network_info { | ||
| 71 | my $public_ip = inet_ntoa(scalar gethostbyname(hostname())); | ||
| 72 | my $privat_ip = inet_ntoa(scalar gethostbyname('internal-' . hostname())); | ||
| 73 | |||
| 74 | |||
| 75 | return [ | ||
| 76 | # use this IP for communication with servers this datacenter (same natdom) | ||
| 77 | { ip => $privat_ip, natdom => my_datacenter() }, | ||
| 78 | # otherwise use this IP | ||
| 79 | { ip => $public_ip }, | ||
| 80 | ] | ||
| 81 | } | ||
| 82 | |||
| 83 | =head2 init | ||
| 84 | |||
| 85 | inialization function called at startup. typically used to lookup hostanmes, IP addresses, | ||
| 86 | and such and store them in variables to make the above functions faster. | ||
| 87 | |||
| 88 | my $HOSTNAME; | ||
| 89 | my $DOMAIN; | ||
| 90 | sub init { | ||
| 91 | $HOSTNAME = hostname(); | ||
| 92 | ($DOMAIN) = $HOSTNAME =~ /^[\.]+\.(.*)/; | ||
| 93 | } | ||
| 94 | |||
| 95 | =head1 BUGS | ||
| 96 | |||
| 97 | none. you write this yourself. | ||
| 98 | |||
| 99 | =head1 SEE ALSO | ||
| 100 | |||
| 101 | AC::MrGamoo | ||
| 102 | |||
| 103 | =head1 AUTHOR | ||
| 104 | |||
| 105 | You! | ||
| 106 | |||
| 107 | =cut |