aspose file tools*
The moose likes Linux / UNIX and the fly likes How to auto start a process when Linux starts or reboot? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "How to auto start a process when Linux starts or reboot? " Watch "How to auto start a process when Linux starts or reboot? " New topic
Author

How to auto start a process when Linux starts or reboot?

Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
I want to start Tomcat automatically when my Linux box powers on or reboots. Is there a way to do this? I use Mandrake Linux.
Thanks
Bruce
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

The /etc/fstab is like the Windows Startup Group. Just open that file and configure it. Better yet, write a shell script and run it in fstab. That way you can pass more parameters if you have to.


GenRocket - Experts at Building Test Data
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
Thanks Gregg.
I will check this out.
Bruce
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
It seems that /etc/fstab is all about various file systems. Is this really the place to add scripts for execution at boot time?
Thanks.
Bruce
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Sorry, I told you wrong the first time.
Since you'll probably want to start the Tomcat application server at boot time, rather than have to start it manually every time, I have included a simple script you can add to your run control environment, typically in the /etc/rc.d/init.d directory. (See Listing 4.) This script will start Tomcat as an unprivileged user (e.g., user name "nobody"). By putting this script in /etc/rc.d/init.d and creating a symbolic link such as "S97tomcat" to it in /etc/init.d/rc5.d, you can start Tomcat services at boot time, without their assuming root privileges. This configuration is for Red Hat 6.1. You should adjust as necessary to suit your flavor of UNIX.
Because Tomcat needs to know some things about its environment to run properly, you should also add the following environment variable settings to the startup.sh and shutdown.sh files called by the init script in Listing 4.

JAVA_HOME=/usr/java/jdk1.3
TOMCAT_HOME=/usr/local/jakarta-tomcat
CLASSPATH=.:$JAVA_HOME/lib/tools.jar
export JAVA_HOME TOMCAT_HOME CLASSPATH
Change the values of JAVA_HOME and TOMCAT_HOME to reflect your installation and place these lines in startup.sh and shutdown.sh before the lines that read:
BASEDIR=`dirname $0`
$BASEDIR/tomcat.sh start "$@"
This information was taken from:
http://www.samag.com/documents/s=1155/sam0101d/0101d.htm
Sorry for telling you wrong. Hope that helps
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666

By putting this script in /etc/rc.d/init.d and creating a symbolic link such as "S97tomcat" to it in /etc/init.d/rc5.d, you can start Tomcat services at boot time

How to create a symbolic link in rc5.d?
Thanks
Bruce
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

If I'm not mistaken, Mandrake is modelled on RedHat. The easiest way to get the different runlevel aliases (softlinks) to work in that case is to use the "/sbin/chkconfig" program:
/sbin/chkconfig --add tomcat3
/sbin/chkconfig --level 345 tomcat3 on
If you installed Tomcat from the RPM, the /etc/rc.d/init.d/tomcat3 (or tomcat4) script is automatically created for you.


Customer surveys are for companies who didn't pay proper attention to begin with.
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Hi Bruce - As Tim said 'chkconfig' is one good way to go. The start/stop/status script should be in /etc/sysconfig. Take a look at some of the samples there.
A less formal alternative is to use /etc/rc.d/rc.local. It is a script that runs at the very end of system initialization.
Regards, Guy
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
Thanks Tim and Guy:
Now I have heard 3 ways to do this:
1.put a script in init.d and a link in rc5.d
2.chkconfig
3.use /etc/rc.d/rc.local
which one should I choose? I want the easiest one but I don’t know which one is the easiest.
Thanks
Bruce
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
OK, just my opinion. 1 and 2 are related in that they depend on/use the symlink architecture to control what processes start at boot. Probably number 3 is easiest here. All you have to do is add to /etc/rc.d/rc.local:
#
# Set and export CATALINA_HOME
#
export CATALINA_HOME=/where/tomcat/lives
#
# Export CLASSPATH *if* you need to. You
# should not need to if TC is installed+
# configured properly.
#
# export CLASSPATH=whatever/you/need
#
# Source the TC startup script
#
. $CATALINA_HOME/bin/startup.sh

That having been said, I also think you should be familiar with 'chkconfig' and using 'service' to start/stop various daemons and subsystems. They are quite useful.
Regarding the 'symlink' concepts behind startup scripts, there is a pretty clear explanation in Aeleen Frisch's "Essential System Administration". Get a copy if you can. There are also probably good explanations out on the net.
Regards, Guy
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
Thanks Guy!
I will check these out.
It is very interesting to learn these Unix/Linux tricks. I have been on AS400 (now called iSeries) for 8 years and I have been playing with Linux for a few weeks and I really like it. I have a couple of Linux for dummies books and a RH Linux 7 Unleashed book. I may need to found a better book.
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Hi Bruce - Frisch's book is Unix System Administration - but 95% applies to Linux, and she discusses in detail where Linux differs from 'standard Unix' Whatever that is!
Later, Guy
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to auto start a process when Linux starts or reboot?