Get To Know Linux: The /etc/init…

转自: http://www.ghacks.net/2009/04/04/get-to-know-linux-the-etcinitd-directory/

If you use Linux you most likely have heard of the init.d directory. But what exactly does this directory do? It ultimately does one thing but it does that one thing for your entire system, so init.d is very important. The init.d directory contains a number of start/stop scripts for various services on your system. Everything from acpid to x11-common is controlled from this directory. Of course it’s not exactly that simple.

If you look at the /etc directory you will find directories that are in the form rc#.d (Where # is a number reflects a specific initialization level – from 0 to 6). Within each of these directories is a number of other scripts that control processes. These scripts will either begin with a “K” or an “S”. All “K” scripts are run before “S” scripts. And depending upon where the scripts are located will determine when the scripts initiate. Between the directories the system services work together like a well-oiled machine. But there are times when you need to start or stop a process cleanly and without using the kill or killall commands. That is where the /etc/init.d directory comes in handy.

Now if you are using a distribution like Fedora you might find this directory in /etc/rc.d/init.d. Regardless of location, it serves the same purpose.

In order to control any of the scripts in init.d manually you have to have root (or sudo) access. Each script will be run as a command and the structure of the command will look like:

/etc/initi.d/command OPTION

Where command is the actual command to run and OPTION can be one of the following:

  • start
  • stop
  • reload
  • restart
  • force-reload

Most often you will use either start, stop, or restart. So if you want to stop your network you can issue the command:

/etc/init.d/networking stop

Or if you make a change to your network and need to restart it, you could do so with the following command:

/etc/init.d/networking restart

Some of the more common init scripts in this directory are:

  • networking
  • samba
  • apache2
  • ftpd
  • sshd
  • dovecot
  • mysql

Of course there may be more often-used scripts in your directory – it depends upon what you have installed. The above list was taken from a Ubuntu Server 8.10 installation so a standard desktop installation would have a few less networking-type scripts.

But what about /etc/rc.local

There is a third option that I used to use quite a bit. This option is the /etc/rc.local script. This file runs after all other init level scripts have run, so it’s safe to put various commands that you want to have issued upon startup. Many times I will place mounting instructions for things like nfs in this script. This is also a good place to place “troubleshooting” scripts in. For instance, once I had a machine that, for some reason, samba seemed to not want to start. Even afer checking to make sure the Samba daemon was setup to initialize at boot up. So instead of spending all of my time up front with this I simply placed the line:

/etc/init.d/samba start

in the /etc/rc.local script and Samba worked like a charm. Eventually I would come back and trouble shoot this issue.

Final Thoughts

Linux is flexible. Linux is so flexible there is almost, inevitably, numerous ways to solve a single problem. Starting a system service is one such issue. With the help of the /etc/init.d system (as well as /etc/rc.local) you can pretty much rest assured your service will start.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用jsoup抓取并输出"1994 / 美国 / 犯罪 剧情"这样的信息,首先需要对HTML页面进行解析。以下是详细步骤: 1. **添加jsoup依赖**:确保你的Java项目中已经添加了jsoup库的依赖。如果使用Maven,可以在pom.xml文件中加入jsoup的相关依赖项。 2. **加载HTML文档**:使用Jsoup的`connect`方法加载目标URL的HTML文档,或者使用`parse`方法从HTML字符串中解析文档。 3. **解析DOM元素**:根据HTML的结构,使用Jsoup提供的DOM遍历方法或CSS选择器来查找包含"1994 / 美国 / 犯罪 剧情"信息的特定元素。 4. **提取文本信息**:一旦定位到包含这些信息的元素,可以使用`text()`方法或者`ownText()`方法提取元素的文本内容。 5. **输出结果**:将提取到的信息按照需要的格式输出。 以下是一个简化的示例代码,演示如何使用Jsoup抓取页面中的特定信息: ```java import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; public class JsoupExample { public static void main(String[] args) { try { // 连接到网页并获取文档对象 Document doc = Jsoup.connect("http://example.com").get(); // 根据HTML结构选择元素,这里假设信息在一个class为"info"的div内 Element infoDiv = doc.select(".info").first(); // 提取并打印文本信息 String infoText = infoDiv.ownText(); System.out.println(infoText); } catch (Exception e) { e.printStackTrace(); } } } ``` 请注意,上述代码仅为示例,你需要根据实际的HTML页面结构和元素来调整选择器。同时,异常处理也应根据具体情况进行完善。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值