ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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".
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?
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?
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.
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
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.
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?
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 ?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.