tags:

views:

520

answers:

4

Hi I am using 64bit Fedora 10 linux. I have created a sample java application. Now I want to write init script for that application. so that my application should start on bootup.

How to write init script to start on bootup.

Thanks Sunil Kumar Sahoo

+2  A: 

There's quite a good guide here:

http://developer.novell.com/wiki/index.php/Writing_Init_Scripts

I'd suggest taking a look at the tomcat startup.sh and shutdown.sh scripts, and then modifying the following init.d script:

#!/bin/bash
#
# tomcat
#
# chkconfig:
# description:  Start up the Tomcat servlet engine.

# Source function library.
. /etc/init.d/functions


RETVAL=$?
CATALINA_HOME="/usr/apps/apache/tomcat/jakarta-tomcat-4.0.4"

case "$1" in
 start)
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
      echo $"Starting Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/startup.sh
        fi
  ;;
 stop)
        if [ -f $CATALINA_HOME/bin/shutdown.sh ];
          then
      echo $"Stopping Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/shutdown.sh
        fi
  ;;
 *)
  echo $"Usage: $0 {start|stop}"
  exit 1
  ;;
esac
brianegge
+2  A: 

I usually just take one of the smaller init scripts from /etc/init.d and modify it.

Edit

The easiest thing to do is just add your program to the /etc/rc.local file. It will be the last start script executed. You won't have to mess around with the "start" and "stop" stuff.

However, if you're interested in being able to start and stop your program at will, you'll need to write a script.

Some of the other answers here will get you started.

Barry Brown
Hi Barry, can u please tell me which script file i will take and modify. I donot know which one is smaller one.
Deepak
To be fair, running stuff out of rc.local is more than a little hacky and really bad form for anything beyond your own local "just get it working right now" needs. If you're ever going to distribute it to anything (including a testing or production environment) you should really have an init script.
Ophidian
You're 100% right. But the OP didn't indicate whether his app is one for his own use or something he's going to distribute.
Barry Brown
+2  A: 

Many distributions come with a skeleton script you can use as a template for your own init script, in /etc/init.d/skeleton or /etc/init.d/skel.

caf
+1  A: 

Some of the best java applications that I have seen tend to use the tanuki wrapper for this.

It standardises startup scripts across different OS's, i.e. can be used to configure a *nix daemon or a windows service.

It provides a standard command line interface for stopping, starting, restarting and checking the status - running or not.

I appreciate seeing it used more and more, as I don't have to learn it again, learn it once and reuse it again and again.

By using this service library, your application can benefit from future enhancements.

crowne
+1 for the link
neuro