Saturday Feb 09, 2008

I have been working on the home network in an effort to attain seamless integration with the Macs. I use a ReadyNAS NV+ with 4x 500GB drives as the network backup/media/storage device. Media sharing is done via a Mac mini to the Xbox 360, Squeezebox and the Mac laptops. When I was running on Tiger I configured automount AFP shares using the NetInfo Manager application. Well, as of the upgrade to Leopard, this application is gone.

I was digging around a bit this morning on how to go about a proper automount under Leopard. I wasn't interested in any sort of kludgey AppleScript that would be setup as some sort of login or startup item. AppleScript will work of course but it wasn't good enough, this *is* UNIX right? A couple of queries into Google and I found a great blog article detailing autofs in Leopard. There are lots of different options, but I was primarily concerned with AFP automounts. This is detailed in part two of the referenced article.

Here is what I ended up with and it works great, as of 10.5.1 that is. I dropped the net option as I wanted a more direct way to access the mounts from the Finder. I created /etc/fstab and added the following.

# -------------------------------------------------------------------------------------
# Mount AFP shares from the ReadyNAS
# servername:/path mount_point url auto,url==afp://username:password@server/path 0 0
# -------------------------------------------------------------------------------------
mynas:/Backup /Network/Backup url auto,url==afp://username:password@mynas/Backup 0 0
mynas:/Media /Network/Media url auto,url==afp://username:password@mynas/Media 0 0
mynas:/Storage /Network/Storage url auto,url==afp://username:password@mynas/Storage 0 0
# -------------------------------------------------------------------------------------


These will be auto-mounted on boot but you can easily refresh the automount config after making changes using sudo automount -cv. You can guess that, via a terminal, you can find the configured mounts under /Network. From the Finder, this is accessible in the Sidebar from either Devices -> Computer -> Network or Shared -> All... Depending on your Finder preferences, you my need enable visibility in the Sidebar.

So really that is it. Easy right?

Tuesday Nov 06, 2007

I run a Mac Mini as my home server, currently with OS X 10.4. Tonight I dug around and got GlassFish up and running using OS X's answer to SMF on Solaris, launchd. I am by no means an expert on launchd but I will happily document what worked for me. First off I installed GlassFish v2 to "/usr/local/glassfish" as per the documented instructions.

Once I verified that it all worked, I sought out how to integrate it into launchd. I certainly don't want it running as root, so I took a look at the available users and groups using the NetInfo Manager application. I found an "appserver" user and associated "appserverusr" group. Seemed a good place to start. I changed the ownership recursively for my install directory to this user and group combination. Once done, I created my launchd plist file and saved it to "/Library/LaunchDaemons/glassfish.plist".

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
	
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.sun.glassfish</string>

        <key>Disabled</key>
        <false/>

        <key>UserName</key>
        <string>appserver</string>
	
        <key>GroupName</key>
        <string>appserverusr</string>

        <key>ProgramArguments</key>
            <array>
                <string>/usr/local/glassfish/bin/asadmin</string>
                <string>start-domain</string>
                <string>domain1</string>
            </array>
		
        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>

Similar to SMF you have to load/import the service description. On OS X you use "launchctl load ./glassfish.plist" for this purpose. If all goes well you will have a running instance of GlassFish. If not, you will see rather vague error messaging in the system.log file.

Some drawbacks. It seems that launchd relies on sending a SIGTERM to the process when you attempt to stop it using "launchctl stop com.sun.glassfish". This doesn't work for GlassFish. I prefer the ability of SMF to define a appropriate shutdown command. Not a huge deal as I can easily stop GlassFish using asadmin or the admin console when needed. Once the process is stopped you can use "launchctl start com.sun.glassfish" to bring it back up. There is no notion of a restarter if the process dies. I think there is a new KeepAlive element in OS X 10.5 but I haven't be able to experiment with that version yet. Sounds promising though.

All in all this works pretty well. GlassFish will launch on boot using the recommended subsystem. If anyone has any tips on achieving a tighter integration with launchd let me know.

This blog copyright 2009 by Matthew Montgomery