views:

120

answers:

4

Given some unix program which I've compiled, what might I need to do to relocate it to a different directory and have it continue running correctly.

I'm thinking of Perl, but would be interested in other systems like Apache which also seem to fail when this is done. To motivate the question, being able to perform this sort of relocation would be very useful when bundling other systems as part of a product install.

For what it's worth, ActivePerl's install process seems to contain some magic which performs the relocation during the install..

Installing ActivePerl...
Copying files to /opt/ActivePerl-5.8...done
Relocating...done (164 files relocated)
Generating HTML documentation...done
Syncing perl PPM database with .packlists...done 

ActivePerl has been successfully installed at /opt/ActivePerl-5.8.

Can anyone enlighten me as to what's happening behind that 'Relocating...' line?

A: 

It depends of what do you mean under "relocate". You can run the binary and then move it to another directory, it should work under Linux.

So, you can write a program which will move all your binaries and configuration files into another directory and then just change current working directory.

Elalfer
I'm not sure it "should just work" - at least it doesn't seem to for perl and apache (but does for Java for what it's worth)
Matt Sheppard
If you move just the perl binary it will work, but if you move any of the libraries it won't be able to find them. Their location is hard coded in the binary.
Schwern
Not in Linux, libraries could not be hard coded.Use LD_LIBRARY_PATH env. variable to add a search path for libraries.
Elalfer
Yeah, LD_LIBRARY_PATH can work, but I'm thinking more of something I might install onto an end user's system (where LD_LIBRARY_PATH probably would not be acceptable) than a quick hack to get something working for myself. Thanks though.
Matt Sheppard
@Elafler I was referring to Perl libraries (.pm files), not the shared libraries associated with the binary.
Schwern
+3  A: 

A lot of it depends on the program. Some programs are fairly self-contained and thus handle moves more gracefully than other programs which have directory paths in externally-located configuration files or other less-forgiving elements.

Amber
Yeah, I guess I'd be interested to know what the elements are, and how to update them. For example, the perl binary seems to pick up some library paths embedded within the binary. I guess there must be some way to fix them as part of the relocation...
Matt Sheppard
+3  A: 

Active Perl doesn't compile perl on your system, it just unpacks and copies it to the right location.

The problem is that a Perl install has many files that need to have installation specific information, such as where to find libraries, where the install is located, and so on. These files are modified to have the correct information during the relocation phase.

daotoad
+7  A: 

When you compile perl, it expects certain files at certain locations. You can see some of those paths with perl -V. For ActivePerl, when you want to move the entire installation, you have to update where perl expects to find things and where its various helper programs expect to find perl. See the documentation for ActiveState's reloc_perl, and maybe look at the source if you have it.

What ActivePerl does has no general bearing on what you would do with other programs. It depends on what they each do and expect.

brian d foy
This would be the correct answer. I work for the company that used to own ActiveState, and have asked ActivePerl authors about this very issue.
Chris Simmons
Cool - Where could I start in learning how to work out how to do this kind of thing to an arbitrary program?
Matt Sheppard
@Matt Last I looked, the technique is to configure the binary with the root of all the hard-coded paths to something like "/xxxXXXxxxREPLACEMExxxXXXxxx" and then do a search and replace on the binary with your new root. Its a little terrifying that it works. I don't know how applicable it is to all compilers and executable formats.
Schwern
I tried doing something like that by hand once, but ran into trouble if the path was a different length to the original. I guess if you start with a very long path and fill it out with nulls things might go ok...
Matt Sheppard
@Matt That's exactly what happens.
Schwern