In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use upstart to achieve process management in Ubuntu. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
In order to be backward compatible with the original init implementation, Ubuntu upstart can be said to retain most of the features of the original init on the surface, so the name of the linux initialization process is still init, and the core of the change is the Event mechanism. It is not easy to understand and explain the significance and underlying mechanism of this change, so I only intend to study the current apparent behavior of Ubuntu upstart (0.3.9, ubuntu 8.04) during system startup. [note: according to Scott James Remnant on his blog, Ubuntu upstart 0.5.0 will be released in the coming weeks.
With regard to system startup, most people who are familiar with Linux should know that the init process (PID=1) is the parent of all processes, and all processes are controlled by it. The init process runs after the kernel finishes loading the file system. So how does the init process start other processes in the system? Before expounding on this issue, I would like to outline several directories and applications related to init in ubuntu, which can be discussed later. These directories and programs include:
Init
Telinit
Runlevel
/ etc/event.d/ / etc/init.d/ / etc/rcX.d/
The first three are applications (note that none of them are shell scripts), which can be understood as being called by the kernel. About their functions, you can check them from manpage. Our focus is on the three directories given later.
The first is the / etc/event.d/ directory, which is the core of Ubuntu upstart. What distinguishes Ubuntu upstart from the original init is that it introduces the event mechanism. The popular Event mechanism is to treat all process triggers, stops, and so on as event (events). The event that Ubuntu upstart needs to identify is stored in / etc/event.d/. There are mainly three kinds of rc-default, rcX. The sysv-rc-conf tool shows the levels of 0meme 1. 6) and ttyX. This rc-default is similar to the famous inittab file, which sets the default run level. [note: there is no concept of run level in Ubuntu upstart, so it is called for init backward compatibility]. Now you should know where to set the default run level when there is no inittab file in ubuntu. Cat rc-default it! The rcX file is the script that needs to run the program when the corresponding run-level event occurs (you can notice that the word event is really everywhere in Ubuntu upstart), while ttyX sets the number of pseudo terminals, that is, the Console called by your Ctrl+Alt+F (1x6). Let's take rc2 as an example, cat rc2:
Start on runlevel 2
Stop on runlevel [! 2]
Console output
Script
Set $(runlevel-- set 2 | | true)
If ["$1"! = "unknown"]; then
PREVLEVEL=$1
RUNLEVEL=$2
Export PREVLEVEL RUNLEVEL
Fi
Exec / etc/init.d/rc 2
End script
Instead of thinking about the details, just pay attention to the first two lines and the penultimate line. As you can see, the rc2 file defines what to execute when run level 2 occurs, and the core is this sentence: exec / etc/init.d/rc 2. In this way, we can naturally transition to the next important directory, / etc/init.d/.
You can ls / etc/init.d/ to take a look at the contents and have a general understanding of it. / etc/init.d/ stores execution scripts for services (services) or tasks (tasks). It can be said that as long as you install a program (especially the service program daemon) that runs when the system starts, it must have a script file in / etc/init.d/. We also go back to the rc2 file above, which executes a command for exec / etc/init.d/rc 2. That is, the / etc/init.d/rc script is passed a parameter "2" to execute. If we take a closer look at the rc script (very long, be patient), we can see a passage like this:
# Now run the START scripts for this runlevel.
# Run all scripts with the same level in parallel
For s in / etc/rc$runlevel.d/S*
This means that when you pass a numeric parameter "X" to the rc script, it will start executing the script starting with S under / etc/rcX.d/ after a series of settings. This transitions to the next directory / etc/rcX.d/.
Go to / etc/rcX.d/,ls-l / etc/rcX.d/ and see what it contains. Haha, yes, there are symbolic links to scripts in / etc/init.d/. The difference is that they start with S and a number. Anyone familiar with the original init should know that S means to run at startup, and the number indicates the order of execution.
In this way, the ubuntu startup process managed by Ubuntu upstart should be clear. Sort it out: 1, the kernel starts init 2 init to find the / etc/event.d/rc-default file, determines the default run level (X) 3, triggers the corresponding runlevel event, and starts running / etc/event.d/rcX 4 Magi RCX run / etc/init.d/rc, passing in the parameter X 5 mag _ mag _ init. D _ etc/init.d/rc script for a series of settings * run the script in the corresponding / etc/rcX.d/, 6. The script in the script 6 in the / etc/rcX.d/ starts according to the pre-set priority until the login screen (starting the X server and GDM) is given.
On how to use upstart in Ubuntu to achieve process management is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.