FrontierMonitor for OS X

FrontierMonitor is so cool. I have it keeping my www.ideaforest.net alive. Thanks so much for the goods. - Scott Greiff

FrontierMonitor is a Perl daemon installed on a OS X machine hosting a Frontier or/and Radio servers. FrontierMonitor will try to launch the Frontier/Radio servers if they are down and will send you a warning by email while loging the event in a log file.

FrontierMonitor is based on approximatively 200 lines of Perl code (including the comments). But the documentation is approximatively six pages long. Go figure. FrontierMonitor is beta software and hasn't been tested a lot. This is the first public release. Use it at your own risk!

FrontierMonitor need the Perl LWP library to run. The LWP library or libwww-perl is for writing www clients in Perl. Instructions to do an easy install of LWP are provided with the FrontierMonitor documentation.

Features

Download FrontierMonitor

http://scriptdigital.com/divers/gems/FrontierMonitor.sit

Documentation

http://scriptdigital.com/divers/frontiermonitor.html

TOC

Installing the Perl LWP library
Configuring FrontierMonitor
Testing FrontierMonitor
Installing FrontierMonitor

Installation

Installing the Perl LWP library (TOP)

The easiest way to install the LWP library is to use the CPAN.pm module (which is the Perl module that handle for you the installation of Perl modules).

If you never used CPAN.pm before, you will need to configure CPAN.pm.

As root or admin, type in the terminal:

perl -MCPAN -eshell

This will start a CPAN session. The first time that CPAN.pm is run, it will ask straithforward questions. I recommend that you install your .cpan directory in you home directory and not in the root/admin directory.

For example, at this question:


First of all, I'd like to create this directory. Where?

CPAN build and cache directory? [/private/var/root/.cpan]

answer:

/Users/myHome/.cpan.

From there, you can use the default answers offered by CPAN.pm.

If everything goes well, you will get this prompt at the end of the configuration process of CPAN.pm

cpan>

Type h if you want to see a list of options of that you can use on the command line while in a CPAN.pm session.

Now quit the CPAN.pm session by simply typing:

cpan>q

WARNING

LWP is installing at
/usr/bin/HEAD
a utility that let you get only the headers of a HTTP transaction it will overwrite the OS X installed UNIX utility at
/usr/bin/head
which is an utility that let you look at the first lines of a file.
Before you install the LWP library, you need to make a backup of
/usr/bin/head.

As root/admin type:

cp /usr/bin/head /usr/bin/head.bk

This will make a backup of the original UNIX utility head.

After your installation of LWP is completed, you will need to do these commands if you followed the above:

cp /usr/bin/head /usr/bin/headlwp
cp /usr/bin/head.bk /usr/bin/head

These commands will produce 3 files, the original head installed by OS X, a backup of it at head.bk and the LWP utility headlwp.

Now start again a CPAN.pm session by typing:

perl -MCPAN -eshell

At the CPAN.pm prompt, type the following (the installation will take a couple of minutes and you will need to answers some questions, use the default answers).

cpan> install Bundle::LWP

You will see a ton of text scrolling, don't worry, that standard behavior. The LWP library is a big library.

If you get an error message at the end of the installation saying that the installation failed, you can still use:

cpan>force install Bundle::LWP

to "force" the installation.

Quit the CPAN.pm session and don't forget to type:

cp /usr/bin/head /usr/bin/headlwp
cp /usr/bin/head.bk /usr/bin/head

Configuring FrontierMonitor(TOP)

To configure FrontierMonitor, open the FrontierMonitor file in the FrontierMonitor folder. Scroll to the end of the file, and you will see the options to configure FrontierMonitor. The configuration options are straightforward.

There is catch with FRONTIER_PATH and RADIO_PATH because of the ™ symbol in each application name (IMO UserLand should consider dropping the ™ symbol for cross-platform compatibility). If you can't find the right keys for this symbol in your text editor, just use '*' without the quotes instead.

FRONTIER_PATH=/Users/myHome/Applications/Frontier/UserLand\ Frontier*;

Also, depending on what you are running in Aqua, its possible that if you try to reboot/logout the machine from Aqua (for example, you have direct physical access to the machine, or you are using Timbuktu), the relaunching of Frontier will stop the reboot. In this case, you can do 3 things: [1] kill the FrontierMonitor daemon, [2] set NUMBER_MINUTES_BETWEEN_SCAN to a higher value than 1 (you have to kill the FrontierMonitor daemon for this to take effect), [3] this problem doesn't appears if you reboot from the command line with a command like 'reboot now'.

Here's an example of a configuration of a copy of FrontierMonitor checking a Frontier server installation.


#----------------------------------------------------------------#

# Configurations for FrontierMonitor

#----------------------------------------------------------------#

# comment the options that you don't want to use and that are not required

# set to 1 if you want to monitor Frontier MONITOR_FRONTIER=1

# path the Frontier app, don't put quotes here FRONTIER_PATH=/Users/myHome/Applications/Frontier/UserLand\ Frontier*

# the url that FrontierMonitor will check to see if Frontier is running FRONTIER_URL=http://127.0.0.1:8080/

# set to 1 if you want to monitor Radio #MONITOR_RADIO=1

# path to the Radio app, don't put quotes here #RADIO_PATH=/Users/myHome/Radio\ UserLand/Radio\ UserLand*

# the url that FrontierMonitor will check to if Radio is running #RADIO_URL=http://127.0.0.1:5335/

# *REQUIRED* -> the address of the recipient of the warning messages EMAIL_RECIPIENT=me@phonyemail.com

# the address of the CC recipient of the warning messages EMAIL_RECIPIENT_CC=me@anotherphonyemail.com

# *REQUIRED* -> path to the log file FRONTIERMONITOR_LOG_PATH=/var/log/frontiermonitor.log

# *REQUIRED* -> the interval of the scan in minutes NUMBER_MINUTES_BETWEEN_SCAN=1

# *REQUIRED* -> the maximum attempted launchs MAX_LAUNCHS_ATTEMPS=5

# set to 1 if you want to test FrontierMonitor #DEBUG_LOG_YES=1

# the path to the debug log #DEBUG_LOG_PATH=/Users/myHome/Desktop/frontiermonitordebug.log

Testing Frontier Monitor(TOP)

To test FrontierMonitor, open the FrontierMonitor Perl script in the FrontierMonitor folder in your favorite text editor and set the option DEBUG_LOG_YES to 1 and the DEBUG_LOG_PATH to the path of a debug file.

In the terminal, cd to the FrontierMonitor repertory. Then start FrontierMonitor as root/admin from the command line.

perl FrontierMonitor

You will greeted by something like this:


2002/07/06 22:33:59 Starting FrontierMonitor daemon...

FrontierMonitor daemon running...

The pid is: 18049

Use 'kill 18049' without the quotes to kill the daemon

Or check the pid at /var/run/frontiermonitor.pid

Or use 'ps -aux|grep -i frontiermonitor' without the quotes to find the pid

The information about the pid is important because the command kill pidnumber will let you stop ("kill") the process. In my example, if I need to kill the Perl daemon, I will do:

kill 18049

Now open a new terminal window to follow the log file that you specified at the option DEBUG_LOG_PATH. In the example, I will type:

tail -f /Users/myHome/Desktop/frontiermonitordebug.log

With this command, you will be able to follow in real time what FrontierMonitor is doing. If FrontierMonitor is running, your suppose to get in the debug file something like this:


2002/07/06 22:40:07 scan pos 3: startApp: called with condition 0

2002/07/06 22:40:07 scan pos 3: startApp: called with condition 

2002/07/06 22:41:07 scan pos 3: startApp: called with condition 0

2002/07/06 22:41:07 scan pos 3: startApp: called with condition 

condition 0 mean in my example that Frontier is up and condition without any following number mean that I'm not monitoring Radio.

Now, to follow the example, if I quit Frontier, it will relaunched at the next FrontierMonitor scan (if everything goes well) and the debug log file will contains something like this:


2002/07/06 22:49:11 scan pos 3: startApp: called with condition 1

2002/07/06 22:49:11 scan pos 4: startApp: condition

2002/07/06 22:49:11 scan pos 5: startApp: launch

Now take your email from the accounts you specified at EMAIL_RECIPIENT and EMAIL_RECIPIENT_CC

You are suppose to get an email titled, Frontier_Launch or Radio_Lauch. The body of the message is in my example (I broke the line for legibility):


2002/07/06 22:49:11
Starting /Users/myHome/Applications/Frontier/UserLand*Frontier* frontierlaunchs = 1

Now type the following command to see if the event was registered.

cat /var/log/frontiermonitor.log

You should see the same message as the one in the email.

If everything is fine, stop the Perl daemon with the kill command described above.

Comment DEBUG_LOG_YES and DEBUG_LOG_PATH.

Installing FrontierMonitor(TOP)

The easy part now.

Just copy the FrontierMonitor folder to
/Library/StartupItems

Set the execution bit of the FrontierMonitor script.

chmod 700 /Library/StartupItems/FrontierMonitor/FrontierMonitor

Either reboot or start manually FrontierMonitor from the command line.

That's all!


Version History

Version 1.0b July 7 2002

First release.