Litespeed, OSX, and Disk Scratching

March 27, 2007

UPDATE: This no longer works in Snow Leopard. Even moving from ‘hdid’ to ‘hdiutil’ doesn’t help. While it technically works it results in all other mounted volumes (disks, DMGs) to appear twice on the desktop and not work or be easily ejectable. Disk Utility can eject them followed by a relaunch of the Finder to clear them off for good.

I recently setup litespeed on my OSX machine for development. Everything works great except that it writes to the hard drive every second. Turns out litespeed writes out it’s status once a second to /tmp/lshttpd/status and that for some reason OSX doesn’t cache that in memory. This can be fixed by mounting a RAM disk at /tmp/lshttpd.

To get this to work, apply the following patch to /usr/local/lsws/bin/lswsctrl

*** lswsctrl.orig       Wed Mar 21 08:34:26 2007
--- lswsctrl    Mon Mar 26 14:20:48 2007
***************
*** 40,45 ****
--- 40,53 ----
        else   
                PID=""
        fi
+ 
+     ram_disk=`/usr/bin/hdid -nomount ram://2048`
+     /sbin/newfs_hfs $ram_disk
+     /bin/rm -rf /tmp/lshttpd
+     /bin/mkdir /tmp/lshttpd
+     /sbin/mount -t hfs $ram_disk /tmp/lshttpd
+     /Developer/Tools/SetFile -a V /tmp/lshttpd
+    
      ./$EXECUTABLE
        ret=$?
        if [ $ret -eq 0 ]; then
***************
*** 51,56 ****
--- 59,66 ---- 
                echo "[OK] $DESC: pid=$NEW_PID."
        else   
                echo "[ERROR] Failed to start $DESC!"
+     /sbin/umount /tmp/lshttpd
+     /usr/bin/hdiutil detach $ram_disk
        fi
  } 

***************
*** 61,66 ****
--- 71,80 ----
        ret=$?
      if  [ $ret -eq 0 ]; then
                echo "[OK] $DESC: stopped."
+     sleep 1 
+     ram_disk=`/bin/df | /usr/bin/grep /tmp/lshttpd | /usr/bin/cut -f1 -d" "`
+     /sbin/umount /tmp/lshttpd
+     /usr/bin/hdiutil detach $ram_disk
        else   
                echo "[ERROR] can not kill $DESC"
        fi

That SetFile line above simply hides the volume from appearing on your desktop.

Now you can run litespeed all the time without having to listen to it touch the hard drive.