Category Archives: Systems Administration

Ant & Tomcat Manager on virtual hosts

I’m kicking out a couple freelance projects using Struts and Hibernate in the next couple weeks, this weekend I was fiddling with the Ant build script and I remembered Tomcat Manager App, which allows you to reload contexts while Tomcat is running (as well as start, stop, install etc..). Unfortunately, the /manager application only sees applications within the virtual host it’s running in and because I’m working with a couple different applications, I have multiple virtual hosts and I need to be able to utilize the /manager application from each one.

Turns out it’s not all that hard to get the /manager application working within a different virtual host… as long as you read the documentation very thoroughly. It’s as simple as adding this:

<Context path="/manager" debug="5" docBase="${CATALINA_BASE}\server\webapps\manager" privileged="true" />

(where ${CATALINA_BASE} is the absolute path to your tomcat install) to the virtual host element you have setup in server.xml (for those not experienced with Tomcat, adding a ‘context’ is similar to adding a virtual directory in IIS, make any more sense?). The one gotcha (in bold) is the privileged attribute. It *must* be set to true to run the /manager or /admin applications in virtual host besides localhost.

Reloading the application using Ant is a breeze, the Tomcat documenation includes an example build file, in short all you need is this:

<property name="path" value="/myapp"/>
<property name="url" value="http://localhost:8080/manager"/>
<property name="username" value="myusername"/>
<property name="password" value="mypassword"/>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask"/>
<target name="reload" >
<reload
  url="${url}"
  username="${username}" password="${password}"
  path="${path}"/>
</target>

Make sure that you have the catalina-ant.jar file coped from {Tomcat_install}\server\lib\ to your {Ant_install}\lib. If you are using Eclipse, go to Windows –> Preferences –> Ant –> –> Runtime –> Classpath and add catalina-ant.jar to the Runtime classpath.

ColdFusion & log4j

Integrating log4j and CFMX - An open source Java project gives developers new capabilities The January issue of ColdFusion Developer’s Journal features an article I wrote on how to integrate ColdFusion and log4j entitled “Integrating log4j and CFMX – An open source Java project gives developers new capabilities”. You can read it here.

While not especially interesting for developers writing simple ColdFusion applications, I’m finding that log files are becoming especially useful in applications with multiple tiers and clients. Even if you don’t use log4j and ColdFusion, I’d suggest taking a long look at your application to find out where it might be helpful to make your application more transparent.

Jakarta Latka

I have a peculiar interest in testing tools… I’ve mentioned JMeter (which is more of a stress testing tool) a couple times before, I just found a new one on the Jakarta site call Latka, which “… is a functional (end-to-end) testing tool. It is implemented in Java, and uses an XML syntax to define a series of HTTP (or HTTPS) requests and a set of validations used to verify that the request was processed correctly.

The cool thing about Latka is the non Java part… anyone that understands a little XML can create and/or edit an xml document that defines an ‘test’ and then run it using the Latka engine. So for instance, here at Mindseye our QA team is composed of invididuals with a small amount of programming experience. They could easily create a Lakta test using the xml syntax and then automate the testing of various applications using Latka. Still not convinced, here’s a sample test:

<?xml version=”1.0″ standalone=”no”?>
<!DOCTYPE suite PUBLIC “-//Apache Software Foundation/DTD Latka Test Suite 1.0/EN”
   “http://jakarta.apache.org/commons/latka/dtds/1.0/suite.dtd”>
<suite defaultHost=”http://www.mindseye.com” label=”mindseye”>
   <request path=”/whymindseye/default.cfm” label=”why you should choose mindseye” method=”get” secure=”false” followRedirects=”true”>
      <validate>
      <statusCode code=”200″ />
      <regexp pattern=”What drives landmark companies” />
      </validate>
   </request>
</suite>

Save this to a file and then type:

latka file:PATH_TO_FILE

from the command line. It should check that the page http://www.mindseye.com/whymindseye/default.cfm returns an HTTP status code 200 and that it contains the phrase “What drives landmark companies”.

Unfortunately, Latka doesn’t appear that anyone is working on it (at least since last July).

On a related note, I also found this Slashdot discussion on “Testing Products for Web Applications?“.

Restoring a .bak file to a SQL Server database

This is for my own benefit… when restoring a .bak file to a SQL Server database where the .bak file was not originally backed up from, right click –> All Tasks –> Restore Database –> From device –> Select Devices –> Add your .bak file. Click OK. Click the Options tab. Now on the left side you should see the Logical file name of the database from the .bak file. On the right side under the lable ‘Move to physical file name’, should be the path that the .bak file originally existed as. This field needs to be changed to the path & file name of the database you’re restoring too. After modifying those two fields, check the ‘Force restore over existing database’ and click ‘OK’.

user level security in apache

I needed to lock down a couple directories on this server using Basic Authentication in Apache… in case you’ve ever wanted too, or someday will need too:

1) Add the username to the password file using the htpasswd module:

# htpasswd /etc/httpd/users username

where ‘/etc/httpd/users’ is the name of the file you want your users/passwords stored and ‘username’ is the username you want to add. It’ll ask you for the password, and then again before adding the user to the file. If the file doesn’t exist, usr the -c flag to create the file:

# htpasswd -c /etc/httpd/users username

2) Then add a .htaccess file in the directory you wan to secure that contains this:

AuthName “username”
AuthType Basic
AuthUserFile /etc/httpd/users
require user username

where ‘/etc/httpd/users/’ is the name your passwd file and ‘username’ is the name of the user you want to allow in this directory.

Cronlog

IIS makes it really easy to maintain your log files… in fact, you don’t have to do anything tricky besides checking the appropriate checkbox. Apache on the other hand is a bit more complicated… I did a couple googles tonight looking for the perfect, easy 5 minute solution. This is what I found. Download the source, unzip, run ./configure, run make, run make install and then change your log settings within the appropriate context of your httpd.conf (I put the following directive within each virtual host definition) to something like this:

CustomLog “|/usr/local/sbin/cronolog /etc/httpd/logs/yoursite.com/%Y%m.log” combined

Save httpd.conf and restart Apache.

That’ll create a log file that looks like this:

/etc/httpd/logs/yoursite.com/200303.log

Pretty handy.

rsync: installation and implementation

I wrote up these directions (based on directions @ http://www.hksilver.net/rsync/ on a couple weeks ago when I was doing some work with rsync. Someday I’m sure I’ll need them again… and maybe someone else will benefit. So here goes nothing:

Download this zip file (which contains cygwin1.dll,instsrv.exe,rsync.exe and srvany.exe) (I mirrored it here)

Decompress the contents to c:\rsync.

Copy out cygwin1.dll to c:\(system folder)\system32, where system folder is either winnt or windows depending upon your OS.

Open a command prompt and type:

cd c:\rsync
instsrv Rsync “c:\rsync\srvany.exe”
exit

Click on Start, run, and type in regedit.

Once you’re in the Registry Editor, make the following changes (Quotes ARE important!):

HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet -> Services -> Rsync

Right click on Rsync, New -> Key Key Name: Parameters
Right click on Parameters New -> String Value
Value Name: AppDirectory
Value: “c:\rsync”

Right click on Parameters New -> String Value
Value Name: Application
Value: “c:\rsync\rsync.exe”

Right click on Parameters New -> String Value
Value Name: AppParameters
Value: –config=”c:\rsync\rsyncd.conf” –daemon

Close the Registry Editor.

SOURCE MACHINE
******************************************************
If this is the source machine (ie: a machine you’d like other machines to copy/sync with), open up c:\rsync\rsyncd.conf in notepad and modify the rsync share setting giving it a well-known, descriptive name. Modify the path to point to a directory that you want to make available for others to get access too. Save and close rsyncd.conf.

Open up Administrative Tools either off the Start Menu or in Control Panel. Double click Services. Scroll down the list to Rsync. Highlight it and start the service.

To test it, open up a command prompt and type:

telnet localhost 873

If you get a connection, rsync was installed successfully. Congratulations!

DESTINATION MACHINE
******************************************************
If this is a machine you’d like to have copy/sync with a remote host, then bring up a command line and type:

cd c:\rsync
rsync -rt –progress –delete [INSERT HOST]::[INSERT SHARE] [INSERT DESTINATION PATH]
exit

For example, if I had a staging server located at ip address 10.10.1.162 with a share called “staging.cephas.net” that I wanted to sync with, I’d type something like this:

rsync -rt –progress –delete 10.10.1.162::staging.cephas.net f:/fInetPub/hosts/live.cephas.net/wwwroot/images/

where 10.10.1.162 is my staging server, staging.cephas.net is the rsync share, and f:/fInetPub/hosts/live.cephas.net/wwwroot/images/ is the destination that I want to be synced up. Note that if you don’t want files deleted from destination that have been deleted in the source, you should remove the –delete option.

If you’d like run through a sync as a test, add the -n flag like this:

rsync -rtn –progress –delete 10.10.1.162::staging.cephas.net f:/fInetPub/hosts/live.cephas.net/wwwroot/images/

Rsync will list out the files that it *would* have copied/deleted.

The synchronization can (and probably should) be run as a scheduled task using Windows Task Scheduler. To do this, create a .bat file, add the following text (substituting your source, share, and destinations):

cd c:\rsync
rsync -rt –progress –delete 10.10.1.162::staging.cephas.net f:/finetpub/hosts/live.cephas.net/wwwroot/images/

and then use the Windows Scheduler (Start –> Programs –> Accessories –> System Tools –> Scheduled Tasks) to create a task that fires every n (minutes? hours?) per day.

Questions or problems? Email me.