/etc/init.d 是一般开机的启动服务存放在这个目录下
/etc/rc.d启动的配置文件和脚本
/etc/init.d & /etc/rc.d/init.d是同一个目录,内容相同
实现机制,其实/etc/init.d是一个符号链接文件,链接指向/etc/rc.d/init.d
你运行以下命令可以看出来
[root@localhost ~]# ls -ld /etc/init.d
lrwxrwxrwx. 1 root root 11 Oct 2 12:15 /etc/init.d -> rc.d/init.d
建立方法是:ln -s /etc/rc.d/init.d /etc/init.d
[root@localhost ]# vim /etc/init.d/mysqld
1 #!/bin/sh
2 # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
3 # This file is public domain and comes with NO WARRANTY of any kind
4
5 # MySQL daemon start/stop script.
6
7 # Usually this is put in /etc/init.d (at least on machines SYSV R4 based
8 # systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
9 # When this is done the mysql server will be started when the machine is
10 # started and shut down when the systems goes down.
11
12 # Comments to support chkconfig on RedHat Linux
13 # chkconfig: 2345 64 36
14 # description: A very fast and reliable SQL database engine.
15
16 # Comments to support LSB init script conventions
17 ### BEGIN INIT INFO
18 # Provides: mysql
19 # Required-Start: $local_fs $network $remote_fs
20 # Should-Start: ypbind nscd ldap ntpd xntpd
21 # Required-Stop: $local_fs $network $remote_fs
22 # Default-Start: 2 3 4 5
23 # Default-Stop: 0 1 6
24 # Short-Description: start and stop MySQL
25 # Description: MySQL is a very fast and reliable SQL database engine.
26 ### END INIT INFO
27
28 # If you install MySQL on some other places than /usr/local/mysql, then you
29 # have to do one of the following things for this script to work:
30 #
31 # - Run this script from within the MySQL installation directory
32 # - Create a /etc/my.cnf file with the following information:
33 # [mysqld]
34 # basedir=<path-to-mysql-installation-directory>
35 # - Add the above to any other configuration file (for example ~/.my.ini)
36 # and copy my_print_defaults to /usr/bin
37 # - Add the path to the mysql-installation-directory to the basedir variable
38 # below.
39 #
40 # If you want to affect other MySQL variables, you should make your changes
41 # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
42
43 # If you change base dir, you must also change datadir. These may get
44 # overwritten by settings in the MySQL configuration files.
45
46
47 basedir=/usr/local/mysql
48 datadir=/data/mysql/data
49
50 # Default value, in seconds, afterwhich the script should timeout waiting
51 # for server start.
52 # Value here is overriden by value in my.cnf.
53 # 0 means don't wait at all
54 # Negative numbers mean to wait indefinitely
55 service_startup_timeout=900
56
57 # Lock directory for RedHat / SuSE.
58 lockdir='/var/lock/subsys'
59 lock_file_path="$lockdir/mysql"
60
61 # The following variables are only set for letting mysql.server find things.
62
63 # Set some defaults
64 mysqld_pid_file_path=
65 if test -z "$basedir"
66 then
67 basedir=/usr/local/mysql
68 bindir=/usr/local/mysql/bin
69 if test -z "$datadir"
70 then
71 datadir=/usr/local/mysql/data
72 fi
73 sbindir=/usr/local/mysql/bin
74 libexecdir=/usr/local/mysql/bin
75 else
76 bindir="$basedir/bin"
77 if test -z "$datadir"
78 then
79 datadir="$basedir/data"
80 fi
81 sbindir="$basedir/sbin"
82 libexecdir="$basedir/libexec"
83 fi
84
85 # datadir_set is used to determine if datadir was set (and so should be
86 # *not* set inside of the --basedir= handler.)
87 datadir_set=
88
89 #
90 # Use LSB init script functions for printing messages, if possible
91 #
92 lsb_functions="/lib/lsb/init-functions"
93 if test -f $lsb_functions ; then
94 . $lsb_functions
95 else
96 log_success_msg()
97 {
98 echo " SUCCESS! $@"
99 }
100 log_failure_msg()
101 {
102 echo " ERROR! $@"
103 }
104 fi
105
106 PATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
107 export PATH
108
109 mode=$1 # start or stop
110
111 [ $# -ge 1 ] && shift
112
113
114 other_args="$*" # uncommon, but needed when called from an RPM upgrade action
115 # Expected: "--skip-networking --skip-grant-tables"
116 # They are not checked here, intentionally, as it is the resposibility
117 # of the "spec" file author to give correct arguments only.
118
119 case `echo "testing\c"`,`echo -n testing` in
120 *c*,-n*) echo_n= echo_c= ;;
121 *c*,*) echo_n=-n echo_c= ;;
122 *) echo_n= echo_c='\c' ;;
123 esac
124
125 parse_server_arguments() {
126 for arg do
127 case "$arg" in
128 --basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`
129 bindir="$basedir/bin"
130 if test -z "$datadir_set"; then
131 datadir="$basedir/data"
132 fi
133 sbindir="$basedir/sbin"
134 libexecdir="$basedir/libexec"
135 ;;
136 --datadir=*) datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`
137 datadir_set=1
138 ;;
139 --pid-file=*) mysqld_pid_file_path=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
140 --service-startup-timeout=*) service_startup_timeout=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
141 esac
142 done
143 }
144
145 wait_for_pid () {
146 verb="$1" # created | removed
147 p
387 exit 1
388 ;;
389 esac
390
391 exit 0