HOWTO Run a java chatserver application as a service under LINUX


I have managed to create a chat server java application. It works fine, when i start it on the command line. However, when i close my ssh session it closes down ofcourse. I would like
to have this program running forever ( as a service or something else ) and dont want to stay logged in all the time.

Is there an easy way to do this ? I'm average experienced on windows platforms but am a novice on LINUX.

Hope someone can point me out or refer me to a tutorial that covers this clearly.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try to start it by using: java <your class> &
Alternatively you can put the above command on your .bashrc or .bash_profile and have it start automatically upon computer/shell start up.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

marcel42Author Commented:
Ok thanks, do you know how to close down this service again ? Just kill it with the kill command ? Or is there a cleaner method ?

Is a wrapper to allow your application to run as either a Windows service, or a UNIX Daemon :-)

> Ok thanks, do you know how to close down this service again ? Just kill
> it with the kill command ? Or is there a cleaner method ?

How do you stop it normally?

Kill would do. Alternatively you could write a script that sends a signal to it in order to stop, something similar to how the Tomcat start/stop is done.
u can search for the Java proccess and kill it by the Id
>  Try to start it by using: java <your class> &

This would still be killed when you logged out (I think)

A more stable version of this would be:

nohup java yourclass & > /tmp/nohup.out

the "nohup" tells the process no to die when you log off (and it gets sent a SIG_INT command to shut down)

I *think* ;-)
Also, I don't think .bashrc is read until you log in, so I am not sure that the process would start when the computer powered up...

(Oh, and SIG_INT in my previous comment should be SIG_HUP obviously) ;-)

Basically, you will either want to write a script to put in /etc/rc.d/init.d/ to allow /sbin/service to start, stop and restart your service, or use that wrapper from tanukisoftware (which is probably easier to use -- init.d scripts make my brain melt sometimes :-(
I think you are right about the "nohup"
Tim's last comments are the ones you need
zzynxSoftware engineerCommented:
Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.