Here's the one I did for MySQL. You can obviously adapt it for any Unix application. This document assumes you already have your startup item configured in both /etc/hostconfig and /System/Library/StartupItems.
Read the rest of the hint for the how-to...
The first thing you need to do is open /etc/rc.common in your text editor of choice. As always, make sure you backup any files you edit. Find the RunService () routine and add the following line to the case statement, right after the restart line:
status ) StatusService ;;
Your case statement should now look like this:
RunService ()
{
case $1 in
start ) StartService ;;
stop ) StopService ;;
restart) RestartService ;;
status ) StatusService ;;
* ) echo "$0: unknown argument: $1";;
esac
}
This entry tells your startup item what to do with the "status" switch. Save /etc/rc.common. Now you need to modify the script that starts and stops your Unix application. Open the startup script and add something similar to this right before the RunService "$1" line at the very end:
StatusService ()
{
ps auxww | grep mysqld | grep -v grep > /dev/null 2>&1
if [ $? -eq 0 ]; then
ConsoleMessage "MySQL is running."
else
ConsoleMessage "MySQL is not running."
fi
}
The first line just greps for the app and pipes the output to /dev/null. The second line queries the exit status and sends the appropriate console message. After adding this bit of code you can save the script. Here it is in action:
baracus:~ root# /System/Library/StartupItems/MySQL/MySQL stop
Stopping the MySQL database server.
baracus:~ root# /System/Library/StartupItems/MySQL/MySQL status
MySQL is not running.
baracus:~ root# /System/Library/StartupItems/MySQL/MySQL start
Starting the MySQL database server.
baracus:~ root# /System/Library/StartupItems/MySQL/MySQL status
MySQL is running.

