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 01-19-2007, 01:50 AM   #1
dsubbarao
LQ Newbie
 
Registered: Jan 2007
Distribution: Redhat
Posts: 14

Rep: Reputation: 0
java program as daemon


Hi All,

I want to run one java program as a daemon on linux.
(That java program is the 3rd party one so i can not modify the source. I have created a jar file with manifest file specifying the main class.so now i am able to run the program form jar with the command java -jar ex.jar.Now i want to make it a daemon so that i can stop and start and restart)

Can any body tell me what is the procedure to install the java program as daemon .so that i can restart it also?

Thanks in Advance
 
Old 01-19-2007, 04:10 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,649

Rep: Reputation: 391Reputation: 391Reputation: 391Reputation: 391
What kind of program is yours ?
 
Old 01-20-2007, 04:05 AM   #3
dsubbarao
LQ Newbie
 
Registered: Jan 2007
Distribution: Redhat
Posts: 14

Original Poster
Rep: Reputation: 0
It is part of my application.It doesn't have anything to do with any ports and all.....It is just pure normal java program which must be executing after it has been installed.(When it starts it searches for any changes for rules those are made by application and keeps log of it.)


Thanks in Advance
 
Old 01-20-2007, 05:33 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,649

Rep: Reputation: 391Reputation: 391Reputation: 391Reputation: 391
If your program doesn't make use of its standard input nor use graphics (AWT / Swing), then you can launch it as a service.

The way to do it depends on what your distro is. For examples, the System V way is creating a stop/start script in /etc/init.d then create lints to it in the appropriate run levels directories (eg. /etc/rc2.d/S99myJavaDaemon).
 
Old 01-21-2007, 05:51 AM   #5
dsubbarao
LQ Newbie
 
Registered: Jan 2007
Distribution: Redhat
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks for the reply.

I am using redhat.I have written the rcscripts for my java program.
I am able to start the service .But I am not able to stop the service.How to stop the service ?? What i had read is i have to create the pid in /var/run directory and we have to give command "kill pid" but i am not able to stop the service ..
I don't have special code to stop the java program.

Can u tell me indetail how to create the pid or the way to stop the service..

I am giving u my rc script:

#!/bin/sh
# chkconfig: 2345 16 84
# description: RulesEngine
# processname: re
# Source function library.
. /etc/rc.d/init.d/functions

prog=re
pidFile="/var/run/re/re.pid"

RETVAL=0


start() {
echo -n $"Starting RE: "
cd root
source .bshrc

local filename="$pidFile"
touch $filename || return 1

chmod g+w $filename || return 1

cd /root/workrpm/usr/share/GRE/
java -jar relight.jar
return $RETVAL
}

stop() {
local pid="$(<$pidFile)"
echo $pid
kill $pid || return 1

}
restart(){
stop
sleep 2
start
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

exit $RETVAL


Thanks in Advance.
 
Old 01-21-2007, 07:03 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,649

Rep: Reputation: 391Reputation: 391Reputation: 391Reputation: 391
Try something like
Code:
pkill -f "java -jar relight.jar"
 
Old 01-22-2007, 12:29 AM   #7
dsubbarao
LQ Newbie
 
Registered: Jan 2007
Distribution: Redhat
Posts: 14

Original Poster
Rep: Reputation: 0
Smile HI jlliagre

Hi jlliagre

Thanks very much..It did work like a charm..

You have made my day...


Thanks once again.
 
Old 01-22-2007, 01:16 AM   #8
dsubbarao
LQ Newbie
 
Registered: Jan 2007
Distribution: Redhat
Posts: 14

Original Poster
Rep: Reputation: 0
HI

But without creating the pid file is there any way to find out the service is started or not???

Thanks in Advance?
 
Old 01-22-2007, 01:49 AM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,649

Rep: Reputation: 391Reputation: 391Reputation: 391Reputation: 391
Sure:
Code:
pgrep -f "java -jar relight.jar"
 
Old 03-02-2007, 12:17 AM   #10
creativemadhan
LQ Newbie
 
Registered: Jul 2006
Posts: 4

Rep: Reputation: 0
Hi,
I am new to scripts, so can u guys tell me whether a jar file and script file without any pid file is enough for creating a service...

Last edited by creativemadhan; 03-02-2007 at 04:20 AM.
 
  


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
Run program in daemon mode gubak Linux - General 3 06-20-2005 02:23 AM
how to run a program as a daemon? iclinux Linux - Newbie 2 04-20-2005 01:11 AM
Forcing Java to use another sound daemon bongwater Mandriva 0 10-31-2004 03:02 AM
show me how to write a daemon program? shrike_912 Programming 2 06-04-2004 02:28 PM
How To Program Daemon(Service) Application wlmapp3 Programming 6 07-23-2003 04:58 PM


All times are GMT -5. The time now is 06:53 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration