How to invoke custom (java) program on Websphere Liberty Profile startup - websphere

How can i start a specific java program when a server instance has been started from within Websphere Liberty Profile?
eg. '> server start test' should start the server + start my specific java program (with a parameter if possible)

There is no builtin mechanism for this, so your best option would be to write a Liberty profile product extension that launches the extra program when the server starts. Specifically, write a feature that contains an OSGi bundle that contains a BundleActivator with a start method that launches the program.

Related

Start a spring boot application inside another java application?

I have two java applications:
a server starting with spring boot
a client using it (through REST api)
For the time, I start both applications in differents processes.
How could I start the server from the client to obtain a "standalone" application? The use of ProcessBuilder to call java.exe is a solution, but it has drawbacks: it will be OS dependant and cannot assure the server process will be shutdown / killed as the client leaves.
From the architecture point of view leave them separate is the best option, as you have a server and a client separate, it will be the behavior in a productive environment.
If you need it only during the development phase, and your reason to run both together is to save time, you can build both in containers using Docker. Basically create two applications, building from two different folders, and then you will start both together.
I found a solution in https://www.toptal.com/spring-boot/spring-boot-application-programmatic-launch . Igor Delac
opens the jar file containing the server to find the class ...loader.archive.JarFileArchive (and some other)
instanciates it and uses it to start the application on the jar itself.
The jar file is not extracted nor modified. Only a few classes are read.

Websphere Application Server : what is com.ibm.wsspi.bootstrap.WSPreLauncher

In IBM Websphere Application Server (WAS) what are the purpose of com.ibm.wsspi.bootstrap.WSPreLauncher and com.ibm.ws.bootstrap.WSLauncher? Every morning we are restarting the Websphere Application Server. So on the stat of WAS it will always be called to load applications war file? Or there are certain action on which these two are used by WAS?
WSPreLauncher and WSLauncher are main entry points in the starting the OSGi framework and server processes. If you look at startServer script, you'll see it invokes the WSLauncher class with a number of additional arguments that are essential to proper server startup. To your question, when using the serverStart script, WSLauncher will be called and as a part of starting all the components of the server, applications, including war files, may be started depending on your specific configuration. You should not invoke either the WSPreLauncher or WSLauncher entry points yourself and instead should use the provided scripts like startServer, startNode, etc.

Spring Boot executable JAR cannot open privileged port as systemd service

I'd like to run my Spring Boot application as a systemd service listening on port 443 directly (not behind nginx/httpd). To do this, I am specifying AmbientCapabilities=CAP_NET_BIND_SERVICE in the systemd service unit like so:
[Service]
User=myapp
ExecStart=/usr/lib/myapp.jar
SucessExitStatus=143
AmbientCapabilities=CAP_NET_BIND_SERVICE
However, the capability seems to be lost when the embedded launch script runs Java. As a test, I substituted my own one-line bash script java -jar /usr/lib/myapp.jar to see if the capability was lost when running any bash script, but that worked. So as far as I can tell, something in the embedded launch script is causing the problem.
With that said, I'm most likely going to drop the embedded launch script in favor of launching Java directly from the systemd service unit, but in case either (1) others have the same problem or (2) this is an actual bug and not just me missing something I did want to at least ask the question.
Cheers!

How to push and run a spring-batch application on Bluemix?

I have created a spring batch application in spring boot to perform a daily activity for processing data in batch. I am also able to build and create an uber-jar that has all the dependencies in it. How do I push this jar file as a batch application (not as a web application) and how do I invoke the application to start from the command line if possible?
For cloud foundry applications without the web interface, you can run them with:
---
...
no-route: true
This will disable the web interface - https://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html#no-route
You may also want to set the health check to process:
---
...
health-check-type: process
This will monitor the exit status of your application. Note that this will monitor the process your java process. If it stops (e.g. batch job application finishes), cloud foundry will try to restart it - https://docs.cloudfoundry.org/devguide/deploy-apps/healthchecks.html. This assumes that you want your application to run continuously.
You will probably want to check the java build pack for methods for running your jar - https://github.com/cloudfoundry/java-buildpack/blob/master/README.md.
I think you will want to deploy using the Java Main method, which runs Java applications with a main() method provided that they are packaged as self-executable JARs. Cloud foundry will automatically run the main() method.

If it possible to access AdminConfig in the Liberty Profile (non ND)

Is it possible to access AdminConfig.getid inside the WebSphere Liberty Profile (non ND), just pure Liberty profile, or even Base version?
Any particular jars needed?
The AdminConfig object is related to the wsadmin tool. According to IBM Documentation for wsadmin, it cannot be used with the Liberty profile. The wsadmin tool should be available with a full profile created under the Base version.
You can refer to this link for more information on using wsadmin. You can use the Java Management Extensions (JMX) framework to make use of the wsadmin objects using Java MBeans. Alternatively, you can use the Administration Thin Client to write your own standalone program to remotely connect to and manage WebSphere Application Servers.

Resources