jsvc & Gradle - no console output, Gradle daemon crashes

725 views Asked by At

I'm trying to test my Java app with IntelliJ IDEA on my local machine (it is intended to be used as a daemon, therefore the use of jsvc).

For testing purposes I want both stdout and stderr to be output to console. According to the jsvc help site (jsvc --help) setting -outfile '&2' and -errfile '&1' should redirect stdout and stderr to each other (as per my understanding).

In a normal shell (with these two options set) the daemon launches and outputs some stuff to the console, but when using a Gradle Exec task and the exact same command the Gradle daemon crashes and outputs to the files '&2' and '&1'.

The task configuration:

File jsvcFile = file("./jsvc")
File pidFile = file("./jsvc.pid")

String mainClass = "substupdater.SubstUpdater"

task run (dependsOn: [jar, jsvc], type: Exec) {

    doFirst {

        // Get the absolute path of all libraries
        String classPath = project.configurations.compile.join(':')

        executable(jsvcFile)

        args("-server", "-cp", classPath + ':' + jar.archivePath, "-nodetach",
             "-cwd", project.rootDir, "-outfile", "'&2'", "-errfile", "'&1'",
             "-pidfile", pidFile, "-procname", project.name, mainClass, "debug")

    }
}

Gradle daemon crash (gradle -d run):

21:57:52.911 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING
21:57:52.914 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Waiting until process started: command '/path/to/jsvc'.
21:57:52.924 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTED
21:57:52.925 [INFO] [org.gradle.process.internal.DefaultExecHandle] Successfully started process 'command '/path/to/jsvc''
21:57:52.926 [DEBUG] [org.gradle.process.internal.ExecHandleRunner] waiting until streams are handled...
Daemon vm is shutting down... The daemon has exited normally or was terminated in response to a user interrupt.
21:57:53.528 [DEBUG] [org.gradle.launcher.daemon.registry.PersistentDaemonRegistry] Removing daemon address: [some-address port:35450, addresses:[/0:0:0:0:0:0:0:1%lo, /127.0.0.1]]
21:57:53.529 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire exclusive lock on daemon addresses registry.
21:57:53.529 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
21:57:53.530 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
21:57:53.530 [DEBUG] [org.gradle.process.internal.ExecHandleRunner] Abort requested. Destroying process: command '/path/to/jsvc'.
21:57:53.532 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: ABORTED
21:57:53.533 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'command '/path/to/jsvc'' finished with exit value 1 (state: ABORTED)
----- End of the daemon log -----

21:57:53.888 [DEBUG] [org.gradle.launcher.daemon.client.DaemonClientInputForwarder] Dispatching close input message: org.gradle.launcher.daemon.protocol.CloseInput@ce9a99
21:57:53.888 [DEBUG] [org.gradle.launcher.daemon.client.DaemonClientConnection] thread 18: dispatching class org.gradle.launcher.daemon.protocol.CloseInput
21:57:53.889 [DEBUG] [org.gradle.launcher.daemon.client.DaemonClientConnection] thread 1: connection stop
21:57:53.907 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
21:57:53.907 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
21:57:53.907 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
21:57:53.908 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
21:57:53.908 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
21:57:53.908 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
21:57:53.908 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try:
21:57:53.908 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace.

Any help would be appreciated :)

1

There are 1 answers

0
Makk0 On BEST ANSWER

I just had to specify the full path to the file descriptor symlinks (namely /proc/self/fd/1 for stdout and /proc/self/fd/2 for stderr) and now output is being done to console.

The Gradle daemon still crashes but I think this is due to Gradle not being able to handle that the jsvc daemon process kills itself(?).