aspose file tools*
The moose likes Linux / UNIX and the fly likes java program run as daemon/service in Linux? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "java program run as daemon/service in Linux?" Watch "java program run as daemon/service in Linux?" New topic
Author

java program run as daemon/service in Linux?

Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

I tried to find out topic in Google. Lots of Links i got to read regarding this but all related to web application.
My scenario is:-
1. I have Centos with 5 services
1. DRBD
2. Heartbeat
3. Dahdi
4. Asterisk
5. Mysql
2. I have jar file which use as swing application for use these 5 services. It has Swing, Networking, MultiThreading, Database handling etc.
3. Till DRBD disk not up Asterisk & Mysql service not start.

Now i want to do:
When pc starts its service step by step start then login screen comes, i will not log in but my java program should start as other service start.

Now for that as per my understanding i should separate Swing & rest of other things.
I done that also( I create 2 different java ) but i dont know which API i should use or whom i should follow?
Can anybody tell me from where i should get info how actually it work? Is JVM start before login screen comes in linux?
I found question-answer related to this.
Similar to this i found another one.
But it all how to do...not how it work. In any book/forum/blog etc where i find this?
Help me.



Millions saw the apple fall, but Newton asked why.
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 495
    
    5
Is the application's backend code amenable to running autonomously without a user interface and without any kind of user actions?
Can all the backend logic (database, network communication to asterisk, etc) be started and managed without any user actions?
Is there tight coupling between the swing front end and the backend code, or is there enough separation (for example, via interfaces, MVC design, etc)?

If the backend is amenable to running autonomously, then it's not difficult to set it up as a CentOS service. But before setting it up that way, the above questions should have answers.

Now, suppose all this is possible and it is deployed as a service. The question is should the swing application also be redesigned?
This depends on the expected behaviour of the application, and you know that best:

1. One possible deployment is: the service runs autonomously doing its networking+database thing, and the swing application also runs as it is, without any
changes. That is it still has its own backend also doing the networking+database thing. Will this be a problem? Any kind of data conflicts, etc?
If it is currently possible to run multiple instances of the swing application simultaneously without any conflicts or other issues, then this solution
is feasible. It'll be less effort than the next possibility.

2. Other possibility is: the service runs autonomously doing its networking+database thing. The swing code is redesigned to cut out all the backend logic (
which is now moved to service) and turned into a pure front end thin client to the service, which now becomes its server. The thin client can talk to the server
service via RPC technologies like RMI, sockets, web services, etc. This redesign may or may not be trivial; it depends on the earlier questions of how
amenable the backend is to separation, and nature of coupling between frontend and backend?

Analyze your application with these points in mind, and accordingly decide.
Once the application itself has been redesigned correctly, deploying the backend logic as a CentOS service is very simple.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

It would be simpler if the program in question wasn't Swing-based.

Linux operates at serveral different runlevels. Runlevel 0/S is halted, Runlevel 1 is single-user, Runlevel 2 isn't commonly used, Runlevel 3 has networking (lower levels do not), runlevel 4 or 5 has X Windows (GUI).

So to even begin to safely launch a GUI-based program you'd need to run it at runlevel 4 or higher.

Beyond that, systems services in Linux are not GUI apps. By definition, a daemon is a continuously-operating non-interactive program in the background. It may be paired with GUI apps that monitor, control, and otherwise interface with it, but the daemon itself does not directly interact with the user by GUI or command-line input.

And, no, an X app cannot run when a user is not logged in. The Display environment is on a per-user basis.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java program run as daemon/service in Linux?