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 does Linux shut down normally?

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

Share

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

Editor to share with you how the Linux shutdown normally, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to understand it!

A file is generated when the system starts and will be deleted when Linux shuts down normally. On the other hand, network administrators can judge whether there is an abnormal shutdown according to whether there is that file when the system is started, so as to reduce the probability of failure in the process of network management.

Steps:

Program the script under / etc/rc.d/init.d/.

Determine whether the computer shuts down properly, and the script that generates the file: touch-file.sh

#! / bin/sh file=/tmp/check if [- e $]; then echo "this is not normal shutdown"

> > / var/log/checkmessage else echo "this is normal shutdown and touch file"

> > / var/log/checkmessage touch $fi

Script for normal shutdown and deletion of files under Linux: rm-file.sh

#! / bin/sh file=/tmp/check echo "this is normal shutdown and rm file"

> > / var/log/checkmessage rm-rf $

Let the script execute automatically.

Ln-s / etc/rc.d/rc0.d/K01rm-file / etc/rc.d/init.d/rm-file.sh

Note:

# ll / etc/rc.d/rc0.d/

The names on both sides of the soft connection are not the same, and the latter can use an absolute path or a relative path. Make sure that the names on both sides are different.

Ln-s / etc/rc.d/rc6.d/K01rm-file / etc/rc.d/init.d/rm-file.sh ln-s

/ etc/rc.d/rc3.d/S01touch-file / etc/rc.d/init.d/touch-file.sh

My system doesn't use x-window, so I don't have level5, which means I don't have to delegate scripts to / etc/rc.d/rc5.d/.

Pay special attention to:

K represents execution when the system is shut down, and S represents boot time. Pay attention to the specification of server scripting, because soft links with K are not necessarily executed automatically when shutting down. Why? When executing the K script, it will query whether there is an empty file name under / var/lock/subsys/ with the same name as the script at the beginning of K. If not, it will not be executed. Therefore, according to the specification written by the server script, touch an empty file with the same name as K01 after / var/lock/subsys/ when starting:

# / var/lock/subsys # touch fm-file

The above is all the contents of the article "how to shut down Linux properly". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to 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