先举个例子:
我们在Ubuntu中启动/停止mysql有两种方式:
>service mysql start
或
>/etc/init.d/mysql start
我一直用第二种方法,今天发现ubuntu升级以后开始报错(但是还能继续用):
root@lillian-VirtualBox:/etc/mysql# /etc/init.d/mysql restart
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql restart
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the stop(8) and then start(8) utilities,
e.g. stop mysql ; start mysql. The restart(8) utility is also available.
mysql stop/waiting
mysql start/running, process 2556
也就是说Ubuntu推荐使用Upstart(对应的命令就是第一种). Upstart是ubuntu使用的,在其他的linux操作系统中,也可以同时使用前面提到的两种控制task的方法,但是实现的细节不同。
Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping themduring shutdown and supervising them while the system is running.
这里是Upstart的手册:
http://upstart.ubuntu.com/cookbook/#pre-start
使用这种方式启停mysql时,会运行/etc/init/mysql.conf这个配置文件。说白了就是一种脚本,用于在启停mysql前后做一些额外的工作,如pre-start等等。
具体用法在上面的手册中很详细。mysql.conf文件中使用的语言一部分是shell。我觉得应该是bash shell, 因为ubuntu的默认shell就是bash shell。
关于service和init.d还可以参考下面这个帖子:
http://askubuntu.com/questions/2075/whats-the-difference-between-service-and-etc-init-d