Run java as a linux service

A

Alessio

Hi,
i must run a MyjavaApplication as a linux service, someone can help me?
alessio
 
E

Erwin Moller

Alessio said:
Hi,
i must run a MyjavaApplication as a linux service, someone can help me?
alessio

Just make a startupscript and shutdownscript and put it in
/etc/rc.d/rc5.d

That is for Redhat runlevel5, which I run.
If you run another Linux-distro I guess you'll find an other appropriate
place.

In the script just run your program as you always do, like this:
java yourApp

Maybe remember the PID and store it somewhere, I am not sure how you want to
set it up.

To shutdown your program you need the PID to send it a kill-signal.

Use S55yourjavaapp and K55yourjavaapp as scriptsnames where S stands for
Startup and K for kill.
The numbers are executed in order.
So if you want your java-app to start late, use number 99, or another one
that is free.

Good luck.

Regards,
Erwin
 
G

Gordon Beaton

i must run a MyjavaApplication as a linux service, someone can help
me?

If you mean that you want to put it in the background so that it will
stay there after you've logged out, then run it like this:

nohup java MyjavaApplication < /dev/null > /dev/null 2>&1 &

If you want to save its output, change the second "/dev/null" in the
example to the name of a suitable logfile.

If you meant something else, be more specific.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top