In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to make the program on the Linux system run automatically after boot". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to make the programs on the Linux system run automatically after boot"!
Linux has its own complete startup system, which grasps the context of Linux startup, and the startup process of Linux will no longer be mysterious.
It is recommended to take a look at the attached pictures before reading.
In this article, it is assumed that the init tree set in inittab is:
/ etc/rc.d/rc0.d
/ etc/rc.d/rc1.d
/ etc/rc.d/rc2.d
/ etc/rc.d/rc3.d
/ etc/rc.d/rc4.d
/ etc/rc.d/rc5.d
/ etc/rc.d/rc6.d
/ etc/rc.d/init.d
1. About the startup of Linux
Init is the father of all processes.
Init read / etc/inittab, execute rc.sysinit script
(note that the file name is not necessary, and some unix even write statements directly in inittab.)
The rc.sysinit script does a lot of work:
Init $PATH
Config network
Start swap function
Set hostname
Check root file system, repair if needed
Check root space
....
Rc.sysinit executes rc?.d scripts according to inittab
Linux is a multi-user system, and getty is a watershed between multi-user and single-user.
Before getty, you ran system scripts.
. About rc.d
All startup scripts are placed under / etc/rc.d/init.d
Placed in rc?.d is a link to a script in init.d
The naming format is:
S {number} {name}
K {number} {name}
The file starting with S passes the start parameter to the script
Files starting with K pass stop parameters to the script
Number decides the order of execution
3. Startup script example
This is a / etc/rc.d/init.d/apache script to start httpd:
Code:
#! / bin/bash
Source / etc/sysconfig/rc
Source $rc_functions
Case "$1" in
Start)
Echo "Starting Apache daemon..."
/ usr/local/apache2/bin/apachectl-k start
Evaluate_retval
Stop)
Echo "Stopping Apache daemon..."
/ usr/local/apache2/bin/apachectl-k stop
Evaluate_retval
Restart)
Echo "Restarting Apache daemon..."
/ usr/local/apache2/bin/apachectl-k restart
Evaluate_retval
Status)
Statusproc / usr/local/apache2/bin/httpd
*)
Echo "Usage: $0 {start | stop | restart | status}"
Exit 1
Esac can see that he accepts the start,stop,restart,status parameter.
You can then set up a link to rc?.d like this:
Code:
Cd / etc/rc.d/init.d & &
Ln-sf.. / init.d/apache.. / rc0.d/K28apache & &
Ln-sf.. / init.d/apache.. / rc1.d/K28apache & &
Ln-sf.. / init.d/apache.. / rc2.d/K28apache & &
Ln-sf.. / init.d/apache.. / rc3.d/S32apache & &
Ln-sf.. / init.d/apache.. / rc4.d/S32apache & &
Ln-sf.. / init.d/apache.. / rc5.d/S32apache & &
Ln-sf.. / init.d/apache.. / rc6.d/K28apache4. About rc.local
Rc.local, which is often used, is entirely a matter of habit, not standard.
Different distributions have different implementations, which can be implemented as follows:
Code:
Touch / etc/rc.d/rc.local
Chmod + x / etc/rc.d/rc.local
Ln-sf / etc/rc.d/rc.local / etc/rc.d/rc1.d/S999rc.local & &
Ln-sf / etc/rc.d/rc.local / etc/rc.d/rc2.d/S999rc.local & &
Ln-sf / etc/rc.d/rc.local / etc/rc.d/rc3.d/S999rc.local & &
Ln-sf / etc/rc.d/rc.local / etc/rc.d/rc4.d/S999rc.local & &
Ln-sf / etc/rc.d/rc.local / etc/rc.d/rc5.d/S999rc.local & &
Ln-sf / etc/rc.d/rc.local / etc/rc.d/rc6.d/S999rc.local5. About bash startup script
/ etc/profile
/ etc/bashrc
~ / .bash_profile
~ / .bashrc
Is the startup script for bash
Generally used to set up a single-user startup environment, you can also boot single-user programs, but to make it clear that they all belong to the bash category rather than the system category.
Their specific roles are described as follows:
/ bin/bash, the command interpreter (hereinafter referred to as shell), uses a series of startup files to establish a runtime environment:
/ etc/profile
/ etc/bashrc
~ / .bash_profile
~ / .bashrc
~ / .bash_logout
Each file has a special function and has a different impact on the login and interaction environment.
/ etc/profile and ~ / .bash_profile are called when you start an interactive login shell.
/ etc/bashrc and ~ /. Bashrc are called when an interactive non-login shell starts.
~ / .bash_logout is read when the user logs out and logs in
An interactive login shell will run after / bin/login has successfully logged in. An interactive non-login shell is run from the command line, such as [prompt] $/ bin/bash. Generally, a non-interactive shell appears when running a shell script. It is called a non-interactive shell because it does not wait for input on the command line but simply executes a script.
At this point, I believe you have a deeper understanding of "how to make the programs on the Linux system run automatically after boot". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.