palette has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I have given a task to replicate the CPAN modules installed in one server to another server
I am using FreeBSD. I executed the command pkg_info and got the list of cpan modules in there
I installed the cpan modules using ppm. perl -MCPAN -e 'install <modulename>'
Now when I started deploying my code on the destination server I realized the CPAN modules version used in the source server is different from the one i installed. That had impact on the code.
In between can anyone tell how can I install the same module and versions of module from the source server to my new server
I also heard like we can take a snapshot of the CPAN modules installed in the server.
So is that I can copy the snapshot directly to the destination server.
Thanks for the help in advance.
Re: perl modules replication
by brian_d_foy (Abbot) on Sep 13, 2007 at 20:30 UTC
|
I just wrote about this in The Perl Review. It's not an easy job (yet). The trick is to get the same versions of everything on the second machine, whether or not those versions are still on CPAN. Most tools only installed the latest version, and often that's not what you want.
The sequence goes something like this for the general case where the platforms are not the same (if they are the same, you might (might!) just be able to copy a directory and be done with it):
- Discover all the module versions on the reference machine
- Match those up to distributions on CPAN or BackPAN. That's the hard part because there isn' t anything out there to help you (not yet, working on it). PAUSE has a map of current modules to latest release distros, but doesn't have that information historically.
- Grab those distros and put them into a MiniCPAN using CPAN::Mini::Inject. You might have to remove some newer dists. There's a bit of manual work here (so far). Also inject any local or private modules you want in there.
- Now, install your bundle or Task from your MiniCPAN using the normal installation process.
- Find out what is different between the two installations and adjust the MiniCPAN until they come out the same.
- Once you have the MiniCPAN set up the way you like it, freeze it. Put it on a CD or something. That's your application snapshot from which everyone else will use.
- If you want to update some distros, start over at the point where you add to MiniCPAN.
I have no idea if this will work with ActivePerl or Strawberry Perl. I finally got VMware running and Windows installed, but I haven't tested it yet.
I'll be giving a talk about this at the Los Angeles Perl Mongers in about a week, and soon after that it should be available as a perlcast.
| [reply] |
Re: perl modules replication
by fmerges (Chaplain) on Sep 13, 2007 at 16:57 UTC
|
perl -MCPAN -e 'autobundle'
Later you copy the module created under ~/.cpan/Bundle to the other hosts, in the same dir, and the you do:
perl -MCPAN -e 'install Bundle::replace_string'
Regards,
fmerges at irc.freenode.net
| [reply] [d/l] [select] |
|
| [reply] [d/l] |
Re: perl modules replication
by andreas1234567 (Vicar) on Sep 13, 2007 at 18:28 UTC
|
At the very least you can use ExtUtils::Installed to determine what modules in which version you have currently installed:
use strict;
use warnings;
use ExtUtils::Installed;
my $instmod = ExtUtils::Installed->new();
foreach my $module ($instmod->modules()) {
my $version = $instmod->version($module);
if ( $version ) {
print "$module installed, version $version\n";
} else {
print "$module installed, version not available\n";
}
}
__END__
Sort::Versions might be useful when comparing module "numbers".
| [reply] [d/l] |
Re: perl modules replication
by andyford (Curate) on Sep 13, 2007 at 16:04 UTC
|
I'm not a FreeBSD expert, but if you install modules from CPAN, they won't be under the control of your FreeBSD package management system, so I think you can forget the info you get from pkg_info, it's not complete.
If you're installing your CPAN modules in the default location, can you just copy your perl installation tree to the target systems?
| [reply] |
|
| [reply] |
Re: perl modules replication
by mr_mischief (Monsignor) on Sep 13, 2007 at 16:10 UTC
|
Don't confuse PPM and CPAN.pm -- they are similar but different.
IIRC, it's possible to download a specific version of a module from CPAN, but I'm at a loss how at the moment.
If your systems are the same OS, same OS version, same processor type, and everything is compiled with the same compiler then you can indeed usually get by with copying your modules over wholesale. (For pure Perl modules, you can do it even if these criteria aren't met.)
As for where they are, your modules probably live someplace like /usr/lib/perl or /usr/local/lib/perl but I'm not sure where they'll be on a particular system, and it's been a long time since I've touched FreeBSD so I can't even tell you for certain where your OS installation would stick them by default.
| [reply] |
Re: perl modules replication
by bart (Canon) on Sep 14, 2007 at 11:13 UTC
|
You can be more specific in the command to CPAN, and tell it to install a specific version, if it still is on CPAN. For that, you have to prefix it with (at least) the initials of the author plus a slash, specify the distribution name, and don't forget to append ".tar.gz". (The latter is a mistake in the design of the CPAN API, IMO.)
For example:
perl -MCPAN -e install -e shift YVES/MIME-Lite-3.01_05.tar.gz
if you want to install a specific developer version from MIME::Lite.
Note that I passed the module name through @ARGV (with shift) because it's not a bareword. I find it a bit easier than quoting.
I also heard like we can take a snapshot of the CPAN modules installed in the server.So is that I can copy the snapshot directly to the destination server.
Well, sort of... you can make a list of the currently installed modules using autobundle in the CPAN shell. The result is a Bundle "module", which, if you install it, will install the modules in it; so it's best to weed out all the stuff you don't need, or don't want to touch. (Last I tried, years ago, it tried to reinstall core modules.) I'm not sure it'll indeed try to match up the version. It might: the data is present.
If it doesn then you can still make a script out of the list of items you want, and then you can install them automatically, at least, for the time that version is still on CPAN.
If the architecture is identical, or if the modules don't depend on the architecture, you can indeed make a copy of the file trees for these modules. Better still is to use the directories that make builds when you test or install a module. That's basically what PPM does, too.
It must be possible to automate making a tarball that. | [reply] [d/l] [select] |
|
Hi,
The other day I made an autobundle while doing a backup of a laptop, and I realize that after doing autobundle, besides of creating the Bundle:: file, there was also the modules itself under ~/.cpan/sources/authors/id. So handy for just copying them along with the bundle module.
Regards,
fmerges at irc.freenode.net
| [reply] |
Re: perl modules replication
by dk (Chaplain) on Sep 13, 2007 at 21:16 UTC
|
On source server, run "pkg_create -b your-package-name", that will create your-package-name.tbz from the installed package. Copy that file to destination server and run "pkg_add your-package-name.tbz"; that also takes care of dependencies. | [reply] |
|
|