I am using Apache-Solr for indexing and searching in my java application.
If want to perform any operation related to Apache-Solr then the solr server is must to be started.
Sometime the terminal in which Solr-server is running is closed accidentally then we have to start that server again, because we can not perform any Search/Index related operation.
I tried to run process in background by putting '&' at end of the command, but it does not working.
I do not want to that terminal is opened in which server is running. So is there any way to run the Apache-Solr-Server in background process?
Thanks in advance..
i think this link will be useful for you it talks about how to use screen if you are using linux and other stuff
start apache-solr-server in background
also you may start
Solr automatically by creating an init/LaunchDaemon script and let the
system handle running it.
Related
I have a process running using Systemctl, configured it with Restart=always
so that even if process crashes then it will restart by itself without manual intervention. When that process restarts I want to take some action in my java code. I don't want poll the process. is there anyway to achieve this?
Thanks in advance.
systemd has a D-Bus API that you can use to receive event notifications when a unit changes state, including changes to its ActiveState property that tells you whether it's currently running. See this answer on Unix & Linux StackExchange for more information.
To use this API from a Java program, you'll need a D-Bus library for Java. It looks like there's a DBus-Java library, though it hasn't been updated in a long time. Alternatively, you might be able to have your Java program invoke the command-line dbus-send and/or dbus-monitor programs and read their output.
I am trying to run infinitely a program that monitors a logfile and updates to the database the errors that have occured and keeping track of a max number of occurances for some error so to send an email if one error is occuring too many times. I managed to do the programme that listens and updates appropriately and sends the email but I don't know how I am gonna be able to start off the programm to run infinitely as it will be monitoring a live system. On the other hand I have a web UI that displays the info updated by the monitoring programme, in other words I don't want the updating programme to stop running even when I my web UI is closed in the browser, behind the scenes I want updating programme to continue to run. I want to separate them so they run independent of each other. I am using Servlets and JSPs for my front end. I was thinking of starting the updating programme in my servlet but I am thinking when it is closed the updating programme will stop run which is what I am trying to avoid. Any kind of advice is highly appreciated, any tool available that allows running a programme infinetely and only stops when server is down and thanks in advance.
NB: I wanted to use log4j to append errors to database to allow me easier
updating but the system wasn't designed to accommodate my requirements so
I have no choice but to use this approach.
Assuming that the Web UI displays information retrieved from the database and if you want to separate out the web UI from the monitoring program, I would suggest keeping a separate native Java process running that constantly monitors the log file and updates the database. The database will be used as a communication medium between the two Web UI and the Java process.
That way the Java process will remain independent of the Web UI and can run indefinitely.
Think it this way -
1. Java process updates the database as it monitors the log file
2. The Web UI reading from database whenever it is up.
The Java process can probably also communicate with Web UI service to provide some heart beat to acknowledge that it's up.
Hope this helps.
I have a simple java program which is just a single piece of code that reads from a database and modifies the contents of the database based on certain conditions. Now, what I want is that this program should start automatically at the startup and silently run in the background unless someone kills it from the task manager.
I have never done something like this before and don't know exactly how to go about it. Can someone help me out as to how this can be done?
Thank you..
Follow the these steps to do the job :(Assuming you are using windows and jre is installed )
First compile your java program and place the class file at one location.
Now create a bat file and place java LOCATION TO THAT CLASS FILE/MyProgram in that.
Put your bat file in start up programs
Restart the system, you will get your program running in back ground..!
Hope this will help you.
There are two problems here
How to add this program to the startup
Windows - Run Java application at Windows startup
Linux - Linux start-up script for java application
Run the program as a daemon (background process)
Simplest way to do is using a while loop and sleep for required time interval in the while loop. Then perform the database
operation.
Also for windows, you can check this JSL
http://www.roeschter.com/
Thanks.
first create you jar bash and then add it to you crontab task list.
I have an application which has a purpose to run when the user first runs their computer.
However, I'd like to make a check box on the app that enables/disables the application loading when the system is started. Is there any way to do this?
Thanks
I recommend you to create a service under windows. My suggestion is http://winrun4j.sourceforge.net/
This question has been discussed in SO time ago:
Code for Auto starting a java application on windows startup
Auto startup for java desktop application?
However, maybe the easier solution is to create a batch file,like suggested in the first link, to run your application as the user logs in.
If you want to enable/disable the startup through a checkbox, the first and simplest solution that comes to my mind is this: you can make a method, invoked by the checkbox listener, that edits the batch file and enables/disables the line used to run the application, in the batch file.
If you have Windows 7, read this tutorial.
I have a java application where I want to check to see if an application is running. If it is not running, I want to start it. If it is running, I want to kill it and then restart it.
Can someone tell me how to do this? I can start/stop the program easily enough, with the ProcessBuilder. But I cannot detect a process that is already running.
Thanks for your help!
John
Without the cooperation of the application (ideally have it listening on a network port), that may be impossible (your Java app might not have the rights to kill the app) and requires OS-specific code. On Linux, you'd uase the ps and kill commands.
Might sound silly, but you can create a file with a known name on application startup. Doesn't need to contain anything. To check if your application is running, check if that file exists.
Is the other application (the process you are monitoring) under your responsibility? If so, you can use a method I used in some high-availability system a few years back:
Open a connection to that other application and "ping" it. If the other application does not respond within a given timeout, it is either down or "hung", which is as bad (and something you can't detect through process monitoring.
Opening a connection can be done using sockets, or though more sophisticated protocols (SOAP?).
An alternative is to have the application send a "I'm alive" message every so often. If you haven't received it in some time - your application needs restarting.
In order to actually "kill" the other process, you can keep the Process instance you get from the exec() method, and destroy() it when you so choose.
Thanks for the replies. That was what I was afraid off. We are trying NOT to add more things to the application that I want to start up. We are basically trying to add a remote control web interface to a collection of applications.
The web server application that I am writing would basically start/stop 3 apps that all talk to each other to achieve a goal. If my web server starts and stops them, all is well. But if, for some reason they are already running when I try to start them bad things happen.
It is something I know I could handle with Visual Studio (C++/C#/etc). But this project has to be written in java due to a platform independence requirement.
Thanks for your help everyone!