diff --git a/mysql-test/r/im_life_cycle.result b/mysql-test/r/im_life_cycle.result index a9f78aea7d3..211a82eb9cf 100644 --- a/mysql-test/r/im_life_cycle.result +++ b/mysql-test/r/im_life_cycle.result @@ -74,3 +74,6 @@ START INSTANCE mysqld1,mysqld2,mysqld3; ERROR 42000: You have an error in your command syntax. Check the manual that corresponds to your MySQL Instance Manager version for the right syntax to use STOP INSTANCE mysqld1,mysqld2,mysqld3; ERROR 42000: You have an error in your command syntax. Check the manual that corresponds to your MySQL Instance Manager version for the right syntax to use +STOP INSTANCE mysqld2; +ERROR HY000: Cannot stop instance. Perhaps the instance is not started, or was started manually, so IM cannot find the pidfile. +End of 5.0 tests diff --git a/mysql-test/t/im_life_cycle.imtest b/mysql-test/t/im_life_cycle.imtest index 2cbe53a7b28..c3a5fb0a648 100644 --- a/mysql-test/t/im_life_cycle.imtest +++ b/mysql-test/t/im_life_cycle.imtest @@ -218,3 +218,11 @@ START INSTANCE mysqld1,mysqld2,mysqld3; --error ER_SYNTAX_ERROR STOP INSTANCE mysqld1,mysqld2,mysqld3; + +# +# Bug #12673: Instance Manager: allows to stop the instance many times +# +--error 3001 +STOP INSTANCE mysqld2; + +--echo End of 5.0 tests diff --git a/server-tools/instance-manager/instance.cc b/server-tools/instance-manager/instance.cc index 39381b457ab..2ed369ba245 100644 --- a/server-tools/instance-manager/instance.cc +++ b/server-tools/instance-manager/instance.cc @@ -469,37 +469,38 @@ int Instance::stop() struct timespec timeout; uint waitchild= (uint) DEFAULT_SHUTDOWN_DELAY; - if (options.shutdown_delay_val) - waitchild= options.shutdown_delay_val; - - kill_instance(SIGTERM); - /* sleep on condition to wait for SIGCHLD */ - - timeout.tv_sec= time(NULL) + waitchild; - timeout.tv_nsec= 0; - if (pthread_mutex_lock(&LOCK_instance)) - goto err; - - while (options.get_pid() != 0) /* while server isn't stopped */ + if (is_running()) { - int status; + if (options.shutdown_delay_val) + waitchild= options.shutdown_delay_val; - status= pthread_cond_timedwait(&COND_instance_stopped, - &LOCK_instance, - &timeout); - if (status == ETIMEDOUT || status == ETIME) - break; + kill_instance(SIGTERM); + /* sleep on condition to wait for SIGCHLD */ + + timeout.tv_sec= time(NULL) + waitchild; + timeout.tv_nsec= 0; + if (pthread_mutex_lock(&LOCK_instance)) + return ER_STOP_INSTANCE; + + while (options.get_pid() != 0) /* while server isn't stopped */ + { + int status; + + status= pthread_cond_timedwait(&COND_instance_stopped, + &LOCK_instance, + &timeout); + if (status == ETIMEDOUT || status == ETIME) + break; + } + + pthread_mutex_unlock(&LOCK_instance); + + kill_instance(SIGKILL); + + return 0; } - pthread_mutex_unlock(&LOCK_instance); - - kill_instance(SIGKILL); - - return 0; - return ER_INSTANCE_IS_NOT_STARTED; -err: - return ER_STOP_INSTANCE; } #ifdef __WIN__ diff --git a/server-tools/instance-manager/messages.cc b/server-tools/instance-manager/messages.cc index a9b00b9e01f..d2595638de0 100644 --- a/server-tools/instance-manager/messages.cc +++ b/server-tools/instance-manager/messages.cc @@ -48,8 +48,8 @@ static const char *mysqld_error_message(unsigned sql_errno) case ER_BAD_INSTANCE_NAME: return "Bad instance name. Check that the instance with such a name exists"; case ER_INSTANCE_IS_NOT_STARTED: - return "Cannot stop instance. Perhaps the instance is not started, or was started" - "manually, so IM cannot find the pidfile."; + return "Cannot stop instance. Perhaps the instance is not started, or was" + " started manually, so IM cannot find the pidfile."; case ER_INSTANCE_ALREADY_STARTED: return "The instance is already started"; case ER_CANNOT_START_INSTANCE: @@ -67,7 +67,7 @@ static const char *mysqld_error_message(unsigned sql_errno) return "Cannot open log file"; case ER_GUESS_LOGFILE: return "Cannot guess the log filename. Try specifying full log name" - "in the instance options"; + " in the instance options"; case ER_ACCESS_OPTION_FILE: return "Cannot open the option file to edit. Check permissions"; default: