Run Maven project on web server in the background - java

Problem
I have got a working Maven project that I would like to deploy on my web server. I have just discovered Maven and Java is not exactly the primary language I write my projects in, so please excuse any mistakes. When I run my project, a continuous HTTP connection is established and it should permanently run on the server (Basically Push Notifications based on made requests).
Further Information
The server is running on Amazon's Linux AMI.
Proposed Solution
I pack the whole Maven project into a .jar file and run it there.
Q1 How do I run the java file on a server (in the background) ?
Monitoring
Q2 How can I monitor which or how many processes are working in the background ? (I would NOT want the java file to run multiple times, thus PREVENTING it from establishing multiple connections)
Termination
Q3 How would I terminate any background processes, if needed (terminate the continuous http connection)?
Connected Questions
Run java jar file on a server as background process
EDIT
Possibly what I was looking for (I'll test it out and report back): https://serverfault.com/questions/152378/run-jar-in-background-on-linux

Related

How to run a Java jar consecutively?

I have 5 java jars in server "A" and a dozen of jars in other server "B". Now I need to run them consecutively. Say if 1 jar in server A has run complete, then 2 jars related to the jar 1 should start to run in server B. How to achieve this?
One option we have considered is to club related jars in one aws server and run through script detecting the jar completion through the log files, but is there any other efficient way to achieve the synchronisation through spring framework or by any other means?
I would look into having two "manager apps" on each server that can communicate with each other through sockets. Say manager app on server A detects jar 1 is completed, then it would send a message to manager app on server B with a command to run the jars related to the jar 1 on server A. To complete this I would look into Server Sockets and Sockets.

Connect to windows remote server using java and modify some files?

Hi I have been doing some manual tasks which consume some of my time and I want to automate it the tasks are:
Connecting to remote windows server using mstsc command and restarting some services.
Connecting to remote windows server and modifying the files, checking the modifications and then again reverting the changes when the changes are tested.
I want to know whether I can achieve a one click solution for this scenario by writing some code in java and reducing the manual time.
Or is there any other solution for the same which can be generic and could be implemented on other servers too.
The steps for the solution to cover would be:
Connect to remote machine using username and password.
Restarting the services from the code or just executing a batch file for the same which could be lying in some folder on the same machine.
Modifying some files on the remote machine.

How to check java application status (Running or stopped) running on a windows server

I have a java jar running on windows server 2012 r2. I have created a task to run this jar on every restart of the server. Now, I need to restart the application whenever its stopped because of some reason. So I should find a way to find the status of the application.
A typical way to handle problems of this sort is with a service wrapper application, of which there are many, each with particular features. Popular examples include
Tanuki, YAJSW, and Procrun, among others. These wrappers have built-in facilities to monitor and keep alive the applications they govern.
If you just want to check whether the application is running, then a common approach is to send probes to some TCP port that it exposes. Many applications open a port specifically for this purpose.

Java socket not connecting on some computers

I've been making a java SE application on another computer for couple of months with Netbeans. The application uses Javas sockets and connects to another application to the another computer (or to the same) through port 4444. The application connects on the first computer perfectly to another application: runned from netbeans, runned from command line and runned from a jar file.
Now I'm continuing the project on another computer. At first I tried to run the same source on this computers Netbeans debugger. Application starts, and it connects to another application, but it stops immediately. No error messages or exceptions. The screen doesn't freeze, but neither won't the applications start to communicate with each other.
I also tried to run the applications jar file from the command line. The same problem appears. It makes connection to another app, but nothing else happens.
Finally started the application from the jar file by doubleclicking it. Now it makes a connection and starts to communicate with another.
Firewall isn't blocking the application or netbeans. I've also tried to run netbeans with firewall down, but still no results. Java has been updated on both computers. For some reasons the application runs perfectly on some computers, and on others, it does this annoying thing.
It's possible that port 4444 is used by another application.
Check this by using the netstat utility.
Your application should be configurable. I.E. port 4444 shouldn't be hard coded.
Grab a stack trace from the running application. It will tell you where the program is "stuck".
You may also benefit from adding logging to your app. This will drop statements to a file or system out/err that you can use to identify its internal state. For example; when you write to a socket:
OutputStream os = socket.getOutputStream();
while (true) {
System.out.println("write loop:enter");
os.write("machine 1".getBytes());
System.out.println("write loop:exit");
}
Good luck.

Can ANT start restart jobs on remote servers?

Is it possible to have ANT restart your java application on a remote server from a build script? If so any pointers to where that might be defined?
I'm using ant now to push the new code over to the remote server but I still have to login to actually restart the app
Using the <sshexec> task you can do pretty much anything on a remote machine (assuming it's got an sshd running). If you don't want to worry about authenticating the ssh session every time, you can set up RSA keys.
<sshexec host="remotehost" username="remoteuser" command="/restart/application/command"/>
Heed the statement at the beginning of the above link:
This task depends on external libraries
You'll need to grab JCraft's JSch jar and put it on Ant's classpath.

Categories

Resources