| | |
| | | import java.awt.Toolkit; |
| | | import java.awt.Window; |
| | | import java.io.BufferedOutputStream; |
| | | import java.io.BufferedWriter; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.FileWriter; |
| | |
| | | import java.io.InputStream; |
| | | import java.io.PrintWriter; |
| | | import java.io.RandomAccessFile; |
| | | import java.io.Writer; |
| | | import java.net.ConnectException; |
| | | import java.net.InetSocketAddress; |
| | | import java.net.ServerSocket; |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.HashSet; |
| | |
| | | import org.opends.quicksetup.CurrentInstallStatus; |
| | | import org.opends.quicksetup.i18n.ResourceProvider; |
| | | import org.opends.quicksetup.installer.webstart.JnlpProperties; |
| | | import org.opends.server.util.SetupUtils; |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static boolean canUseAsPort(int port) |
| | | { |
| | | boolean canUseAsPort = false; |
| | | ServerSocket serverSocket = null; |
| | | try |
| | | { |
| | | InetSocketAddress socketAddress = new InetSocketAddress(port); |
| | | serverSocket = new ServerSocket(); |
| | | if (!isWindows()) |
| | | { |
| | | serverSocket.setReuseAddress(true); |
| | | } |
| | | serverSocket.bind(socketAddress); |
| | | canUseAsPort = true; |
| | | |
| | | serverSocket.close(); |
| | | |
| | | /* Try to create a socket because sometimes even if we can create a server |
| | | * socket there is already someone listening to the port (is the case |
| | | * of products as Sun DS 6.0). |
| | | */ |
| | | try |
| | | { |
| | | new Socket("localhost", port); |
| | | canUseAsPort = false; |
| | | |
| | | } catch (IOException ioe) |
| | | { |
| | | } |
| | | |
| | | } catch (IOException ex) |
| | | { |
| | | canUseAsPort = false; |
| | | } finally |
| | | { |
| | | try |
| | | { |
| | | if (serverSocket != null) |
| | | { |
| | | serverSocket.close(); |
| | | } |
| | | } catch (Exception ex) |
| | | { |
| | | } |
| | | } |
| | | |
| | | return canUseAsPort; |
| | | return SetupUtils.canUseAsPort(port); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static boolean isPriviledgedPort(int port) |
| | | { |
| | | return (port <= 1024) && !isWindows(); |
| | | return SetupUtils.isPriviledgedPort(port); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static boolean isWindows() |
| | | { |
| | | return containsOsProperty("windows"); |
| | | return SetupUtils.isWindows(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static boolean isMacOS() |
| | | { |
| | | return containsOsProperty("mac os"); |
| | | return SetupUtils.isMacOS(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static boolean isUnix() |
| | | { |
| | | return !isWindows(); |
| | | return SetupUtils.isUnix(); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * Commodity method to help identifying the OS we are running on. |
| | | * @param s the String that represents an OS. |
| | | * @return <CODE>true</CODE> if there is os java property exists and contains |
| | | * the value specified in s, <CODE>false</CODE> otherwise. |
| | | */ |
| | | private static boolean containsOsProperty(String s) |
| | | { |
| | | boolean containsOsProperty = false; |
| | | |
| | | String osName = System.getProperty("os.name"); |
| | | if (osName != null) |
| | | { |
| | | containsOsProperty = osName.toLowerCase().indexOf(s) != -1; |
| | | } |
| | | |
| | | return containsOsProperty; |
| | | } |
| | | |
| | | /** |
| | | * Sets the permissions of the provided paths with the provided permission |
| | | * String. |
| | | * @param paths the paths to set permissions on. |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns if the server is running on the given path. |
| | | * @param serverPath the installation path of the server. |
| | | * @return <CODE>true</CODE> if the server is running and <CODE>false</CODE> |
| | | * otherwise. |
| | | */ |
| | | public static boolean isServerRunning(String serverPath) |
| | | { |
| | | boolean isServerRunning; |
| | | if (isWindows()) |
| | | { |
| | | String testPath = serverPath+File.separator+ |
| | | "locks"+File.separator+"server.lock"; |
| | | File testFile = new File(testPath); |
| | | |
| | | boolean canWriteFile = false; |
| | | Writer output = null; |
| | | try { |
| | | //use buffering |
| | | //FileWriter always assumes default encoding is OK! |
| | | output = new BufferedWriter( new FileWriter(testFile) ); |
| | | output.write("test"); |
| | | output.close(); |
| | | output = new BufferedWriter( new FileWriter(testFile) ); |
| | | output.write(""); |
| | | output.close(); |
| | | |
| | | canWriteFile = true; |
| | | |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | finally |
| | | { |
| | | if (output != null) |
| | | { |
| | | try |
| | | { |
| | | output.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | } |
| | | isServerRunning = !canWriteFile; |
| | | } |
| | | else |
| | | { |
| | | isServerRunning = fileExists(serverPath+File.separator+ |
| | | "logs"+File.separator+"server.pid"); |
| | | } |
| | | return isServerRunning; |
| | | } |
| | | |
| | | /** |
| | | * This is just a commodity method used to try to get an InitialLdapContext. |
| | | * @param t the Thread to be used to create the InitialLdapContext. |
| | | * @param pair an Object[] array that contains the InitialLdapContext and the |