Commit 69260bd2914dc873a9704f031b0ddad553650e25

Authored by Paul Barrett
1 parent d76d048f

Added support for starting and stopping mysql to service control batch and shell scripts

Committed by: Paul Barrett
Showing 2 changed files with 95 additions and 9 deletions
dmsctl.bat
... ... @@ -17,29 +17,34 @@ set SOFFICE_PORT=8100
17 17 set OpenofficeServiceName=KTOpenoffice
18 18 set SchedulerServiceName=KTScheduler
19 19 set LuceneServiceName=KTLucene
  20 +set MySQLServiceName=MySQL_ZendServer51
20 21  
21 22 rem ============= MAIN ==============
22   -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
  23 +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
23 24 goto %1
24 25  
25 26 :help
26 27 echo USAGE:
27 28 echo.
28   -echo dmsctl.bat ^<start^|stop^|restart^|install^|uninstall^>
  29 +echo dmsctl.bat ^<start^|stop^|restart^|install^|uninstall^> [servicename]
29 30 echo.
30   -echo help - this screen
  31 +echo help - this screen
31 32 echo.
32   -echo start - start the services
33   -echo stop - stop the services
34   -echo restart - restart the services
  33 +echo start - start the services
  34 +echo stop - stop the services
  35 +echo restart - restart the services
35 36 echo.
36   -echo install - install the services
  37 +echo install - install the services
37 38 echo uninstall - uninstall the services
38 39 echo.
  40 +echo servicename - optional service name to start/stop only that service.
  41 +echo only mysql is supported for individual control at this time.
  42 +echo.
39 43  
40 44 goto end
41 45  
42 46 :start
  47 +IF ""%2"" == ""mysql"" goto start_mysql
43 48 echo Starting services
44 49 sc start %OpenofficeServiceName%
45 50 sc start %LuceneServiceName%
... ... @@ -48,6 +53,7 @@ sc start %SchedulerServiceName%
48 53 goto end
49 54  
50 55 :stop
  56 +IF ""%2"" == ""mysql"" goto stop_mysql
51 57 echo Stopping services
52 58 sc stop %LuceneServiceName%
53 59 sc stop %SchedulerServiceName%
... ... @@ -56,6 +62,16 @@ ping -n 7 127.0.0.1 &gt; null
56 62 IF ""%1"" == ""restart"" goto start
57 63 goto end
58 64  
  65 +:start_mysql
  66 +echo Starting MySQL Service
  67 +sc start %MySQLServiceName%
  68 +goto end
  69 +
  70 +:stop_mysql
  71 +echo Stopping MySQL Service
  72 +sc stop %MySQLServiceName%
  73 +goto end
  74 +
59 75 :restart
60 76 goto stop
61 77  
... ...
dmsctl.sh
1   -#!/bin/bash
2   -
3 1 # Boot KnowledgeTree services
4 2 # chkconfig: 2345 55 25
5 3 # description: KnowledgeTree Services
... ... @@ -40,6 +38,7 @@ LUCENE_PIDFILE=$INSTALL_PATH/var/log/lucene.pid
40 38 LUCENE_PID=""
41 39 LUCENE="$JAVABIN -Xms512M -Xmx512M -jar ktlucene.jar"
42 40 LUCENE_STATUS=""
  41 +:q
43 42  
44 43 # Scheduler
45 44 SCHEDULER_PATH="$INSTALL_PATH/bin/"
... ... @@ -49,6 +48,13 @@ SCHEDULERBIN=&quot;$INSTALL_PATH/var/bin/schedulerTask.sh&quot;
49 48 SCHEDULER="$SCHEDULERBIN"
50 49 SCHEDULER_STATUS=""
51 50  
  51 +# MySQL: modify if needed for your installation
  52 +MYSQL_PATH=/etc/init.d
  53 +MYSQLBIN=mysql
  54 +MYSQL_PIDFILE=/var/run/mysqld/mysqld.pid
  55 +MYSQL_PID=""
  56 +MYSQL_STATUS=""
  57 +
52 58 get_pid() {
53 59 PID=""
54 60 PIDFILE=$1
... ... @@ -92,6 +98,16 @@ get_scheduler_pid() {
92 98 fi
93 99 }
94 100  
  101 +get_mysql_pid() {
  102 + get_pid $MYSQL_PIDFILE
  103 + if [ ! $PID ]; then
  104 + return
  105 + fi
  106 + if [ $PID -gt 0 ]; then
  107 + MYSQL_PID=$PID
  108 + fi
  109 +}
  110 +
95 111 is_service_running() {
96 112 PID=$1
97 113 if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
... ... @@ -138,6 +154,18 @@ is_scheduler_running() {
138 154 return $RUNNING
139 155 }
140 156  
  157 +is_mysql_running() {
  158 + get_mysql_pid
  159 + is_service_running $MYSQL_PID
  160 + RUNNING=$?
  161 + if [ $RUNNING -eq 0 ]; then
  162 + MYSQL_STATUS="mysql not running"
  163 + else
  164 + MYSQL_STATUS="mysql already running"
  165 + fi
  166 + return $RUNNING
  167 +}
  168 +
141 169 start_soffice() {
142 170 is_soffice_running
143 171 RUNNING=$?
... ... @@ -272,12 +300,54 @@ stop_scheduler() {
272 300 fi
273 301 }
274 302  
  303 +start_mysql() {
  304 + is_mysql_running
  305 + RUNNING=$?
  306 +
  307 + if [ $RUNNING -eq 1 ]; then
  308 + echo "$0 $ARG: mysql (pid $MYSQL_PID) already running"
  309 + else
  310 + nohup $MYSQL_PATH/$MYSQLBIN start &> $INSTALL_PATH/var/log/dmsctl.log &
  311 + if [ $? -eq 0 ]; then
  312 + echo "$0 $ARG: mysql started"
  313 + ps ax | grep $MYSQLBIN | awk {'print $1'} > $MYSQL_PIDFILE
  314 + sleep 2
  315 + else
  316 + echo "$0 $ARG: mysql could not be started"
  317 + ERROR=3
  318 + fi
  319 + fi
  320 +}
  321 +
  322 +stop_mysql() {
  323 + NO_EXIT_ON_ERROR=$1
  324 + is_mysql_running
  325 + RUNNING=$?
  326 +
  327 + if [ $RUNNING -eq 0 ]; then
  328 + echo "$0 $ARG: $MYSQL_STATUS"
  329 + if [ "x$NO_EXIT_ON_ERROR" != "xno_exit" ]; then
  330 + exit
  331 + else
  332 + return
  333 + fi
  334 + fi
  335 + get_mysql_pid
  336 + if kill $MYSQL_PID ; then
  337 + echo "$0 $ARG: mysql stopped"
  338 + else
  339 + echo "$0 $ARG: mysql could not be stopped"
  340 + ERROR=4
  341 + fi
  342 +}
  343 +
275 344 help() {
276 345 echo "usage: $0 help"
277 346 echo " $0 (start|stop|restart)"
278 347 echo " $0 (start|stop|restart) scheduler"
279 348 echo " $0 (start|stop|restart) soffice"
280 349 echo " $0 (start|stop|restart) lucene"
  350 + echo " $0 (start|stop|restart) mysql"
281 351 cat <<EOF
282 352  
283 353 help - this screen
... ...