Commit 69260bd2914dc873a9704f031b0ddad553650e25
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,29 +17,34 @@ set SOFFICE_PORT=8100 | ||
| 17 | set OpenofficeServiceName=KTOpenoffice | 17 | set OpenofficeServiceName=KTOpenoffice |
| 18 | set SchedulerServiceName=KTScheduler | 18 | set SchedulerServiceName=KTScheduler |
| 19 | set LuceneServiceName=KTLucene | 19 | set LuceneServiceName=KTLucene |
| 20 | +set MySQLServiceName=MySQL_ZendServer51 | ||
| 20 | 21 | ||
| 21 | rem ============= MAIN ============== | 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 | goto %1 | 24 | goto %1 |
| 24 | 25 | ||
| 25 | :help | 26 | :help |
| 26 | echo USAGE: | 27 | echo USAGE: |
| 27 | echo. | 28 | echo. |
| 28 | -echo dmsctl.bat ^<start^|stop^|restart^|install^|uninstall^> | 29 | +echo dmsctl.bat ^<start^|stop^|restart^|install^|uninstall^> [servicename] |
| 29 | echo. | 30 | echo. |
| 30 | -echo help - this screen | 31 | +echo help - this screen |
| 31 | echo. | 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 | echo. | 36 | echo. |
| 36 | -echo install - install the services | 37 | +echo install - install the services |
| 37 | echo uninstall - uninstall the services | 38 | echo uninstall - uninstall the services |
| 38 | echo. | 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 | goto end | 44 | goto end |
| 41 | 45 | ||
| 42 | :start | 46 | :start |
| 47 | +IF ""%2"" == ""mysql"" goto start_mysql | ||
| 43 | echo Starting services | 48 | echo Starting services |
| 44 | sc start %OpenofficeServiceName% | 49 | sc start %OpenofficeServiceName% |
| 45 | sc start %LuceneServiceName% | 50 | sc start %LuceneServiceName% |
| @@ -48,6 +53,7 @@ sc start %SchedulerServiceName% | @@ -48,6 +53,7 @@ sc start %SchedulerServiceName% | ||
| 48 | goto end | 53 | goto end |
| 49 | 54 | ||
| 50 | :stop | 55 | :stop |
| 56 | +IF ""%2"" == ""mysql"" goto stop_mysql | ||
| 51 | echo Stopping services | 57 | echo Stopping services |
| 52 | sc stop %LuceneServiceName% | 58 | sc stop %LuceneServiceName% |
| 53 | sc stop %SchedulerServiceName% | 59 | sc stop %SchedulerServiceName% |
| @@ -56,6 +62,16 @@ ping -n 7 127.0.0.1 > null | @@ -56,6 +62,16 @@ ping -n 7 127.0.0.1 > null | ||
| 56 | IF ""%1"" == ""restart"" goto start | 62 | IF ""%1"" == ""restart"" goto start |
| 57 | goto end | 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 | :restart | 75 | :restart |
| 60 | goto stop | 76 | goto stop |
| 61 | 77 |
dmsctl.sh
| 1 | -#!/bin/bash | ||
| 2 | - | ||
| 3 | # Boot KnowledgeTree services | 1 | # Boot KnowledgeTree services |
| 4 | # chkconfig: 2345 55 25 | 2 | # chkconfig: 2345 55 25 |
| 5 | # description: KnowledgeTree Services | 3 | # description: KnowledgeTree Services |
| @@ -40,6 +38,7 @@ LUCENE_PIDFILE=$INSTALL_PATH/var/log/lucene.pid | @@ -40,6 +38,7 @@ LUCENE_PIDFILE=$INSTALL_PATH/var/log/lucene.pid | ||
| 40 | LUCENE_PID="" | 38 | LUCENE_PID="" |
| 41 | LUCENE="$JAVABIN -Xms512M -Xmx512M -jar ktlucene.jar" | 39 | LUCENE="$JAVABIN -Xms512M -Xmx512M -jar ktlucene.jar" |
| 42 | LUCENE_STATUS="" | 40 | LUCENE_STATUS="" |
| 41 | +:q | ||
| 43 | 42 | ||
| 44 | # Scheduler | 43 | # Scheduler |
| 45 | SCHEDULER_PATH="$INSTALL_PATH/bin/" | 44 | SCHEDULER_PATH="$INSTALL_PATH/bin/" |
| @@ -49,6 +48,13 @@ SCHEDULERBIN="$INSTALL_PATH/var/bin/schedulerTask.sh" | @@ -49,6 +48,13 @@ SCHEDULERBIN="$INSTALL_PATH/var/bin/schedulerTask.sh" | ||
| 49 | SCHEDULER="$SCHEDULERBIN" | 48 | SCHEDULER="$SCHEDULERBIN" |
| 50 | SCHEDULER_STATUS="" | 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 | get_pid() { | 58 | get_pid() { |
| 53 | PID="" | 59 | PID="" |
| 54 | PIDFILE=$1 | 60 | PIDFILE=$1 |
| @@ -92,6 +98,16 @@ get_scheduler_pid() { | @@ -92,6 +98,16 @@ get_scheduler_pid() { | ||
| 92 | fi | 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 | is_service_running() { | 111 | is_service_running() { |
| 96 | PID=$1 | 112 | PID=$1 |
| 97 | if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then | 113 | if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then |
| @@ -138,6 +154,18 @@ is_scheduler_running() { | @@ -138,6 +154,18 @@ is_scheduler_running() { | ||
| 138 | return $RUNNING | 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 | start_soffice() { | 169 | start_soffice() { |
| 142 | is_soffice_running | 170 | is_soffice_running |
| 143 | RUNNING=$? | 171 | RUNNING=$? |
| @@ -272,12 +300,54 @@ stop_scheduler() { | @@ -272,12 +300,54 @@ stop_scheduler() { | ||
| 272 | fi | 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 | help() { | 344 | help() { |
| 276 | echo "usage: $0 help" | 345 | echo "usage: $0 help" |
| 277 | echo " $0 (start|stop|restart)" | 346 | echo " $0 (start|stop|restart)" |
| 278 | echo " $0 (start|stop|restart) scheduler" | 347 | echo " $0 (start|stop|restart) scheduler" |
| 279 | echo " $0 (start|stop|restart) soffice" | 348 | echo " $0 (start|stop|restart) soffice" |
| 280 | echo " $0 (start|stop|restart) lucene" | 349 | echo " $0 (start|stop|restart) lucene" |
| 350 | + echo " $0 (start|stop|restart) mysql" | ||
| 281 | cat <<EOF | 351 | cat <<EOF |
| 282 | 352 | ||
| 283 | help - this screen | 353 | help - this screen |