如何实现程序自启动

如何实现程序自启动

怎样配置一个程序在系统启动的时候自己执行?希望能说的详细一点.
我刚学linux不久,谢谢大家的帮忙!!!      
很难说详细 自己查查资料的好      
看看这些资料就能明白了

[0 N0.1936 huan ~ ]$ cat /etc/init.d/README
        Configuration of System V init under Debian GNU/Linux

Most Unix versions have a file here that describes how the scripts
in this directory work, and how the links in the /etc/rc?.d/ directories
influence system startup/shutdown.

For Debian, this information is contained in the policy manual, chapter
"System run levels and init.d scripts".  The Debian Policy Manual is
available at:

    http://www.debian.org/doc/debian-policy/#contents

The Debian Policy Manual is also available in the Debian package
"debian-policy".  When this package is installed, the policy manual can be
found in directory /usr/share/doc/debian-policy. If you have a browser
installed you can probably read it at

    file://localhost/usr/share/doc/debian-policy/

Some more detailed information can also be found in the files in the
/usr/share/doc/sysv-rc directory.

Debian Policy dictates that /etc/init.d/*.sh scripts must work properly
when sourced.  The following additional rules apply:

* /etc/init.d/*.sh scripts may not rely for their correct functioning
  on their being sourced rather than executed.  That is, they must work
  properly when executed too. They must include "#!/bin/sh" at the top.

* /etc/init.d/*.sh scripts must conform to the rules for sh scripts as
  spelled out in the Debian policy section entitled "Scripts" (§10.4).



[0 N0.1937 huan ~ ]$ zcat /usr/share/doc/sysv-rc/README.runlevels.gz

                Order of scripts run in /etc/rc?.d
                ==================================

0. Overview.

   All scripts executed by the init system are located in /etc/init.d.
   The directories /etc/rc?.d (? = S, 0 .. 6) contain relative links to
   those scripts. These links are named S<2-digit-number><original-name>
   or K<2-digit-number><original-name>.

   If a scripts has the ".sh" suffix it is a bourne shell script and
   MAY be handled in an optimized manner. The behaviour of executing the
   script in an optimized way will not differ in any way from it being
   forked and executed in the regular way.

   The following runlevels are defined:

   N       System bootup (NONE).
   S       Single user mode (not to be switched to directly)
   0       halt
   1       single user mode
   2 .. 5  multi user mode
   6       reboot

1. Boot.

   When the systems boots, the /etc/init.d/rcS script is executed. It
   in turn executes all the S* scripts in /etc/rcS.d in alphabetical
   (and thus numerical) order. The first argument passed to the
   executed scripts is "start". The runlevel at this point is "N" (none).

   Only things that need to be run once to get the system in a consistent
   state are to be run. The rcS.d directory is NOT meant to replace rc.local.
   One should not start daemons in this runlevel unless absolutely
   necessary. Eg, NFS might need the portmapper, so it is OK to start it
   early in the bootprocess. But this is not the time to start the
   squid proxy server.

2. Going multiuser.

   After the rcS.d scripts have been executed, init switches to the
   default runlevel as specified in /etc/inittab, usually "2".

   Init then executes the /etc/init.d/rc script which takes care of
   starting the services in /etc/rc2.d.

   Because the previous runlevel is "N" (none) the /etc/rc2.d/KXXxxxx
   scripts will NOT be executed - there is nothing to stop yet,
   the system is busy coming up.

   If for example there is a service that wants to run in runlevel 4
   and ONLY in that level, it will place a KXXxxxx script in
   /etc/rc{2,3,5}.d to stop the service when switching out of runlevel 4.
   We do not need to run that script at this point.

   The /etc.rc2.d/SXXxxxx scripts will be executed in alphabetical
   order, with the first argument set to "start".

3. Switching runlevels.

   When one switches from (for example) runlevel 2 to runlevel 3,
   /etc/init.d/rc will first execute in alphabetical order all K
   scripts for runlevel 3 (/etc/rc3.d/KXXxxxx) with as first argument
   "stop" and then all S scripts for runlevel 3 (/etc/rc3.d/SXXxxxx)
   with as first argument "start".

   As an optimization, a check is made for each "service" to see if
   it was already running in the previous runlevel. If it was, and there
   is no K (stop) script present for it in the new runlevel, there is
   no need to start it a second time so that will not be done.

   On the other hand, if there was a K script present, it is assumed the
   service was stopped on purpose first and so needs to be restarted.

   We MIGHT make the same optimization for stop scripts as well-
   if no S script was present in the previous runlevel, we can assume
   that service was not running and we don't need to stop it either.
   In that case we can remove the "coming from level N" special case
   mentioned above in 2). But right now that has not been implemented.

4. Single user mode.

   Switching to single user mode is done by switching to runlevel 1.
   That will cause all services to be stopped (assuming they all have
   a K script in /etc/rc1.d). The runlevel 1 scripts will then switch
   to runlevel "S" which has no scripts - all it does is spawn
   a shell directly on /dev/console for maintenance.

5. Halt/reboot

   Going to runlevel 0 or 6 will cause the system to be halted or rebooted,
   respectively. For example, if we go to runlevel 6 (reboot) first
   all /etc/rc6.d/KXXxxxx scripts will be executed alphabetically with
   "stop" as the first argument.

   Then the /etc/rc6.d/SXXxxxx scripts will be executed alphabetically
   with "stop" as the first argument as well. The reason is that there
   is nothing to start anymore at this point - all scripts that are
   run are meant to bring the system down.

   In the future, the /etc/rc6.d/SXXxxxx scripts MIGHT be moved to
   /etc/rc6.d/K1XXxxxx for clarity.

[0 N0.1938 huan ~ ]$      
你可以修改/etc/rc.local文件   
例如你要在系统启动时 运行mysql  就将命令写入
/usr/local/mysql/bin/mysqld_safe &
别忘了后台执行符号&      
/etc/rc.local在RH类系统里才有      
我如下方式修改rc.loccal
cd /home/lbw
./testdb &
testdb无法启动,它是一个连orcale数据库的程序
我把testdb换成一个普通的程序,就是不用连数据库,就可以启动,请问这是为什么?应该如何做才能启动testdb?谢谢!      
Li-jiahua说的很对 受教了 多谢!


lbwdevil,你说的没怎么看懂 你为什么不用绝对路径
加入/home/lbw/testdb &试试      
绝对路径也不行,还是一样的问题.是不是跟数据库有关呀?      
这就不太清楚了
如果你在shell下运行testdb ,无法连上database的话,这样话,根本不用谈什么自动启动了
可能是程序本身的问题,也可能是数据库的问题      
是不是数据库没有在test程序运行之前起动/??