#!/bin/sh

#* -------------------------------------------------------------------------- */
#*                      CAT: AppLogic Global Catalog                          */
#*                                                                            */
#*                appliance.sh - Appliance controlling script                 */
#* -------------------------------------------------------------------------- */
#* Copyright (C) 2005 3Tera, Inc. All rights reserved.                        */
#*                                                                            */
#* Use of this notice does not imply publication or disclosure.               */
#* This software contains CONFIDENTIAL and PROPRIETARY information            */
#* constituting valuable TRADE SECRETS of 3Tera, Inc., which may be disclosed */
#* by 3Tera, Inc., only under strict limitations on its use and               */
#* confidentiality, and may not be (a) disclosed to third parties,            */
#* (b) copied in any form, or (c) used for any purpose except as specifically */
#* permitted in writing by 3Tera, Inc.                                        */
#* In addition, any hard-copy, printout or other tangible expression of this  */
#* software must include on every page thereof the copyright notice contained */
#* herein and the phrase "3TERA CONFIDENTIAL - HIGHLY PROPRIETARY".           */
#* -------------------------------------------------------------------------- */

# exit with no action, if this is not running in an AppLogic environment
# (standalone startup)
[[ -f /etc/applogic.sh ]] || exit 0

# import appliance properties
source /etc/applogic.sh

# log file
logfile=/var/log/appliance/log

# perform service control command
case "$1" in
    start)   sh /appliance/create_db.sh             >>$logfile 2>&1
             vme=/appliance/vme id=maintenance
             RET=$?
             if [ $RET != 0 ]; then
                echo "Failed to create database."   >>$logfile
                exit 1
             fi
             perl /appliance/start_mysqld.pl        >>$logfile 2>&1
             RET=$?
             if [ $RET != 0 ]; then
                echo "Failed to start mysql."       >>$logfile
                exit 1
             fi
             sh /appliance/db_permck.sh             >>$logfile 2>&1
             RET=$?
             if [ $RET != 0 ]; then
                echo "Insufficent permissions for root@% in the mysql database." >>$logfile
                exit 1
             fi
             sh feed_mysql_counters.sh &
             ;;

    stop)    mysqladmin shutdown
             ;;

    *)       echo "usage: $0 {start|stop}"
             exit 1
esac

exit 0


