Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set up self-starting service in linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to set up the self-startup service in linux. The editor thinks it is very practical, so I hope you can get something after reading this article. Let's take a look at it with the editor.

This is done in three main ways:

Ln-s establishes a soft link to the / etc/init.d/ service in the / etc/rc.d/rc*.d directory (* represents one of the seven runlevels 0-6)

Chkonfig Command Line run level Settings

Ntsysv pseudo-graph run level setting

Note:

1. These three methods are mainly used for redhat-based distributions.

two。 If you don't know what the running level is, then you'd better look at the relevant information before you experiment.

The first way: ln-s to establish and start a soft connection

There are seven run levels in Linux (which can be set in the / etc/inittab file), each corresponding to the seven directories of / etc/rc.d/rc [0runs 6] .d

Tips:/etc/rc [0room6] .d is actually a soft connection of / etc/rc.d/rc [0fol6] .d, mainly to maintain compatibility with Unix.

Each of these seven directories stores the services that need to be shut down or started when the corresponding runtime is loaded.

As you can see from the details, each script file corresponds to a specific service in the / etc/init.d/ directory.

The script file at the beginning of K represents that the runtime needs to be closed when loading, and the representative at the beginning of S needs to execute.

So when we need to boot up and start our own script, we just need to drop the executable script in the / etc/init.d directory and establish a soft link in / etc/rc.d/rc*.d

[root@localhost] # ln-s / etc/init.d/sshd / etc/rc.d/rc3.d/S100ssh

Here, sshd is the script file for a specific service, S100ssh is its soft link, and S starts with self-starting when loading.

If you need to set up self-startup at multiple runlevels, you need to establish multiple soft links

This method is tedious and suitable for custom service scripts.

If some services already exist in the system (for example, there are httpd service items when you install Apache), you can use the following two ways

The second way: chkconfig

If you need to start some services automatically, simply use the chkconfig service name on. If you want to shut down, change on to off.

By default, chkconfig launches the four levels of 2345. If you want to customize, you can add-- level option.

Above, we first turn off all startup levels of the sshd service, and then use the-- level option to start the custom level

The Tips:--list option allows you to view the startup status of the specified service, while chkconfig has no option to view the status of all services.

The third way: ntsysv pseudo-graph

Ntsysv and chkconfig are actually the same, except with graphics.

There are two ways to start ntsysv, one is to enter ntsysv directly on the command line, the other is to use the setup command, and then select the system service

By default, the level of startup service set in ntsysv is the current runlevel.

For example, if my current runlevel is 3, then after I choose to start the service in the pseudo-graphical interface, it will also run at a level of 3

If you want to customize the runlevel, you can use ntsysv-- level method.

The above three operations need to ensure that the service script file is executable and have root permission

Among them, the first method is mostly used for custom scripts, and the second and third are mostly used for services that already exist in the system.

Such as ftp, samba, ssh, httpd and so on.

And, to make the relevant settings, you need to figure out the problem of the run level.

Tips: if you want to start a service manually, the traditional way is / etc/init.d service name start

It's actually possible to do this, service service name start.

The above is how to set up the self-startup service in linux. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report