Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUSTCOM-14 Improvements in stop-domain process #4699

Merged
merged 3 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
import com.sun.enterprise.util.HostAndPort;
import com.sun.enterprise.util.io.FileUtils;
import com.sun.enterprise.util.io.ServerDirs;
import java.net.InetAddress;
import java.net.InetSocketAddress;

import org.glassfish.api.ActionReport;
import org.glassfish.api.admin.CommandException;
Expand Down Expand Up @@ -94,6 +96,7 @@ public abstract class LocalServerCommand extends CLICommand {
////////////////////////////////////////////////////////////////
private ServerDirs serverDirs;
private static final LocalStringsImpl STRINGS = new LocalStringsImpl(LocalDomainCommand.class);
private final static int IS_RUNNING_DEFAULT_TIMEOUT = 2000;

////////////////////////////////////////////////////////////////
/// Section: protected variables
Expand Down Expand Up @@ -354,24 +357,18 @@ protected final int getServerPid() {
* @return boolean indicating whether the server is running
*/
protected final boolean isRunning(String host, int port) {
Socket server = null;
try {
server = new Socket(host, port);

try(Socket server = new Socket()) {
if (host == null) {
host = InetAddress.getByName(null).getHostName();
}

server.connect( new InetSocketAddress(host, port), IS_RUNNING_DEFAULT_TIMEOUT);
return true;
}
catch (Exception ex) {
}catch (Exception ex) {
logger.log(Level.FINER, "\nisRunning got exception: {0}", ex);
return false;
}
finally {
if (server != null) {
try {
server.close();
}
catch (IOException ex) {
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.sun.enterprise.admin.cli.remote.RemoteCLICommand;
import com.sun.enterprise.universal.process.ProcessUtils;
import com.sun.enterprise.util.io.FileUtils;
import com.sun.enterprise.util.net.NetUtils;
import java.io.File;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -95,10 +96,7 @@ protected void validate()
protected void initDomain() throws CommandException {
// only initialize local domain information if it's a local operation

// TODO Byron said in April 2013 that we should probably just check if
// NetUtils says that the getHost() --> isThisMe() rather than merely
// checking for the magic "localhost" string. Too risky to fool with it today.
if (programOpts.getHost().equals(CLIConstants.DEFAULT_HOSTNAME)) {
if (NetUtils.isThisHostLocal(programOpts.getHost())) {
MeroRai marked this conversation as resolved.
Show resolved Hide resolved
super.initDomain();
} else if (userArgDomainName != null) { // remote case
throw new CommandException(Strings.get("StopDomain.noDomainNameAllowed"));
Expand Down