1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.CommandException; 27 import com.sun.enterprise.cli.framework.CommandValidationException; 28 import com.sun.enterprise.cli.framework.CLILogger; 29 import java.lang.IllegalThreadStateException ; 30 import com.sun.enterprise.util.SystemPropertyConstants; 31 import com.sun.enterprise.util.OS; 32 import java.io.File ; 33 import java.io.IOException ; 34 35 36 45 public final class StartDatabaseCommand extends DatabaseCommand 46 { 47 private final static String DB_HOME = "dbhome"; 48 private String dbHome; 49 50 57 public boolean validateOptions() throws CommandValidationException 58 { 59 return super.validateOptions(); 60 } 61 62 63 68 public String [] startDatabaseCmd() throws Exception 69 { 70 if (OS.isDarwin()) { 71 return new String [] { 72 sJavaHome+File.separator+"bin"+File.separator+"java", 73 "-Djava.library.path="+sInstallRoot+File.separator+"lib", 74 "-Dderby.storage.fileSyncTransactionLog=True", 75 "-cp", 76 sClasspath + File.pathSeparator + sDatabaseClasspath, 77 "com.sun.enterprise.cli.commands.DerbyControl", 78 "start", 79 dbHost, dbPort, "true", dbHome 80 }; 81 } 82 else { 83 return new String [] { 84 sJavaHome+File.separator+"bin"+File.separator+"java", 85 "-Djava.library.path="+sInstallRoot+File.separator+"lib", 86 "-cp", 87 sClasspath + File.pathSeparator + sDatabaseClasspath, 88 "com.sun.enterprise.cli.commands.DerbyControl", 89 "start", 90 dbHost, dbPort, "true", dbHome 91 }; 92 } 93 } 94 95 96 101 public String [] sysinfoCmd() throws Exception 102 { 103 if (OS.isDarwin()) { 104 return new String [] { 105 sJavaHome+File.separator+"bin"+File.separator+"java", 106 "-Djava.library.path="+sInstallRoot+File.separator+"lib", 107 "-Dderby.storage.fileSyncTransactionLog=True", 108 "-cp", 109 sClasspath + File.pathSeparator + sDatabaseClasspath, 110 "com.sun.enterprise.cli.commands.DerbyControl", 111 "sysinfo", 112 dbHost, dbPort, "false" 113 }; 114 } 115 else { 116 return new String [] { 117 sJavaHome+File.separator+"bin"+File.separator+"java", 118 "-Djava.library.path="+sInstallRoot+File.separator+"lib", 119 "-cp", 120 sClasspath + File.pathSeparator + sDatabaseClasspath, 121 "com.sun.enterprise.cli.commands.DerbyControl", 122 "sysinfo", 123 dbHost, dbPort, "false" 124 }; 125 } 126 } 127 128 129 133 public void runCommand() throws CommandException, CommandValidationException 134 { 135 validateOptions(); 136 final CLIProcessExecutor cpe = new CLIProcessExecutor(); 137 String dbLog = ""; 138 try { 139 prepareProcessExecutor(); 140 141 dbHome = getOption(DB_HOME)==null?System.getProperty("user.dir"): 143 getOption(DB_HOME); 144 dbLog = dbHome + File.separator + DerbyControl.DB_LOG_FILENAME; 145 146 CLILogger.getInstance().printDebugMessage("Ping Database"); 147 cpe.execute(pingDatabaseCmd(true), true); 148 if (cpe.exitValue() > 0) { 150 CLILogger.getInstance().printDebugMessage("Start Database"); 151 cpe.execute(startDatabaseCmd(), false); 152 if (cpe.exitValue() != 0) { 153 throw new CommandException(getLocalizedString("UnableToStartDatabase", 154 new Object []{dbLog})); 155 } 156 } 157 else if (cpe.exitValue() < 0) { 158 throw new CommandException(getLocalizedString("CommandUnSuccessful", 160 new Object [] {name} )); 161 } 162 else { 163 CLILogger.getInstance().printMessage(getLocalizedString( 165 "StartDatabaseStatus", 166 new Object []{dbHost, dbPort})); 167 CLILogger.getInstance().printDetailMessage(getLocalizedString( 168 "CommandSuccessful", 169 new Object [] {name})); 170 } 171 } 172 catch (IllegalThreadStateException ite) { 173 178 if (!getBooleanOption(TERSE)) { 179 try { 180 CLILogger.getInstance().printDetailMessage( 181 getLocalizedString("database.info.msg", 182 new Object []{dbHost, dbPort})); 183 CLILogger.getInstance().printDebugMessage("Database SysInfo"); 185 new CLIProcessExecutor().execute(sysinfoCmd(), true); 186 } 187 catch (Exception e) { 188 throw new CommandException(getLocalizedString("CommandUnSuccessful", 189 new Object [] {name}), e); 190 } 191 } 192 CLILogger.getInstance().printMessage(getLocalizedString("DatabaseStartMsg")); 193 if ((new File (dbLog)).canWrite()) { 194 CLILogger.getInstance().printMessage(getLocalizedString("LogRedirectedTo", 195 new Object []{dbLog})); 196 } 197 198 CLILogger.getInstance().printDetailMessage(getLocalizedString( 199 "CommandSuccessful", 200 new Object [] {name})); 201 } 202 catch (Exception e) { 203 displayExceptionMessage(e); 204 } 205 } 206 207 } 208 | Popular Tags |