ABN 25 173 915 011 markomedia - web development

markomedia - web development

  • Home
  • Contact
  • Blog

2010 May

  • markomedia
    • 2010
      • May
Share |
  • May 20, 2010

    Startup Script for Apache Tomcat on Snow Leopard HOWTO

    Author
    Marko Tomic

    I have just set up Apache Tomcat startup script on Snow Leopard and I thought I’d blog about it while it’s still fresh in my head.  Assuming you have installed Tomcat in /usr/local/tomcat directory, you can do the following to start Tomcat on system startup.

    1. Create your startup script:

    sudo nano /usr/local/tomcat/bin/tomcat
    #!/bin/sh # Tomcat Startup Script
    CATALINA_HOME=/usr/local/tomcat; export CATALINA_HOME
    JAVA_HOME=/Library/Java/Home; export JAVA_HOME
    TOMCAT_OWNER=root; export TOMCAT_OWNER
     
    start() {
    	echo -n "Starting Tomcat: "
    	su $TOMCAT_OWNER -c $CATALINA_HOME/bin/startup.sh
    	sleep 2
    }
     
    stop() {
    	echo -n "Stopping Tomcat: "
    	su $TOMCAT_OWNER -c $CATALINA_HOME/bin/shutdown.sh
    }
     
    # See how we were called.
    case "$1" in
    	start)
    	start
    ;;
    	stop)
    	stop
    ;;
    	restart)
    	stop
    	start
    ;;
    *)
     
    echo $"Usage: tomcat {start|stop|restart}"
    exit
    esac

    Set your TOMCAT_OWNER correctly.  You should run it as a valid system user.

    2. Create a symbolic link in /usr/bin for easier access

    sudo ln -s /usr/local/tomcat/bin/tomcat /usr/bin/tomcat

    3. Create the startup daemon which will start Tomcat when the system boots up

    sudo mkdir /Library/StartupItems/tomcat
    sudo nano /Library/StartupItems/tomcat/tomcat
    #!/bin/sh
    . /etc/rc.common
     
    # The start subroutine
    StartService() {
    # Insert your start command below.
    tomcat start
    }
     
    # The stop subroutine
    StopService() {
    # Insert your stop command(s) below.
    tomcat stop
    }
     
    # The restart subroutine
    RestartService() {
    # Insert your start command below.
    tomcat restart
    }
     
    RunService "$1"

    4. Create your startup parameters plist file

    sudo nano /Library/StartupItems/tomcat/StartupParameters.plist
    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
    <plist version="0.9">
    	<dict>
    		<key>Description</key>
    		<string>Tomcat web server</string>
    		<key>OrderPreference</key>
    		<string>Late</string>
    		<key>Provides</key>
    		<array>
    			<string>Local Web Services</string>
    		</array>
    		<key>Uses</key>
    		<array>
    			<string>SystemLog</string>
    		</array>
    	</dict>
    </plist>

    Restart your Mac and you should be sweet.

    For more info on how to install Tomcat, e.g. Railo on Tomcat via Apache see my blog post on Learnosity Website. Also, have a look at Mark’s version using Apache mod proxy

    Marko

    Top
  • May 19, 2010

    MySQL startup script on Mac OS X Snow Leopard

    Author
    Marko Tomic

    I’ve had problems starting up MySQL database server on startup on Snow Leopard.  MySQL preference pane seems to be flaky and it often fails to start MySQL server.

    I created this startup script myself and it seems to work nicely.
    sudo nano /System/Library/LaunchDaemons/org.mysql.mysqld.plist

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    	<dict>
    		<key>RunAtLoad</key>
    		<true/>
    		<key>Umask</key>
    		<integer>7</integer>
    		<key>UserName</key>
    		<string>_mysql</string>
    		<key>Disabled</key>
    		<false/>
    		<key>WorkingDirectory</key>
    		<string>/usr/local/mysql</string>
    		<key>GroupName</key>
    		<string>_mysql</string>
    		<key>KeepAlive</key>
    		<true/>
    		<key>Program</key>
    		<string>/usr/local/mysql/bin/mysqld</string>
    		<key>Label</key>
    		<string>org.mysql.mysqld</string>
    		<key>ProgramArguments</key>
    		<array>
    			<string>--user=_mysql</string>
    		</array>
    	</dict>
    </plist>

    Now make sure file permission is correct and load the daemon.

    sudo chown root:wheel /System/Library/LaunchDaemons/org.mysql.mysqld.plist
    sudo launchctl load /System/Library/LaunchDaemons/org.mysql.mysqld.plist
    sudo launchctl start org.mysql.mysqld

    Restart your Mac and your MySQL server should be running.

    Marko

    Top

    Navigation

    • Home
    • Contact
    • Blog

    Archives

    • February 2012
    • January 2012
    • December 2011
    • November 2011
    • October 2011
    • September 2011
    • August 2011
    • July 2011
    • May 2011
    • December 2010
    • October 2010
    • September 2010
    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009

    From the blog

    • IE6, IE7, IE8, & IE9 on OS X in Virtual Machine

    • opendiff and FileMerge on OS X

    • Bandwidth throttling on OS X

    • bash script useful tips

    • apr_sockaddr_info_get() failed for mydomain.com

    About us

    Marko Tomic - Web professional and an Adobe Certified Expert with over 10 years of commercial experience using variety of technologies.

    Connect

    Facebook icon Twitter icon Email icon RSS icon