Something I Know

Pier headless on Mac OS X

Overview

In thirty minutes you can go from zero to a full fledged installation of Smalltalk with Pier to create a blog. One that you have full source code to that is easily customizable.

Prerequisites

You’ll need a registered domain name and webserver already set up. If you’d like to learn how to make this happen, please see homemade dot mac

A good tool for managing virtual servers in apache is webmin. This is discussed in more detail in another excellent article ISP-in-a-box

The intended audience is Mac OS X but many of the techniques will work on other unix-like operating systems. It has been specifically tested on Tiger (Mac OS 10.4) but should work on Leopard and newer too.

Purpose

To date, I have not seen a concise easily understood way of running Seaside as a server process on the Mac. It needs to be truly headless. It needs to start up at boot time and fall down elegantly at shutdown. Out of sight and out of mind but always running, just like your webserver.

There are several nice one-click Seaside downloads out there. But nobody has explained how to get them to invoke headless until now.

For a long time I have considered Apple’s WebObjects to be the best solution to developing interesting and highly dynamic web sites. But now, perhaps a better solution has materialized in the form of Seaside. I’ve been lurking into the realm of Seaside for approximately two years. It certainly has a great deal of promise.

Now is the time to get my hands dirty and bring you along with me. What better way to get into this bold new world than to make a blog with it? I encourage you to do the same.

Download Smalltalk, Seaside, Pier

There is ridiculously little you have to do. A one-click installer is made that has Smalltalk, Seaside, and Pier all combined. There are a few variants of this but the one that is sure to have the latest version of Pier comes directly from the piercms web site. Go ahead and download it now.

Smalltalk - some background

True Smalltalk could be concisely described as "An operating system with unlimited customizability."

To call it a "programming language" is misleading. Sure enough it is one and has a special syntax with just a "small" set of keywords (hence the cheeky name small talk). This "language" runs in its own Virtual Machine. It introduced the "mouse" to the world before the Macintosh even existed. Running smalltalk feels very much like opening a mini operating system into a new window. It’s just like "Virtual PC" except instead of running WinXP you are in Smalltalk with this alien OS you never knew existed.

There is no plethora of files to compile into a program with Smalltalk, just the "image" that you run. It is one of only a handful of truly living languages. The fact that Smalltalk predates even the Macintosh make some want to call it a "dead language". Very ironic. Any language that has static source files are the truly dead languages since you must first compile and then run them in order to breathe life into them. The "Cult of the dead" is a story for another time.

For now the point I’m trying to make is that no matter how talented you are, be prepared to be lost and enjoy the change of pace. This is culture shock at its finest. Keep your mind open so you may learn a new bag of tricks.

Run Pier

Create a new folder at "/Applications/Smalltalk" to be used to collect all your Smalltalk related toys. For right now, drag the decompressed "Pier" application bundle into this folder. Later you will probably want to bring other "images" into this folder as you dabble further with Smalltalk so it doesn’t hurt making this "Smalltalk" folder beforehand.

Double click the Pier.app bundle. In a fraction of a second, even on older computers, the Smalltalk environment is up and ready to go. There will be some text in a form of text editor displayed in the Virtual Machine window. Towards the top it will tell you how to access Pier but it will mostly likely be this URL: http://localhost:8080/seaside/pier Go ahead and view that URL. Amazing huh? In the blink of an eye everything is loaded and working.

To close the Smalltalk environment single-click anywhere in the background of the virtual machine. A menu will appear. Choose "Quit". When it asks if you want to save changes say "No."

Make Pier run headless

Update the app bundle startup sequence

Tweak the startup parameters by:

  1. right-clicking (or control-clicking) the Pier.app bundle
  2. choose "Show Package Contents"
  3. double click on the "Contents" folder
  4. double click on the info.plist file
  5. the Property List Editor launches to let you modify info.plist
  6. open the "Root" triangle
  7. look for "LSBackgroundOnly" and set it to "Yes" if it is not already.

Hopefully in newer releases of these one-click installers this LSBackgroundOnly flag will already be set. Contrary to what its name suggests it has very little to do with running headless. The only purpose it serves is to not display anything in the Dock when running headless so it really should be enabled all the time, even when you want to run "with a head".

Create a launchd script

Fire up Terminal.app and cd to "/Library/LaunchDaemons/". Now give the command:

sudo vi com.squeak.seaside.plist

After you authenticate as an admin user this opens up the classic unix text editor. Now type a lowercase "i" to enter input mode then cut and paste the following:

<?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>Disabled</key>
	<false/>
	<key>Label</key>
	<string>com.squeak.seaside</string>
	<key>OnDemand</key>
	<false/>
	<key>ProgramArguments</key>
	<array>
		<string>/Applications/Smalltalk/Pier-1.2.app/Contents/MacOS/Squeak VM Opt</string>
		<string>-memory</string>
		<string>200m</string>
		<string>-headless</string>
		<string>/Applications/Smalltalk/Pier-1.2.app/Contents/Resources/pier.image</string>
	</array>
        <key>ServiceIPC</key>
        <false/>
        <key>StandardErrorPath</key>
        <string>/Library/Logs/com.squeak.seaside.log</string>
        <key>StandardOutPath</key>
        <string>/Library/Logs/com.squeak.seaside.log</string>
	<key>UserName</key>
	<string>root</string>
</dict>
</plist>

Finally, to save and close the file first hit the "escape" or "esc" key then type "wq" (meaning: write and quit) and use the "return" key at the end.

The file should be fairly self explanatory. In the "ProgrammingArguments" section we have:

  1. path to the Smalltalk virtual machine
  2. memory (RAM) flag
  3. limit to 200 megs of Ram
  4. open headless as a server process
  5. path to the Smalltalk image

This script is for "launchd". This is an open source background server process manager. It is like "cron", "inetd", and many other oldies but goodies. "launchd" is an attempt to combine the best features of all these programs into one and is the preferred way to run server processes on the Mac. It handles all the tedious tasks of remembering the process id of the server application and terminating it at the appropriate time.

To launch your Pier application you’ll need to run the following command once. Henceforth, the app will always be running even after rebooting your computer:

sudo launchctl load /Library/LaunchDaemons/com.squeak.seaside.plist

If you ever need to turn off the Pier application for any reason, perhaps to run it "with a head" for a little while, use this similar command:

sudo launchctl unload /Library/LaunchDaemons/com.squeak.seaside.plist

Note: do not try to run two Virtual Machines against the same image file at the same time.

Secure your Pier installation from the world

Your blog is not yet available to the world. Before we make it public, lets tighten the security.

  1. Set a Seaside password
    • Open http://localhost:8080/seaside/
    • Click "config"
    • Type "admin / seaside" for the username / password combination
    • Click "configure" next to the "config" listing
    • Pick a new password then scroll down to the bottom to click the "save" button
    • Click the "close" button (don’t forget to save in the prior step)
  2. Remove unwanted packages
    • Remove everything but: browse, config, files, magritte, pier
  3. Set Pier server parameters
    • Click "configure" next to the "pier listing
    • Set resource base URL -> /
    • Set server host name -> www.yourdomain.com (ex: www.somethingiknow.com)
    • Set server path -> /
    • Click "save" button
    • Click "close" button
  4. Set Pier password
    • Click "pier" from the listings
    • Click the "login" link
    • Use "admin / pier" for the username / password combination
    • Click "change password?"
    • Type a new password then click the "save" button
  5. Set Pier Persistence (so your blog will write to disk)
    • Click "System Environment"
    • From the "Persistency" toggle choose "Image Persistency"
    • Click the "select" button
    • Accept the default options but go ahead and click the "snapshot" button to save state to disk immediately
    • You may now close your web browser

Configure Apache webserver

There are two optional server modules that need to be installed so your web server can forward traffic to your Pier application. Find the following lines scattered amongst the Apache httpd.conf file and un-comment them:

AddModule mod_rewrite.c
AddModule mod_proxy.c
LoadModule rewrite_module /usr/lib/apache/1.3/mod_rewrite.so
LoadModule proxy_module /usr/lib/apache/1.3/libproxy.so

Note: for me on Mac OS X Tiger this file is located in "/etc/httpd/httpd.conf" but it could be elsewhere depending on if you compiled a custom Apache or run a more modern Mac OS X.

Use "webmin" to create a virtual server for your website or edit httpd.conf by hand. Add the following directives in the appropriate location (modifying server names to your situation of course):

ServerName www.somethingiknow.com
DirectoryIndex somethingiknow_coming.html
DocumentRoot /Library/WebServer/Documents/pier
RewriteEngine ON
RewriteRule ^/seaside/files/(.*)$ http://localhost:8080/seaside/files/$1 [proxy,last]
RewriteCond /Library/WebServer/Documents/pier/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ http://localhost:8080/seaside/pier/$1 [proxy,last]
LogLevel error

Apply changes then restart Apache.

Summary

Your blog should now be up and running on a single application instance. It’s a server process and will take care of itself at system startup and shutdown. It saves its state directly in the Smalltalk image.

There are surely more robust ways to host your app but this is a good clean way to start. I’ve heard about "Swazoo", "Cherokee", "Blackfoot", "Magma" but they are all buzzwords to me at the moment. Though I’m sure some combination of them will provide object-database persistence across multiple application instances.

Posted by admin at 5 August 2009, 11:59 pm with tags Seaside link

Comments

On my Mac OS X - Version 10.5.8, this file is located in "/etc/apache2/httpd.conf".

Posted by Goya at 10 August 2009, 4:07 pm link

An alternative solution to access hidden files on Mac OS X is to execute the following in a Terminal:

defaults write com.apple.finder AppleShowAllFiles 1

then, restart your Mac.

To deactivate:

defaults write com.apple.finder AppleShowAllFiles 0

Posted by Goya at 10 August 2009, 4:40 pm link