[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
Comments (10)