问题发现

今天在给ubuntu系统安装ftp服务时,一件奇怪的事引起了我的注意。当我服务安装完成后,想要测试一下是否能控制服务,便输入如下命令:

service vsftpd restart

它返回的信息是:

stop: Unknown job: vsftpd
start: Unknown job: vsftpd

另外甚至在/etc/init.d/文件夹中都没有发现vsftpd的启动脚本。

之后我google后在service命令前加了sudo,命令如下:

sudo service vsftpd restart

结果成功运行。

现在虽然ftp能够正常的启动和终止,但是另一个疑问没有解决,service不是调用/etc/init.d/文件夹里的启动脚本的吗,然而/etc/init.d/中并没有vsftpd这个脚本,为什么还能够运行?我通过man命令查看了一下service指令的信息,果然发现了一些端倪,里面是这样讲的

The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT, or the name of an upstart job in /etc/init.

于是我在/etc/init文件夹中果然发现了vsftpd.conf这个文件。但是又有奇怪的事情出现了,查看/etc/init/文件夹中许多文件是和/etc/init.d/文件夹中重复的,比如mysql。那么这两个文件夹有什么区别吗?

寻求答案

这种东西当然是寻求google的帮助最快了。果然很快就找到了一位外国大神的答案。他是这么说的:

/etc/init.d contains scripts used by the System V init tools (SysVinit). This is the traditional service management package for Linux, containing the init program (the first process that is run when the kernel has finished initializing¹) as well as some infrastructure to start and stop services and configure them. Specifically, files in /etc/init.d are shell scripts that respond to start, stop, restart, and (when supported) reload commands to manage a particular service. These scripts can be invoked directly or (most commonly) via some other trigger (typically the presence of a symbolic link in /etc/rc?.d/).

/etc/init contains configuration files used by Upstart. Upstart is a young service management package championed by Ubuntu. Files in /etc/init are configuration files telling Upstart how and when to start, stop, reload the configuration, or query the status of a service. As of lucid, Ubuntu is transitioning from SysVinit to Upstart, which explains why many services come with SysVinit scripts even though Upstart configuration files are preferred. In fact, the SysVinit scripts are processed by a compatibility layer in Upstart.

简而言之,/etc/init.d/就是旧时代liunx的用法,/etc/init/是现在Ubuntu的提倡并一步步转型的用法。为了平缓过渡,便让service命令可以同时寻找到两个文件夹。

问题思考

问题到这貌似解决了,但是感觉还差些什么。

在查看service命令时,是这么介绍的:

service - run a System V init script

没错,service这个命令一开始就是用在SysVinit上的,为了支持Upstart才额外增加了启动/etc/init/文件夹,那么如何使用Upstart启动服务呢。最后查看Upstart的文档,当我要重启mysql时。我只需要输入如下命令:

sudo restart mysql

而且Upstart的启动配置文件确实简单很多。

问题总结

其实这两个文件夹的区别也就是服务启动方式的区别,目前有三种启动方式。(例如我启动mysql服务)

1.只从/etc/init.d/文件夹启动:

/etc/init.d/mysql start

2.只从/etc/init/文件夹启动(Ubuntu提倡):

sudo start mysql

3.从两个文件夹中启动:

service start mysql

最新文章

  1. centos 7.0 nginx 1.7.9成功安装过程
  2. PHP慢脚本日志和Mysql的慢查询日志
  3. windows svn 上传后 自动部署 到web目录下
  4. Jquery_操作cookies
  5. SqlSever基础 dateadd day 增加五天
  6. UVA 11584 一 Partitioning by Palindromes
  7. EXt form属性
  8. algorithm@ 大素数判定和大整数质因数分解
  9. TeXLive安装过程
  10. php基础知识笔记
  11. 前后端分离,接口API,契约
  12. 前端面试题(3) cookie,sessionStorage和localStorage的区别
  13. Hyperledger Fabric Model——超级账本组成模型
  14. xshell连接虚拟机ubuntu
  15. LocalDate
  16. p132程序代码解析
  17. css设置文本自动换行
  18. apt-get update 更新 ubuntu时出现Hash sum mismatch的原因及解决方法
  19. [转帖]召冠总的 Oracle常用的性能诊断语句. --保存学习备查
  20. python删除数组元素导致跳过元素

热门文章

  1. I.MX6 sdio 设备注册及识别
  2. linux部署web项目到tomcat下(图文详解)
  3. C:static 关键字、静态变量、跨类访问数据
  4. (二十六)分类信息的curd-分类信息添加
  5. C++语言中的static关键字的作用是什么?
  6. poj1651【区间DP·基础】
  7. python __builtins__ license类 (41)
  8. CF1060E Sergey and Subway(点分治)
  9. [USACO10MAR]伟大的奶牛聚集Great Cow Gat…【树形dp】By cellur925
  10. 使用Ctex中遇到的一些问题