Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application under Linux Service 1

Status
Not open for further replies.

Toyman

Programmer
Jun 19, 2001
68
0
0
GB
Hi

I've written an Application (Server) that will run as a service under Linux. I've created the service script and all seems OK. The only problem is that when I execute the java command within the script, It doesn't return because the application is running under the VM.

So the question is. How do I create an Application that runs under the VM, after it exits. (mmm this doesn't make sence). But I'm sure there is someone that know what I'm trying to do.

Toyman
VB / Java Programmer
 
Not sure about what you're trying to do, but I think you'll need to launch a child process.

Cheers,

Dian
 
I think you're asking: "How can I get my call to the 'main' method to exit immediately, leaving my server running inside the JVM?". I don't think you can. You'll have to use the native 'process fork' on whatever platform you're using.

I've used a service wrapper for this with success. Check out //wrapper.tanukisoftware.org

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
... damn, missed off the http [smile]...


I've checked and it does support Linux.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
A bit hacky :

Or when you kick off your app, add the "&" to the end of the command which will run in the JVM process in the background :

Code:
java MyServer & > /var/log/MyServer.log 2>&1

That also redirects stdout and stderr to the MyServer.log (make sure the user can actually write to /var/log)

--------------------------------------------------
Free Database Connection Pooling Software
 
Hi sedj

Yes you were right !!!! & did the trick.....
Thanks... easy solution to the problem ...
All working fine now !!!!!!!

Thanks all for your replies !!!!!

Toyman
VB / Java Programmer
 
That's okay as far as it goes. The service wrapper I mentioned will allow your application to be auto-started when the machine is rebooted. It also copes with application failure and can be configured to automatically attempt restarts of the app in such an event.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
I was going to suggest sedj's idea...

As for:
The service wrapper I mentioned will allow your application to be auto-started when the machine is rebooted.

That is easy enough... make a link to the script in init.d, and links to that link in the rc directories for the level you want to start it at.

It also copes with application failure and can be configured to automatically attempt restarts of the app in such an event.
While a neat feature, I don't think it's worth the extra bloat for most applications. I, personally, generally want to know when a service goes down, figgure out WHY it went down, and fix the problem before even thinking of restarting the service.

[plug=shameless]
[/plug]
 
jstreich, your points are good ones...

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top