Archive for the ‘Linux’ Category

A friend asked me for some help the other day. At the place he works at they use IIS on their production servers, but each developer works locally using Apache. Why use different webservers for production and development? He said they do it because its easier to develop locally with Apache. My guess is its easier because you can run multiple sites at once with Apache. With IIS on a desktop machine you can only run one site at a time. I do the exact same thing at my job, actually.

Anyway, once in a while this causes issues. In this case, there was code on the server that required a username and password in order to access the page. The security was done at the web server level, aka “HTTP authentication”, which causes your browser to prompt you for a username and password. These credentials then get sent along in the request headers (its actually a little more complicated than that but I won’t get into that here). After authenticating, the username is available to ColdFusion as a CGI variable – CGI.REMOTE_USER.

When using IIS, that value is also available as CGI.AUTH_USER. In all CGI variable specs I could find, they all reference REMOTE_USER, not AUTH_USER, I’m not sure when AUTH_USER started to be used. Anyway, this ColdFusion code running on the IIS server would look to the CGI.AUTH_USER variable and display some things differently depending on who the user was.

This posed a problem when trying to run this code locally under apache. The CGI.AUTH_USER variable did exist, but it was always blank. One could change the code to use the more multi-platform friendly “REMOTE_USER”, but sometimes there are hurdles to changing existing code.

But there is a way to mimic the behavior of IIS, by copying the REMOTE_USER value into AUTH_USER. Its only three simple lines but it took me quite a while to figure this out.

RewriteEngine on
RewriteCond %{REMOTE_USER} (.*)
RewriteRule .* - [E=AUTH_USER:%1]

You’ll need to have mod_rewrite enabled of course. Usually all you need to do is uncomment a line that looks like this in httpd.conf:

LoadModule rewrite_module modules/mod_rewrite.so

The three magic lines can go into the httpd.conf file, or you could place them in a .htaccess file in the directory you’re working in.

I was installing ColdFusion 7.02 on a client’s CentOS 5.2 Linux server the other day and received an error when running the installer. Note that this OS is NOT supported by Adobe for this version of ColdFusion. This is a fairly old version of CF being installed on a pretty current version of CentOS. The error was:

[root@server tmp]# ./coldfusion-702-linux.bin
Preparing to install...
Extracting the JRE from the installer archive...
Unpacking the JRE...
Extracting the installation resources from the installer archive...
Configuring the installer for this system's environment...
awk: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
dirname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/bin/ls: error while loading shared libraries: librt.so.1: cannot open shared object file: No such file or directory
basename: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
dirname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
basename: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
Launching installer
grep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/tmp/install.dir.3348/Linux/resource/jre/bin/java: error while loading shared libraries: libpthread.so.0: cannot open shared object file: No such file or directory

There is a hard coded value in the installer thats causing things to get messed up. Fixing this is fairly easy, you can modify the installer like this:

cp coldfusion-702-linux.bin coldfusion-702-linux.bin.backup
cat coldfusion-702-linux.bin.backup | sed "s/export LD_ASSUME/#xport LD_ASSUME/" > coldfusion-702-linux.bin

That comments out the offending line in all places in the installation script.

More discussion on this here:
http://www.billmitchell.org/coldfusion/centos5/mx7_apache.php
http://www.talkingtree.com/blog/index.cfm/2006/12/6/Running-ColdFusion-MX-7-on-Fedora-Core-6-Linux

You will probably run into more issues installing CF7 on this version of CentOS but it can be done. I also had to upgrade the connector to work with Apache 2.2 (when CF7 came out the connector was designed to run on Apache 2.0). The Adobe KB article that discusses this is here: http://kb.adobe.com/selfservice/viewContent.do?externalId=8001e97&sliceId=1. Their example didn’t quite work for me because its defaulting to the version of Java thats on your OS, which won’t work unless its a Sun 1.4.2x version. So I just used the JRE that is bundled with ColdFusion to install the new connector:

/opt/coldfusionmx7/runtime/jre/bin/java -Dtrace.ci=1 -jar ../../runtime/lib/wsconfig.jar \
        -server coldfusion \
    -ws apache \
        -dir /etc/httpd/conf \
        -bin /usr/sbin/httpd \
        -script /etc/rc.d/init.d/httpd \
        -coldfusion -v

I thought that was the last hurdle but when we tried to log in to the ColdFusion administrator we got an error about “The Graphing service is not available”. The message in the log file was “Unable to initialize Graphing service: java.lang.UnsatisfiedLinkError: /opt/coldfusionmx7/runtime/jre/lib/i386/libawt.so: libXp.so.6: cannot open shared object file: No such file or directory”. This was fixed by installing the libXp library:

yum install libXp

I was trying to execute a .cfm page on a new CentOS 5.2 server and I received this error. Not all requests were erroring out, the CF Administrator was working fine as were other simple pages. But when I tried to load a page that instantiated some java objects, I got this error.

"coldfusion.jsp.CompilationFailedException: Errors reported by Java compiler: jikes: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory

I checked to make sure libstdc++ was installed, and it was, although not version 5. I checked another one of our Linux CF8 servers, it didn’t have version 5 installed either, so I didn’t think that was the problem. I noticed the other server had some compat libs installed that I was missing though. I ran this command: yum install compat-libstdc\* which installed two RPMs: compat-libstdc++-296 and compat-libstdc++-33. Then I restarted ColdFusion, and was able to execute the page with no errors.

One of my clients has a site where they offer their archived radio shows for downloading. The files they provide us come from directly from the radio station. They are already in MP3 format, but they are encoded at an insanely high bitrate for a talk show, and are in stereo to boot. This can eat up a lot of bandwidth unnecessarily.

There are over 100 files, so opening each one in an audio tool such as Audacity or SoundBooth to re-compress would be quite tedious. Here is a short script I wrote to re-encode the files. Note that I did this on our Linux server, but since Perl and lame/notlame are both available for Windows you shouldn’t have a problem doing it there either.
Continue reading ‘Batch conversion of audio files – shrinking MP3s’ »

Sometimes its necessary to delete all the .svn folders from your subversion working copy.

Here is a simple way to do it on Linux:

rm -rf `find . -name .svn`

That might not work if you have hundreds or thousands of folders, as it might be too many arguments for the rm command. I still like it because its simple. But a more robust way would be:

find . -name .svn -prune -exec rm -rf {} \;

This calls rm on each file separately.

I haven’t tried the following, but on Windows you may be able to:

Create a cleanSVN.cmd file in the root containing these lines:

for /f “tokens=* delims=” %%i in (’dir /s /b /a:d *svn’) do (
rd /s /q “%%i”
)

You could also try browsing to the files in Windows Exporer and then:
Right click on the folder and click Search..
Enter .svn as the filename to search for.
Click “More advanced options” and select:
– Search hidden files and folders
– Search subfolders
Press search button and delete the folders you find appropriate.

The Windows tips came from Axel’s blog at http://www.axelscript.com/2008/03/11/delete-all-svn-files-in-windows/

We’ve been having some issues with people committing to the subversion server without entering a comment. Its easy to to require a comment using a “pre-commit” hook, which is a script that runs before someone’s changes are committed to the repository. A sample commit hook is supplied with subversion that you can enable to require comments. The problem is it doesn’t report back any error message (users will just get a generic “commit failed” in their svn client), and there is no provision for making sure the comment is a minimum length.

I tried to modify the example script, but I’m pretty bad with shell scripting. I looked for a perl one, which I knew I could easily modify, but couldn’t find any. So I whipped this one up:
Continue reading ‘Require subversion comments – a perl pre-commit hook’ »

There has been some discussion on various ColdFusion discussion lists regarding the maximum heap size you can allocate to ColdFusion/Jrun. Windows allows a process to grab as much as 2GB of contiguous memory. Subtracting out memory for overhead, permgen memory, etc. you are left somewhere with 1.5-1.8GB available for general heap memory.

We were considering moving one of our clients to a Linux server if that would allow us to allocate more memory to the heap. In my research, it seemed the opinions were split about 50/50 as to if Linux would allow us to allocate more than 2GB of memory. So I decided to test for myself. I placed an order for 4GB of memory and waited for them to arrive.

Once I had swapped out my 4 256MB modules for the 4 1GB modules, I increased the heap size (Xms and Xmx options in jvm.config) to 2048 and restarted the server. No problems! I kept increasing by 100mb at a time until I reached 2600 – there it failed to start, so I backed it down to 2500mb. With the permgen and other overhead, Jrun was taking up about 2950Mb of memory – indicating a 3GB limit. I have been running this way for a few days now with no problems.

Your experience may vary of course, depending on what memory options you have in your jvm.config file. I did not need to do anything special other than bump up the Xms and Xmx values.

So the short answer is Yes, you can allocate about 1GB more memory to ColdFusion when running on Linux.

The command line statistics program supplied with ColdFusion, cfstat, has never worked for me. I’ve never tried it on Windows, but I have tried it on Linux on versions 6 and 7, and now version 8.

A little digging around told me why it never worked in CFMX 6-7. Apparently the cfstat script was looking for a particular jar file using a relative path – so it only worked if you were calling it from within the ColdFusion installation directory, which I guess I never did. Looking at the cfstat script in version 8, I can see they specify the full path.

But cfstat still wasn’t working for me in CF8, I got this error message:
Continue reading ‘Getting cfstat to work’ »

A few months ago I decided to go on a book binge and acquired a stack of books about two feet tall. It includes classics such as The Pragmatic Progammer and Practices of an Agile Developer, as well as some on Java, Asterisk, Extreme Programming, Linux Firewalls, and a NASCAR book thrown in for good measure.

I’ve gotten through a couple, and will be posting reviews of a few of them. This week I finished Apache Security, from O’Reilly. I found this book while browsing the programming section of Borders (the programming section of my local Borders is amazing!), and I’ve found it to be a real gem.
Continue reading ‘Book Review – Apache Security’ »

Some people have encountered problems during the ColdFusion MX 7 install on Linux/Apache. When you first start the ColdFusion server, you may see something like this:

Configuring the web server connector (Launched on the first run of the ColdFusion MX 7 start script)
Running apache connector wizard...
=======================================
There was an error while running the connector wizard
Connector installation was not successful

Continue reading ‘Problems installing the ColdFusion connector on Linux/Apache’ »