How do i know that jetty started successfully with application instance from an ant target? - ant

I face the following problem: whenever i try to start Jetty with an application instance i need check if the application is running. I need to do that from an ant target.
I want to have something behaving like the following pseudocode:
**
<target name="target1"
depends="run-jetty-with-application"
description="Target1">
<--when run-jetty-with-application is ok(jetty is up and application is running)-->
<antcall target="target2"/>
<--end when-->
</target>
**
I should also mention that i have no publicly exposed urls that could give me the status of the application.
I'm not after the hacky solution like waitfor.
Thanks in advance!

There are only 2 ways to know if Jetty is started, all webapps are deployed without error, all lifecycle is started successfully, and the server is available to serve content.
Periodically ask for a resource on that web app, confirming that it is up and running. (timeout with failure if resources doesn't make itself available after a period of time)
Hook into the LifeCycle.Listener on the Server component, wait for the .lifeCycleStarted(LifeCycle event) for the server, then walk the entire handler tree, looking for any Handler component that failed to deploy via the DeploymentManager.
As you can imagine, the first technique is the easiest.
This is the <waitfor> facility in Ant, and is what the Jetty project itself uses.
The second approach requires a custom Ant task.
You can either write it yourself, and know that it will do what you want. Or use the jetty-ant tasks with daemon mode to get almost the same thing (the JettyRunTask in daemon mode starts up the server, but it does not wait for start to finish or the webapps to deploy successfully before it returns control to ant).

Related

How to set log direction in Spring Cloud DataFlow

I have set
spring.cloud.deployer.local.workingDirectoriesRoot=D:\\Deploy
in application.properties to define log folder.
However, It does not works, the log of task when I launched is written on java.io.tmpdir (C:/..../temp/).
I am using spring-cloud-dataflow-server-core version 2.3.0.RELEASE
Does I need to put these config in dataflow-server.yml ?
How can I configure the log folder of SCDF and their tasks?
We just added some tests for windows and noticed that correct format (assuming task name is timestamp) which actually works on windows when using drive letter is:
deployer.timestamp.local.working-directories-root=file:/C:/tmp
Think is how in a spring world binding works from String to java.nio.file.Path. For those interested to know more, It's spring core's PathEditor which uses Paths.get(URI), thus need for file:.
The property workingDirectoriesRoot is a local deployer property and not an application property. Hence, it needs to be passed when launching the task.
task launch <task-name> --properties "deployer.<task-name>.local.workingDirectoriesRoot=D:\\Deploy"

Umbraco scheduledTasks not working

I have a scheduled task that I want to run every 5 minutes.
I added the url for my method in umbracoSettings.config and the necessary settings but scheduledTasks doesn't seem to be running.
I tried debugging it by calling the url from the browser and I do hit my break point.
I tried checking the logs but there are no errors being recorded. Is this a bug in umbraco? How can I know that the scheduled task is running?
<scheduledTasks>
<!-- add tasks that should be called with an interval (seconds) -->
<task log="true" alias="task1" interval="300" url="http://localhost:43203/umbraco/api/Integration/Init"/>
</scheduledTasks>
I'm using Umbraco 7.5.8
I never had trouble using scheduledTasks in other versions of Umbraco.
The main issue I've seen with scheduled tasks is when the server that's running can't resolve the address in the task. Sometimes a server can be so locked down it can't actually "see" itself, so it can't get to the URL to run it. If this was the case though, you'd normally see some errors in the Umbraco TraceLog file in /App_Data/Logs/.
If your breakpoint isn't getting hit, you could try adding some logging code to the method you're calling and see if that gets written to the Umbraco log files? That way you should be able to tell if it's being hit or not.
Its working now. if you look at umbracoServer table in the database you will see a column isMaster.
The scheduledTasks is only running on the master server.

How to remote debug a Spring Cloud Data flow Task

We are using Spring XD for executing some batch jobs and considering to use Spring Cloud Dataflow. For this I wanted to remote debug a execution of a Task and I was not able to make it working.
I tried to export the following environment variable before the SCDF server is started:
spring.cloud.deployer.local.javaOpts=Xdebug -Xrunjdwp:transport=dt_socket,address=12201,server=y
Also tried to pass as argument in the GUI while invoking the task:
app.<appname>.local.javaOpts=Xdebug -Xrunjdwp:transport=dt_socket,address=12201,server=y
Nothing seems to be working.
I'm able to debug the composed-task-runner launched by SCDF using the listen debugger mode, this will also work for your task as well.
Run Debugger in your IDE in listen mode on port 5006. (this project's classpath should have composed-task-runner sources, put break point some where )
Run SCDF with -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 option, attach debugger to the SCDF process in your IDE on port 5005 (attach mode).
Put breakpoint at this line :
String javaOptsString = getValue(deploymentProperties, "javaOpts");
in JavaCommandBuilder class (for spring-cloud-deployer-local v.1.3.0.M2 it's line #83).
Launch your task - debugger stops at breakpoint.
Step Over once in your IDE, the value of javaOptsString is null now. Using IDE, set the value of javaOptsString to
-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5006,suspend=y
Press Resume in IDE.
Your breakpoint set in #1 should be hit in few seconds.
If you know how to pass javaOpts as deployment properties of your task - you will be able to debug in listen mode without this nightmare ;-). I've not found a way to escape = and , characters in the -agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5006,suspend=y javaOpts deployment property.
We are working on an improved solution for the local-deployer - you can follow spring-cloud/spring-cloud-dataflow#369 for tracking purpose.
There is, however, the following option that exists to aggregate all the application logs into the server console directly, which might be useful while in active development.
stream deploy --name myStream --properties "deployer.*.local.inheritLogging=true"
Finally I was able to remote debug a composed task or regular task. Follow the below steps:
In scdf UI go to tasks and click on the definition section
Click play button (invoke) on the task/composed task that you want to invoke.
On the launch task page define your task arguments
Add the following properties by clicking 'Add Property' button:
- deployer.composed-task-runner.local.debugPort=12103
- deployer.composed-task-runner.local.debugSuspend=y
Now launch the task
You can now see in the log that when the composed task's java process is launched it is called with the debug parameter.
If you want to control the heap memory or any java options you can do by adding the following property:
deployer.composed-task-runner.local.javaOpts=Xmx2048M
Note that 'composed-task-runner' is the name of the App (Not the name of the task).

Web deployment failing due to file in use

I'm using Microsoft's Web Deploy Remote Agent service to allow me to easily publish code to the server from within Visual Studio.
The web site I am deploying is using log4net to log messages to log files, and every time I try to deploy a new version of the code, I get this error in Visual Studio stating that the current log4net log file is in use:
An error occurred when the request was processed on the remote
computer. The file 'Web.log' is in use.
The process cannot access 'C:\inetpub\wwwroot\Logs\Web.log' because it
is being used by another process.
I can solve this by going onto the server and doing an iisreset before publishing... but that is kind of defeating the point of 'easy' publishing from Visual Studio :)
Is there some way I can get the publish task to issue an iisreset automatically, or some other way I can work round this?
I kept poking around and found some tidbits around the file being locked in a few other forums. Have you tried adding
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
To your <appender> element in the web.config file? From the Apache docs
Opens the file once for each AcquireLock/ReleaseLock cycle,
thus holding the lock for the minimal amount of time. This method of
locking is considerably slower than FileAppender.ExclusiveLock but
allows other processes to move/delete the log file whilst logging
continues.
As far as the performance considerations, I suppose you would need to test if this will affect you or not as I am assuming it really depends on how often you are writing to the log file as to how much this will impact performance. I can't believe that getting/releasing a lock could take all that much time though.
There is a MSDEPLOY provider called recycleApp which is used exactly for this. You can include this in your deployment manifest.
Another option is to use ignoreOnErrors flag which will skip the file in use and continue with the deployment.

Forcing a Windows service to fail

Whenever a specific Windows service fails I want to run a program I've created myself. However, I simply can't find a way to make it fail on purpose, so that I can actually test that everything works correctly.
Note that the service in question is not something I've written myself, so I can't make it fail programmatically from inside the code. I wouldn't, however, mind writing a program that can make a service fail.
Of course I would prefer just having a "Make service fail" button somewhere in services.msc ... ;)
The server I'm doing this on is running Windows Server 2012.
If you don't want to use command line :
As an admin open the Windows Task Manager, in the Services tab find the service you want to test. Right click the service and click on Go to process. The selected process (if any) is the one corresponding to your service. Kill this process to simulate a service failure.
Be aware that killing a process this way can lead to problems.
Define "fail". If you want the process to end, just use pskill or a similar tool that can terminate a process elevated (as an admin).

Resources