1. Proxying DBI with DBD::Gofer
and App::Staticperl
San Diego.pm talk
May 17, 2012
2. Environment
• Need to connect to Informix IDS servers
• Remote systems with strict firewalls
• Production systems, no configuration change
possible
• Minimal footprint required for maintenance
• Sounds complicated? Because it is.
3. Solution: DBD::Gofer
• Stateless DBI proxy
• Works by changing DSN connect string
• Or even setting DBI_AUTOPROXY environment
variable
• Transparent for DBI applications
• Support different transports
• One of them is “stream” (SSH)
4. Server side
• Needs to have Perl with recent enough DBI
• Needs database specific DBD (DBD::Informix)
• System Perl is Untouchable, period
• Custom Perl build litters a lot
• Maintenance is PITA
• Answer: App::Staticperl
5. App::Staticperl
• Marc Lehmann’s Yet Another brilliant work
• Allows building all-in-one Perl executable
• Including pure Perl modules
• Including XS modules and shared objects (!)
• Not unlike PAR::Packer, but actually works
• Unlike PAR, no zips and no write permission
required
6. App::Staticperl gotchas
• Not very mature: may or may not work for
your specific application
• May take extensive Unix/Linux knowledge
• May take some Perl building skills
• In short, you gotta know what you’re doing
• … but even then, some modules Just Don’t
Work
7. Case study
• Building static Perl for Solaris
• Minimal module list: DBI, DBD::Informix
• Some dependencies as well
• Using GCC 4.4
• Linking against native Informix CSDK
• Bundling it all including environment startup
into one fat Perl executable
8. Step 1: Build App::Staticperl
• Default installation blows up in Solaris (make
test fails)
• Do forced make install
• Manually edit ~/perl/bin/staticperl
• Lots of small system specific changes
• Try running “staticperl install”, see if it breaks
• Make changes, try running, iterate
9. Step 2: install CPAN modules
• staticperl instcpan DBI …
• Some modules may fail at first
• A dose of patience and some big wrench is
required
• Finally all tests should reasonably pass
10. Step 3: Customizing for Informix
• Add Informix configuration variables right
there in staticperl
• Most important: PATH, LD_LIBRARY_PATH
• Linking against shared objects in known
location
• Utmost importance: LD_RUN_PATH (ld -R)
• Prepare bootstrap.pl: set up Informix
environment variables
11. Step 4: Customizing for DBI
• Prepare “bundle” file: take bundle.smallperl as
an example (Remove first line “static”! Almost
drove me mad!)
• Add DBI, DBD::Gofer::*, DBD::Informix
• Add perl5db.pl and Term::ReadLine for
debugger (you’ll need it, trust me)
• Add utf8, Encode, whatever
12. Step 5: Building
• ~/perl/bin/staticperl mkperl -v --boot
bootstrap.pl gofer.bundle
• -v to see if something goes wrong
• --boot sets bootstrap script, it gets executed
when static perl starts up
• Don’t use “exit 0” in bootstrap, you’d be much
surprised (remember perl5db.pl? Invaluable.)
13. Finita
• Voila, we’ve got a statically built perl
• One 5.5M executable file, no dependencies
• All run time library paths are built in
• Send it over to remote system and test
• <Live demo here>
14. Questions?
• I have working staticperl script for Solaris, with
DBD::Informix built in
• Not CPAN quality (ugh), so isn’t published
• But if you’re curious, drop me a line:
Alex Tokarev <tokarev@cpan.org>