| Author |
How to auto start a process when Linux starts or reboot?
|
Bruce Jin
Ranch Hand
Joined: Sep 20, 2001
Posts: 664
|
|
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
Sheriff
Joined: Jul 11, 2001
Posts: 15040
|
|
|
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.
|
My Blog | DZone Articles
|
 |
Bruce Jin
Ranch Hand
Joined: Sep 20, 2001
Posts: 664
|
|
Thanks Gregg. I will check this out. Bruce
|
 |
Bruce Jin
Ranch Hand
Joined: Sep 20, 2001
Posts: 664
|
|
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
Sheriff
Joined: Jul 11, 2001
Posts: 15040
|
|
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: 664
|
|
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: 12510
|
|
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.
|
One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
|
 |
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: 664
|
|
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: 664
|
|
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
|
 |
 |
|
|
subject: How to auto start a process when Linux starts or reboot?
|
|
|