Search in sources :

Example 1 with ProcessManager.behaviour

use of org.neo4j.server.startup.ProcessManager.behaviour in project neo4j by neo4j.

the class WindowsBootloaderOs method runProcess.

private void runProcess(List<String> command, ProcessManager.Behaviour behaviour) {
    List<String> entireCommand = asExternalCommand(command);
    ctx.processManager().run(entireCommand, behaviour);
    if (entireCommand.stream().anyMatch(cmd -> cmd.equals(powershellCmd())) && command.stream().anyMatch(cmd -> cmd.endsWith(PRUNSRV_I_386_EXE) || cmd.endsWith(PRUNSRV_AMD_64_EXE))) {
        // This is special condition where we run a command with our prunsrv windows-service util and we have to run it with powershell,
        // probably because we're running a command which exceeds 2000 characters which is the limit of cmd.exe.
        // Since it seems to be really hard to make powershell wait for completion of commands that it runs (we've certainly tried)
        // then we have to try and wait the completion manually here. The general idea is to see if there's any prunsrv process running
        // and we're simply waiting until there is none. Now this is somewhat risky because if there's any other process with the exact same name
        // we'll wait here for the max time. Although know that the PS1 scripts that this was ported from doesn't even have the option to run
        // these prunsrv commands in powershell.exe, it always ran them in cmd.exe. The main cause of a command line being too long for cmd.exe
        // is that the classpath is too long since other things are somewhat fixed and doesn't exceed this limit on any sane environment.
        // And the main reason the classpath is too long is that we're currently running in a test environment, because in a real-world
        // packaging environment the classpath is a couple of wildcard directories.
        Stopwatch stopwatch = Stopwatch.start();
        do {
            try {
                resultFromPowerShellCommand("Get-Process", PRUNSRV_AMD_64_EXE + "," + PRUNSRV_I_386_EXE);
                // If this command completes normally there's at least one running process containing that name
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ie) {
                    Thread.currentThread().interrupt();
                    break;
                }
            } catch (BootFailureException e) {
                // If this command returns exit code != 0 it typically means that there's no processes of this name running
                break;
            }
        } while (!stopwatch.hasTimedOut(Bootloader.DEFAULT_NEO4J_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS));
    }
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Files(java.nio.file.Files) Lists(org.eclipse.collections.api.factory.Lists) GraphDatabaseSettings.logs_directory(org.neo4j.configuration.GraphDatabaseSettings.logs_directory) Preconditions(org.neo4j.util.Preconditions) StringUtils(org.apache.commons.lang3.StringUtils) MutableList(org.eclipse.collections.api.list.MutableList) Collectors(java.util.stream.Collectors) ProcessManager.behaviour(org.neo4j.server.startup.ProcessManager.behaviour) Stopwatch(org.neo4j.time.Stopwatch) String.format(java.lang.String.format) BootloaderSettings.windows_tools_directory(org.neo4j.configuration.BootloaderSettings.windows_tools_directory) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) TimeUnit(java.util.concurrent.TimeUnit) StringUtils.join(org.apache.commons.lang3.StringUtils.join) List(java.util.List) Stream(java.util.stream.Stream) EXIT_CODE_NOT_RUNNING(org.neo4j.server.startup.Bootloader.EXIT_CODE_NOT_RUNNING) GraphDatabaseSettings.store_user_log_path(org.neo4j.configuration.GraphDatabaseSettings.store_user_log_path) Path(java.nio.file.Path) Arrays.stream(java.util.Arrays.stream) BootloaderSettings(org.neo4j.configuration.BootloaderSettings) Stopwatch(org.neo4j.time.Stopwatch)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 String.format (java.lang.String.format)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Arrays.stream (java.util.Arrays.stream)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StringUtils (org.apache.commons.lang3.StringUtils)1 StringUtils.isNotEmpty (org.apache.commons.lang3.StringUtils.isNotEmpty)1 StringUtils.join (org.apache.commons.lang3.StringUtils.join)1 Lists (org.eclipse.collections.api.factory.Lists)1 MutableList (org.eclipse.collections.api.list.MutableList)1 BootloaderSettings (org.neo4j.configuration.BootloaderSettings)1 BootloaderSettings.windows_tools_directory (org.neo4j.configuration.BootloaderSettings.windows_tools_directory)1 GraphDatabaseSettings.logs_directory (org.neo4j.configuration.GraphDatabaseSettings.logs_directory)1 GraphDatabaseSettings.store_user_log_path (org.neo4j.configuration.GraphDatabaseSettings.store_user_log_path)1 EXIT_CODE_NOT_RUNNING (org.neo4j.server.startup.Bootloader.EXIT_CODE_NOT_RUNNING)1