From 69260bd2914dc873a9704f031b0ddad553650e25 Mon Sep 17 00:00:00 2001 From: Paul Barrett Date: Wed, 18 Nov 2009 11:34:11 +0200 Subject: [PATCH] Added support for starting and stopping mysql to service control batch and shell scripts --- dmsctl.bat | 30 +++++++++++++++++++++++------- dmsctl.sh | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 95 insertions(+), 9 deletions(-) diff --git a/dmsctl.bat b/dmsctl.bat index 01b49fa..2b1660e 100644 --- a/dmsctl.bat +++ b/dmsctl.bat @@ -17,29 +17,34 @@ set SOFFICE_PORT=8100 set OpenofficeServiceName=KTOpenoffice set SchedulerServiceName=KTScheduler set LuceneServiceName=KTLucene +set MySQLServiceName=MySQL_ZendServer51 rem ============= MAIN ============== -if NOT ""%1"" == ""help"" IF NOT ""%1"" == ""start"" IF NOT ""%1"" == ""path"" IF NOT ""%1"" == ""stop"" IF NOT ""%1"" == ""restart"" IF NOT ""%1"" == ""install"" IF NOT ""%1"" == ""uninstall"" goto help +IF NOT ""%1"" == ""start"" IF NOT ""%1"" == ""path"" IF NOT ""%1"" == ""stop"" IF NOT ""%1"" == ""restart"" IF NOT ""%1"" == ""install"" IF NOT ""%1"" == ""uninstall"" goto help goto %1 :help echo USAGE: echo. -echo dmsctl.bat ^ +echo dmsctl.bat ^ [servicename] echo. -echo help - this screen +echo help - this screen echo. -echo start - start the services -echo stop - stop the services -echo restart - restart the services +echo start - start the services +echo stop - stop the services +echo restart - restart the services echo. -echo install - install the services +echo install - install the services echo uninstall - uninstall the services echo. +echo servicename - optional service name to start/stop only that service. +echo only mysql is supported for individual control at this time. +echo. goto end :start +IF ""%2"" == ""mysql"" goto start_mysql echo Starting services sc start %OpenofficeServiceName% sc start %LuceneServiceName% @@ -48,6 +53,7 @@ sc start %SchedulerServiceName% goto end :stop +IF ""%2"" == ""mysql"" goto stop_mysql echo Stopping services sc stop %LuceneServiceName% sc stop %SchedulerServiceName% @@ -56,6 +62,16 @@ ping -n 7 127.0.0.1 > null IF ""%1"" == ""restart"" goto start goto end +:start_mysql +echo Starting MySQL Service +sc start %MySQLServiceName% +goto end + +:stop_mysql +echo Stopping MySQL Service +sc stop %MySQLServiceName% +goto end + :restart goto stop diff --git a/dmsctl.sh b/dmsctl.sh index b571fd9..30f402e 100755 --- a/dmsctl.sh +++ b/dmsctl.sh @@ -1,5 +1,3 @@ -#!/bin/bash - # Boot KnowledgeTree services # chkconfig: 2345 55 25 # description: KnowledgeTree Services @@ -40,6 +38,7 @@ LUCENE_PIDFILE=$INSTALL_PATH/var/log/lucene.pid LUCENE_PID="" LUCENE="$JAVABIN -Xms512M -Xmx512M -jar ktlucene.jar" LUCENE_STATUS="" +:q # Scheduler SCHEDULER_PATH="$INSTALL_PATH/bin/" @@ -49,6 +48,13 @@ SCHEDULERBIN="$INSTALL_PATH/var/bin/schedulerTask.sh" SCHEDULER="$SCHEDULERBIN" SCHEDULER_STATUS="" +# MySQL: modify if needed for your installation +MYSQL_PATH=/etc/init.d +MYSQLBIN=mysql +MYSQL_PIDFILE=/var/run/mysqld/mysqld.pid +MYSQL_PID="" +MYSQL_STATUS="" + get_pid() { PID="" PIDFILE=$1 @@ -92,6 +98,16 @@ get_scheduler_pid() { fi } +get_mysql_pid() { + get_pid $MYSQL_PIDFILE + if [ ! $PID ]; then + return + fi + if [ $PID -gt 0 ]; then + MYSQL_PID=$PID + fi +} + is_service_running() { PID=$1 if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then @@ -138,6 +154,18 @@ is_scheduler_running() { return $RUNNING } +is_mysql_running() { + get_mysql_pid + is_service_running $MYSQL_PID + RUNNING=$? + if [ $RUNNING -eq 0 ]; then + MYSQL_STATUS="mysql not running" + else + MYSQL_STATUS="mysql already running" + fi + return $RUNNING +} + start_soffice() { is_soffice_running RUNNING=$? @@ -272,12 +300,54 @@ stop_scheduler() { fi } +start_mysql() { + is_mysql_running + RUNNING=$? + + if [ $RUNNING -eq 1 ]; then + echo "$0 $ARG: mysql (pid $MYSQL_PID) already running" + else + nohup $MYSQL_PATH/$MYSQLBIN start &> $INSTALL_PATH/var/log/dmsctl.log & + if [ $? -eq 0 ]; then + echo "$0 $ARG: mysql started" + ps ax | grep $MYSQLBIN | awk {'print $1'} > $MYSQL_PIDFILE + sleep 2 + else + echo "$0 $ARG: mysql could not be started" + ERROR=3 + fi + fi +} + +stop_mysql() { + NO_EXIT_ON_ERROR=$1 + is_mysql_running + RUNNING=$? + + if [ $RUNNING -eq 0 ]; then + echo "$0 $ARG: $MYSQL_STATUS" + if [ "x$NO_EXIT_ON_ERROR" != "xno_exit" ]; then + exit + else + return + fi + fi + get_mysql_pid + if kill $MYSQL_PID ; then + echo "$0 $ARG: mysql stopped" + else + echo "$0 $ARG: mysql could not be stopped" + ERROR=4 + fi +} + help() { echo "usage: $0 help" echo " $0 (start|stop|restart)" echo " $0 (start|stop|restart) scheduler" echo " $0 (start|stop|restart) soffice" echo " $0 (start|stop|restart) lucene" + echo " $0 (start|stop|restart) mysql" cat <