Running Play service from Gradle - gradle

I am attempting to use a Gradle task to run a Play service, but I'm finding the Gradle task will hang (presumably waiting for a return value from the Play bootstrap script).
What I'm doing from the Play side is simply:
sbt dist
Which produces a .zip distribution (like 'myproject.zip'), which I then expand where I want to run this service from.
On the Gradle side, I was thinking I would do something like this:
task start(type: Exec) {
workingDir "myproject/bin"
commandLine './myproject'
}
This does indeed start up the Play service just fine, but the Gradle task will hang indefinitely (until you do a control+C).
The most obvious thing that came to mind to try was something like:
task start(type: Exec) {
workingDir "myproject/bin"
commandLine 'nohup ./myproject &'
}
But that ends in a dead end:
Execution failed for task ':start'.
> A problem occurred starting process 'command 'nohup ./playservicetemplate &''
It seems like this is a really common use case, so I'm wondering if there is an obvious solution that I'm overlooking.

There is perhaps a more Gradle-ish way to do this, but I solved it by leveraging ProcessBuilder. My new task looks like:
task start {
ProcessBuilder builder = new ProcessBuilder("./myproject")
builder.directory(new File("myproject/bin"))
builder.start()
}
Obviously, you can get a lot fancier with this (a quick Google of 'java processbuilder' will net you pages upon pages of examples), but this will do the trick for my purposes.

Related

Vert.x address already in use: bind - Not kill processes (Windows)

I'm creating a simple REST Server using Vert.x on intelliJ IDEA. When I run to test it, processes never are stopped after clicking the stop button from intelliJ. I undestand this because if I try to run, stop and rerun will appear the error "Address already in use: bind" so each time I must search java processes and kill them by Task Manager. Someone know a better solution?
I resolved changing in my build.gradle.kts this line of code:
tasks.withType<JavaExec> { args = listOf("run", mainVerticleName, "--redeploy=$watchForChange", "--launcher-class=$launcherClassName", "--on-redeploy=$doOnChange")}
With this:
tasks.withType<JavaExec> { args = listOf("run", mainVerticleName, "--launcher-class=$launcherClassName", "--on-redeploy=$doOnChange")}
So I removed the "--redeploy=$watchForChange" and it works fine.

Run Golang project in Sublime Text 3

I cannot find a suitable solution for my needs with running a Go project inside a Sublime Text 3 and seeing it's output in real-time.
If I try a build system from:
GoSublime - I can use run, it even runs and stops, but there is no output, which I need. It appears only when I cancel build - it's too late.
Official Golang Build from Go developers - I can build the project, and that's it. It allows to run 1 file (current) only, but I need the whole project.
I've tried to use flags for run command and to add *.go, but then I get *.go: no such file or directory
How do I see the output in real-time in one of these solutions? I've tried to create my own build system with shell_cmd = go run *.go, but stopping the process with Cancel build is not working then. Maybe you can explain how do I stop a running Go program? My mybuild.sublime-build is similar to this:
{
"env": {
"GOROOT": "/path/gosrc/go",
"GOPATH": "/path/godev"
},
"path": "$PATH:/path/gosrc/go/bin",
"working_dir": "/path/godev/src/github.com/user/program",
"cmd": "go run *.go",
"shell": true
}
..I can run Build and see the needed output, but how do I then stop a running process?
P.S. Program is not just executing and exiting - it's a service, so I should see the output when the needed actions happens.
I personally use GoSublime and go build . followed by running the app by name as a second command. Obviously this sucks in a lot of ways, but it kinda sorta works most of the time. It provides a nice fast way to check for compile errors, which is most of what I need.
Honestly, just running in a dedicated shell is nicer in every way.
AFAIK, there is no better Go build system available for Sublime Text (that isn't an endorsement, it sucks, just less than most).
I found a tutorial where I was able to run Go files on build in Sublime Text 3 here: https://www.alexedwards.net/blog/streamline-your-sublime-text-and-go-workflow
If you use Build With: Go - Run you get outputs, but if you are running for example a net/http local host in Go you won't be able to run multiple programs and cancel build also does not work.
Here is an example of simple fmt.Println output in Sublime Text 3:
> Environment:
> GOPATH=C:/Users/Christiaan/go
> Directory: C:\Users\Christiaan\Documents\02_Personal\04_Learning\09_Go\01_test
> Command: C:\Users\Christiaan\go\go1.15rc1\bin\go.exe run -v C:\Users\Christiaan\Documents\02_Personal\04_Learning\09_Go\01_test\test2.go
> Output:
command-line-arguments
gas_pedal: 22314 brake_pedal: 0 steering_wheel: 12562
> Elapsed: 3.856s
> Result: Success

Running two Gradle application tasks concurrently in same project

It looks like when I try to run a second Gradle task for the same project in a different window, the second one blocks on a lock. Is there a straightforward way around this?
What I'm trying to do: My project has a couple server subprojects that both use the application plugin. I'd like to start both (e.g., $ gradle :server1:run) so I could connect and try them out.
I know I can write a task to deploy the two servers to a test area and start them there, but the application:run task is convenient during development for one application, so I'd like to use it for two if possible.
I'm using Gradle 2.7.
Here is what I ended up doing. Rather than using the application plugin's run task, I used installDist, and wrote a simple task to run the generated start script. Then I extended it by creating a simple service script that I stored under src/dist/bin. The script handles start, stop, and status operations. The final result:
ext.installDir = "$buildDir/install/" + project.name
ext.command = "$installDir/bin/" + project.name
task start(type:Exec, dependsOn:'installDist') {
description "Starts the " + applicationName + " application"
workingDir "$installDir"
commandLine "$command", "start"
}
task stop(type:Exec, dependsOn:'installDist') {
description "Stops the " + applicationName + " application"
workingDir "$installDir"
commandLine "$command", "stop"
}
task status(type:Exec, dependsOn:'installDist') {
description "Displays the " + applicationName + " application status"
workingDir "$installDir"
commandLine "$command", "status"
}
Now from the parent project I can just type:
$ gradlew start
to start both servers and
$ gradlew stop
to shut them both down.

Run exe outside of gradle scope

I am trying to kick of an exe (mongodb) from gradle, but need that exe to run outside of gradle scope so that the gradle task is not blocked for ever.
task startMongo(type: Exec) {
executable "$buildDir/mongo/mongod.exe"
args "--dbpath=$buildDir/mongo/data/db"
}
Mongodb starts fine, but the task is blocked as the mongo server waits for connections.
2014-12-10T14:30:33.018-0700 [initandlisten] waiting for connections on port 27017
Robert - thank you. I wrote a custom gradle task and started the exe in background.
class MyTask extends DefaultTask {
#TaskAction
void startProcess() {
ProcessBuilder processBuilder = new ProcessBuilder()
processBuilder.command('exe-path', 'arg')
processBuilder.start()
}

vlad tasks: after update, before symlink

We're using vlad the deployer to deploy our rails app.
Currently, we have some tasks that run after the vlad:update task. These tasks take a few minutes. During those few minutes, the site is broken.
I'd like to run those tasks in the middle of vlad:update -- after it has done everything except create the "current" symlink. How do I do that? the vlad:update task appears to be monolothic.
Found the answer. Define your task to run before the update_symlinks task rather than after the update task.
remote_task :finish_deployment, :roles => :app do
...
end
remote_task :update_symlinks => :finish_deployment

Resources