// remove instance data
public void removeInstance() {
BrokerResources rb = Globals.getBrokerResources();
Logger logger = Globals.getLogger();
// check existence of the instance
String topdir = Globals.getInstanceDir();
if (!(new File(topdir)).exists()) {
if (!silent) {
// print out error message if not silent
System.err.println(rb.getString(rb.E_INSTANCE_NOT_EXIST,
Globals.getConfigName()));
}
Broker.getBroker().exit(BrokerExitCode.INSTANCE_NOT_EXISTS,
rb.getString(rb.E_INSTANCE_NOT_EXIST,
Globals.getConfigName()),
BrokerEvent.Type.FATAL_ERROR);
}
BrokerStateHandler.shuttingDown = false;
BrokerStateHandler.shutdownStarted = false;
// make sure no other running broker is using this instance
BrokerConfig conf = Globals.getConfig();
LockFile lf = null;
try {
lf = LockFile.getLock(
conf.getProperty(Globals.JMQ_VAR_HOME_PROPERTY),
Globals.getConfigName(),
"localhost", // no need to localize
0);
} catch (Exception e) {
Object[] msgargs = {
LockFile.getLockFilePath(conf.getProperty(
Globals.JMQ_VAR_HOME_PROPERTY),
Globals.getConfigName()),
e.toString(),
Globals.getConfigName()};
logger.logStack(Logger.ERROR, rb.E_LOCKFILE_EXCEPTION, msgargs, e);
getBroker().exit(BrokerExitCode.IOEXCEPTION,
rb.getKString(rb.E_LOCKFILE_EXCEPTION, msgargs),
BrokerEvent.Type.FATAL_ERROR);
}
// Make sure we got the lock
if (!lf.isMyLock()) {
Object[] msgargs = {
lf.getFilePath(),
lf.getHost() + ":" + lf.getPort(),
Globals.getConfigName()};
logger.log(Logger.ERROR, rb.E_LOCKFILE_INUSE, msgargs);
getBroker().exit(BrokerExitCode.INSTANCE_BEING_USED,
rb.getKString(rb.E_LOCKFILE_INUSE, msgargs),
BrokerEvent.Type.FATAL_ERROR);
}
boolean loggerClosed = false;
try {
if (!force) {
// get confirmation
String yes = rb.getString(rb.M_RESPONSE_YES);
String yes_s = rb.getString(rb.M_RESPONSE_YES_SHORT);
String no_s = rb.getString(rb.M_RESPONSE_NO_SHORT);
String objs[] = { Globals.getConfigName(),
yes_s,
no_s
};
System.out.print(rb.getString(
rb.M_REMOVE_INSTANCE_CONFIRMATION, objs));
System.out.flush();
String val = (new BufferedReader(new InputStreamReader
(System.in))).readLine();
// if not positive confirmation, just exit!
if (!yes_s.equalsIgnoreCase(val) &&
!yes.equalsIgnoreCase(val)) {
printErr(rb.getString(rb.I_INSTANCE_NOT_REMOVED));
Broker.getBroker().exit(1,
rb.getString(rb.I_INSTANCE_NOT_REMOVED),
BrokerEvent.Type.SHUTDOWN);
}
}
// audit logging of remove instance
Globals.getAuditSession().brokerOperation(null, null,MQAuditSession.REMOVE_INSTANCE);
// delete the persistence store first
// the property Store.I_REMOVE_PERSISTENT_STORE should
// be set correctly in parseArgs()
try {
Globals.getStore();
} catch (BrokerException ex) {
logger.log(Logger.ERROR, ex.toString());
Broker.getBroker().exit(BrokerExitCode.PROBLEM_REMOVING_PERSISTENT_STORE,
ex.toString(),
BrokerEvent.Type.EXCEPTION);
}
// now delete the rest
if (!silent) {
println(rb.getString(rb.I_REMOVE_INSTANCE));
}
// close the logger to make sure we can delete the log directory
// otherwise, in the case of NFS mounted directory, a hidden
// file will be created when the opened log file is deleted
// and that will prevent the log directory being removed
logger.close();
loggerClosed = true;
FileUtil.removeFiles(new File(topdir), true);
Broker.getBroker().exit(0, rb.getString(rb.I_REMOVE_INSTANCE),
BrokerEvent.Type.SHUTDOWN);
} catch (IOException ex) {
if (loggerClosed) {
logger.open();
}
logger.log(Logger.ERROR, ex.toString());
Broker.getBroker().exit(BrokerExitCode.IOEXCEPTION,
ex.toString(), BrokerEvent.Type.FATAL_ERROR);
}
}