LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-18-2008, 10:59 AM   #1
fireball003
Member
 
Registered: Apr 2005
Location: Bangladesh
Distribution: Soalris10 , Slackware11
Posts: 54

Rep: Reputation: 15
run a java application (server) as service


Hi,
I want to run my own written java server application in selinux. I want to run it forever as long as the server runs. I am using ssh. Now how can I do it?

Say like adding my program as a service like so that it will not be closed when I will close ssh.

Please suggest me how i can do it.

Thanks in advance.
 
Old 07-18-2008, 12:25 PM   #2
Clemente
Member
 
Registered: Aug 2003
Distribution: Debian, Ubuntu
Posts: 188

Rep: Reputation: 30
Hi,

just a quick shot (I never did java programs as services outside of tomcat, jboss or similar).

You can daemonize any program using the "daemon" program. You might want to take a look at "man daemon".

Greet-o-mente
 
Old 07-19-2008, 07:54 PM   #3
fireball003
Member
 
Registered: Apr 2005
Location: Bangladesh
Distribution: Soalris10 , Slackware11
Posts: 54

Original Poster
Rep: Reputation: 15
Hi,
Thanks a lot for your help.

I was thoroughly checking deamon and how to work witht hat. But it seems rather complex to me. Is there any way to do that using script?

I just need to start my java application now.
 
Old 07-19-2008, 08:36 PM   #4
Clemente
Member
 
Registered: Aug 2003
Distribution: Debian, Ubuntu
Posts: 188

Rep: Reputation: 30
Hi,

in fact, daemon is not so complex. I will give some examples - the "normal" program, I want to daemonize, is a ping on localhost:
Code:
ping localhost
To run it as daemon, I write:
Code:
daemon -- ping localhost
To check that my ping does really run, I look at the output of ps:
Code:
clemens@hammerhai : ~ : 03:25
>ps faux | grep ping
clemens  11508  0.0  0.0   3400   472 ?        Ss   03:23   0:00 daemon -- ping localhost
clemens  11509  0.0  0.0   1916   668 ?        S    03:23   0:00  \_ ping localhost
It runs - and will keep on running, if I log of. Only way to stop it - at least the only way, I know - is:
Code:
kill 11508
.

To get more control, I can name my daemon:
Code:
daemon --name="mydaemon" -- ping localhost
Using this name, I can stop and restart it as follows:
Code:
daemon --name="mydaemon" --stop -- ping localhost
daemon --name="mydaemon" --restart -- ping localhost
To get any output from my daemon, I can set an output file:
Code:
daemon --name="mydaemon" --output=/tmp/mydaemon.output -- ping localhost
To check what happens, I do look into my output file:
Code:
 
clemens@hammerhai : ~ : 03:32
>cat /tmp/mydaemon.output 
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.025 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.028 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.028 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.027 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.027 ms
64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.028 ms
64 bytes from localhost (127.0.0.1): icmp_seq=7 ttl=64 time=0.028 ms
64 bytes from localhost (127.0.0.1): icmp_seq=8 ttl=64 time=0.033 ms
And I don't forget to stop my daemon as shown above.

To run your java program, you can change the "ping localhost" to the comand, you use to start your application.

I hope, this one helps a little bit,
Greet-o-mente
 
1 members found this post helpful.
Old 07-21-2008, 06:38 PM   #5
fireball003
Member
 
Registered: Apr 2005
Location: Bangladesh
Distribution: Soalris10 , Slackware11
Posts: 54

Original Poster
Rep: Reputation: 15
Hi,
You are great! Thanks a lot for your help! I really appreciate it

However i tried whole day to find out the daemon program you have used and failed. In fact what i found is- daemon is a function rather than a program. Also i tried start-stop-daemon command that other people recommended atv that also didnt work in my system. Both of those commands are unavailable in bash.

Please tell me which program it is or where i can download it from.

Thank you.
 
Old 07-21-2008, 07:03 PM   #6
Clemente
Member
 
Registered: Aug 2003
Distribution: Debian, Ubuntu
Posts: 188

Rep: Reputation: 30
Hi,

there is propably any system function called daemon, but the "daemon" I use is a program.
I took it for granted in the distributions I use - but I did some investigations. ;-)

Using Ubuntu, daemon is packaged in a package called - tataa - daemon. You can install it with
Code:
apt-get install daemon
I assume, that most distribution maintain a similar package, too.

What system/distribution do you use?

The daemon's homepage is located here: http://libslack.org/daemon/

There, you can find sourceballs and some documentation.
 
Old 07-21-2008, 09:49 PM   #7
fireball003
Member
 
Registered: Apr 2005
Location: Bangladesh
Distribution: Soalris10 , Slackware11
Posts: 54

Original Poster
Rep: Reputation: 15
It works!! Ah... After sevral days of searching I was becoming hopeless... you are the solver of this problem
You are awesome! Thank you man!! Thanks a lot!!

I have installed daemon rpm version from http://libslack.org/daemon/ and without any problem the system started working.

Best regards.
 
Old 07-22-2008, 05:02 AM   #8
Clemente
Member
 
Registered: Aug 2003
Distribution: Debian, Ubuntu
Posts: 188

Rep: Reputation: 30
Was a pleasure. Nice to read you succeeded!

Greet-O-mente
 
Old 04-08-2009, 06:05 AM   #9
mihir123
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
Start - stop daemon

Can this daemon be run as start - stop daemon???

It means that it should automatically start when linux / solaris boots up (i.e during startup).....and stops during shutdown....

Please reply as soon as possible......
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Unable To Get Java Application To Run on Debian carlosinfl Debian 2 04-11-2008 05:31 PM
Java Application Server and Studio Creator dougnc Linux - General 14 11-25-2006 10:51 AM
Need help choosing Java application server. z-vet *BSD 2 07-13-2006 04:44 PM
Looking for hosting service that will allow me to run a Jabber server scavenge General 0 06-08-2006 10:57 AM
LXer: Sun Microsystems Introduces NetBeans Profiler Milestone 11 for Optimized Java Application Run-Time Monitoring LXer Syndicated Linux News 0 12-23-2005 05:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:12 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