LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-04-2004, 10:24 AM   #1
bbresc512
LQ Newbie
 
Registered: Apr 2004
Posts: 10

Rep: Reputation: 0
Deploying Java program


Hi all,
I have a Java program that is an HTTP server.
Is there any way to deploy this program as a deamon? I mean, I know that it's possible to run this program on start up, but then I will still be needing a set of stop/start commands to handle this program.
Or may be a different question... Can this program be built as a service? , something like:
"service HTTPprogram stop/start".

I'm desperate. Can someone help?

Thanks in advance.
 
Old 05-04-2004, 11:29 AM   #2
aaa
LQ Guru
 
Registered: Jul 2003
Location: VA
Distribution: Slack 10.1
Posts: 2,194

Rep: Reputation: 47
Starting should be easy (just run it, maybe with an '&'). The tricky part would be stopping it. I'm thinking maybe you can run another java program that can communicate with it and tell it to stop?

Edit: see this:
http://www.javaworld.com/javaworld/j...-0324-ipc.html

Last edited by aaa; 05-04-2004 at 11:41 AM.
 
Old 05-04-2004, 11:48 AM   #3
bbresc512
LQ Newbie
 
Registered: Apr 2004
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by aaa
Starting should be easy (just run it, maybe with an '&'). The tricky part would be stopping it. I'm thinking maybe you can run another java program that can communicate with it and tell it to stop?

Edit: see this:
http://www.javaworld.com/javaworld/j...-0324-ipc.html
Thanks for the prompt reply,

Starting....
sorry, I'm new to linux. What you mean by '&'.
How can I start the program if not by command line? I mean I don't want a terminal session to by hanged by an HTTP server. I thought about cron, but it doesn't look good to me. I've read something about the batch command, but it was mentioned that the batch process not always gets the CPU, or something like this, I'm still learning it.

Stopping...
How people write service programs? I know I can write a service program in Windows.

Thanks again
 
Old 05-04-2004, 11:52 AM   #4
aaa
LQ Guru
 
Registered: Jul 2003
Location: VA
Distribution: Slack 10.1
Posts: 2,194

Rep: Reputation: 47
To run any program in the background, you use the '&':
java FTPServer &
 
Old 05-04-2004, 12:47 PM   #5
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
The way I've done it before, on slackware at least is to have a script that actually starts the program like

exec java blah...blah

Then immediately saved the process id of the process to a file using the bash built in variable that stores the id of the last process run. You can then use a normal case selection script to start/stop it using the pid held in the file to stop it. In slack you can then bump the startup script into /etc/rc.d and add an appropriate entry to /etc/rc.d/rc.M

It isn't too difficult at all and someone could probably bash you out a framework in no time at all, unfortunately I'm linux'less for the foreseeable future at the moment else I'd help out a bit more
 
Old 05-04-2004, 03:06 PM   #6
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 52
you can look at examples provided in you /etc/rc.d/
you need to allow a random number for your java server process number and deal with conditions and arguments start stop restart.
 
Old 05-04-2004, 06:06 PM   #7
bbresc512
LQ Newbie
 
Registered: Apr 2004
Posts: 10

Original Poster
Rep: Reputation: 0
Please kindly clarify what you mean by "allowing a random number for java server porcess" and " deal with conditions and arguments start stop restart"?
I've just ask about the '&' sign
But I'm a very quick learner with about 9 years of programming experience. I need a starting point here, so I can concentrate my efforts in the right direction.
Could you please provide an example from the /etc/rc.d explaining the above?
Parameters to what? To my Java program? It can't be it, right?
 
Old 05-04-2004, 06:16 PM   #8
bbresc512
LQ Newbie
 
Registered: Apr 2004
Posts: 10

Original Poster
Rep: Reputation: 0
"aaa" "Looking_Lost", thanks for you replies.

I'm certainly in a better position now. I personally prefer the aaa's suggestion about using another program, than killing the process. After all it's an HTTP server, so I can send a termination HTTP request to the local host.

But I'm still wondering. Where did that come from:?

service vsftpd stop/start/restart

Obviously it is possible to write a socket service. May be "mrcheeks" can shed some light on this ?
 
Old 05-05-2004, 07:13 AM   #9
aaa
LQ Guru
 
Registered: Jul 2003
Location: VA
Distribution: Slack 10.1
Posts: 2,194

Rep: Reputation: 47
I suggest you use a combination of a socket and lockfile to do this. Modify your server so it shuts down when a certain signal is sent over the network (listen on a certain port, for anything?). Then, after receiving the signal, it checks the lockfile (any file you want) to see if the request was from on that computer. Then you can make a program or just a script to a) remove/modify the lockfile, and b) then contact the server via the network to tell it to shut down.

I think 'service' (it's a script) just runs scripts in /etc/init.d/ . I'm guessing if you just make a script that takes 'start' or 'stop' as a parameter and put it in /etc/init.d , you will get the behavior you want. Take a look at the scripts already in /etc/init.d for how to do this.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deploying PHP on Jboss ???? markwaugh Linux - General 0 07-12-2005 08:48 AM
Deploying Linux builds sorvad Linux - General 1 01-31-2005 07:27 AM
deploying a web app poeta_boy Programming 5 12-09-2004 09:50 AM
Stop java program(threaded program..should end cleanly) rmanocha Programming 4 11-09-2004 09:36 AM
deploying linux in corporate rehabkhaled Linux - General 1 08-05-2003 07:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration