« [Tip] A scriptable export | Main | [Commentary] Stalled: Getting Development into Gear »

November 22, 2004

[Article] How to create a startup item on OS X

by Marcel Trapman
www.it2be.com

How to create a startup item on a OS X machine... 

Sniff, this weekend I was utterly disappointed with my Mac for the very first time in something like 13 years (could it be the number 13)... Last friday I needed to install a Servoy Application Server together with Sybase ASA on a Mac. I thought this would be as simple as installing Windows Services. But it was NOT.

Unfortunately the forum was not helping all the way either although I have to thank ‘Swingman’ for the given directions. After one weekend and a despirate cry for help to Jan Aleman (at which he responded like Servoy always does, very prompt!) I finally have it working. To spare you readers all those hours, although I learned a lot (again), I wrote this little tutorial.

In order to get this done you need some patience as well as the ‘console’, ‘terminal’ and ‘Activity Monitor’ utilities in your ‘/applications/utilities’ folder. You also need a text editor that can write plain text like BBEdit or SubEthaEdit. Bare in mind that in this tutorial I assume that the Servoy folder can be found in the ‘Applications’ folder. If not, you have to change the script accordingly. The library folder is also located in the main directory and not in that of the system or any user...  

Step 1 Go into the folder ‘/Library/StartupItems’ Create a folder ‘Servoy’ Start your text editor, create a new document and copy/paste the following code:

#!/bin/sh
##
# Servoy Application Server
## 
. /etc/rc.common 
StartService () {
            ConsoleMessage "Starting Servoy Application Server..."
            . /Applications/Servoy/servoy_server.sh&

StopService()
{
            ConsoleMessage "In the future Stop Servoy Application Server here" }  
RestartService ()
{
            ConsoleMessage "Restarting Servoy Application Server..."
            StopService
            StartService
}
RunService "$1"

Write the file into the new folder ‘/Library/StartupItems/Servoy’ under exactly the same name as the name of the folder. In this case ‘Servoy’.

Step 2 Create a new text document again and copy/paste the following code:

{
            Description = "Servoy Application Server";
            Provides = ("Servoy");
            Requires = ("Resolver");
            Preference = "Late";
            Messages =
           {
                        start = "Starting Servoy Application Server";
                        stop = "Stopping Servoy Application Server";
            };
}  

The file has to be saved in the new folder ‘/Library/StartupItems/Servoy’ named ‘StartupParameters.plist’.  

Step 3 After the creation of these two files go into the Terminal application and change the rights of the new StartupItem:

chmod +x /Library/StartupItems/Servoy

Step 4 Navigate to the root of the Servoy installation and open the file servoy_server.sh in the texteditor and copy the below code into the file. Make sure that the codeline starting with java -Djava ends with $@”. It is ONE line... It is even better to copy/paste only the new lines before the ‘while’ loop... 

#!/bin/sh  
##
# Start IT2Print with Sybase ASA and Servoy Application Server
## 
cd /Applications/Servoy export DYLD_LIBRARY_PATH=/Applications/Servoy/sybase_db /Applications/ Servoy /sybase_db/dbsrv9 @/Applications/ Servoy /sybase_db/sybase.config& 
while true
do            java -Djava.awt.headless=true -classpath .:lib/commons-collections.jar:lib/commons-dbcp.jar:lib/commons-pool.jar:lib/activation.jar:lib/antlr.jar:lib/j2db.jar:lib/j2dbdev.jar:lib/compat141.jar:lib/jh.jar:lib/jndi.jar:lib/js.jar:lib/jta.jar:lib/mail.jar:lib/jug.jar:lib/jdbc2_0-stdext.jar:lib/naming-common.jar:lib/naming-resources.jar:lib/servlet.jar:lib/xerces.jar:lib/server-bootstrap.jar:lib/commons-fileupload-1.0.jar:lib/commons-logging.jar:lib/hibernate2.jar com.servoy.j2db.server.ApplicationServer "$@"
            EXITCODE=$?
            if [ "$EXITCODE" != 99 ]; then exit $EXITCODE; fi
done

Now save the file again.    

Step 5 The last file to edit in your text editor is sybase.config in the folder sybase_db in the Servoy root. Before saving the file the first line should look like:

-ti 0 -x tcpip{dobroadcast=no} -ud -qs -qw –o /Applications/Servoy/sybase_db/sybase_log.txt

For those of you that pay attention the command –ud is added to make Sybase ASA run as a deamon. The rest of the script remains untouched...   After you did all this you should be set to go...  

One last thing, when you copy the above pieces of code you'd better to take out all formatting stuff like extra spaces and linefeeds. Sorry for that...

Have fun,  

Marcel

| Posted by IT2Be on November 22, 2004 at 02:37 PM in Articles | Permalink

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341c8d8153ef00d834726ed469e2

Listed below are links to weblogs that reference [Article] How to create a startup item on OS X:

Comments

If you are a pre-OS X mac user like me, pick yourself up a copy of QuicKeys for $100 and add Servoy server to the start up queue (all of one line that you don't even have to type). I have NO CLUE what Marcel is talking about here! So of course I now have to go and try it out....

Posted by: David Workman | Nov 23, 2004 1:01:39 AM

David,

I am talking about creating a complete server setup on OS X at a client site :-)

Following your suggestion would mean investing $100 for something like 15 minutes of extra work. You still have to change the servoy_server.sh and the sybase.properties files.

The 'only' difference are the startup files and a learning curve on Unix.

Posted by: Marcel Trapman | Nov 23, 2004 5:47:20 AM

15 minutes of work now that you have figured it out :) Good stuff and I'll be using from now on.

Currently, my QuicKeys routine is this:
- start up Servoy Developer
- shut down Servoy Developer (this starts up Sybase)
- run a shell script to start up Servoy Server as a service.
- set it to run on startup

A hack I know but it works and it only took me 15 minutes to figure out originally.... I'm a big fan of letting others do the heavy lifting :)

Posted by: David Workman | Nov 23, 2004 1:28:34 PM

But I am smarter now :-)

Posted by: Marcel Trapman | Nov 23, 2004 1:54:17 PM

Good stuff Marcel! One quick question. I think I know what to eliminate if I am not using Sybase ASA as either the main database nor as the servoy_repository for one solution but would you mind spelling that out? I think there are still advantages to setting it up this way even without having the 'auto' start for Sybase, aren't there?

Posted by: John Allen | Nov 23, 2004 2:21:02 PM

Thanks for the compliment...

The only thing you need to take out is the line that starts up sybase in the servoy_server.sh script. Ofcourse you don't have to touch the sybase.properties file either in that case.

What and how to start up only part of the db's using ASA is described in the docs...

Sure there are advantages to start up this way. But only in the case you need to run the application server at the clients (or your own) site. Make sure your database is started up first in any case!

Posted by: Marcel Trapman | Nov 23, 2004 2:31:51 PM

Hi Marcel,

I still can't get this to work properly. Any chance of posting your files as a zip archive? -- copying and pasting from the webpage introduces too many problems!

Posted by: Swingman | Nov 29, 2004 2:19:18 PM

I have it finally working.
What is confusing about the article is the part for servoy_server.sh.
It doesn't contain linebreaks where it should have them.

The part BEFORE the while true etc. should be the following.

cd /Applications/Servoy
export DYLD_LIBRARY_PATH=/Applications/Servoy/sybase_db
/Applications/Servoy/sybase_db/dbsrv9 @/Applications/Servoy/sybase_db/sybase.config &

So 3 lines...not 1 as the article formating made us believe.
Ofcourse when you have servoy installed in a different location you have to change the paths accordingly.
I hope this helps

Posted by: Robert J.C. Ivens (ROCLASI) | Dec 10, 2004 4:16:19 PM

Figured out how you can startup the Application Server in OS X without any extra tools:

- Put extra info in servoy_server.sh and sybase.config as mentioned in former posts
- Select servoy_server.sh
- get info (CMD i)
- set Open With at 'Terminal', save and close
- Open System Preferences
- Go to Accounts > Serveraccount
- Drag servoy_server.sh to Startup Items
- Restart OS X Server (in case you like to test it)

Works fine by me!

Posted by: Karel Broer | May 11, 2005 9:11:02 AM

It's very important to give the server time to get started. On my Xserve (new in Feb 05) it takes three or four minutes to get fully up to speed.

Unaware of this requirement I used the browser to launch the server's admin pages almost immediately. The browser couldn't find that location so I incorrectly assumed the fault was in the setup.

Posted by: Morley Chalmers | Jul 7, 2005 11:59:43 AM

Post a comment