CentOS Boot Custom Script
Sometimes we need to set up a script on the server so that he can start it on his own. The method is as follows:
cd/etc/init.d VI youshell.sh #将youshell. SH modified for your own foot name
Write your own script and save the exit.
When writing a script, please join the release
#add for chkconfig #chkconfig: #description: #关于脚本的简短描述 #processname: #第一个进程名, the rear settings will be used when starting from the
Description
2345 refers to the script run level, that is, in 2345 of these 4 modes can be run, 234 are text interface, 5 is the graphical interface x
70 refers to the script's future boot sequence number, if the other program's startup sequence number is smaller than 70 (such as 44, 45), the script needs to wait until these programs are started.
30 refers to the stop sequence number of the script when the system shuts down.
To add executable permissions to the script:
chmod +x youshell.sh
Use the Chkconfig command to set the script to start from
Chkconfig--add ServiceName
This will allow your script to run automatically after it is powered on.
In addition, this method can also be used in Redhat to achieve power-on from boot.
How to use Chkconfig
Chkconfig (check config)
Function Description: Check, set up the system of various services.
Syntax: chkconfig
[--add] [--del] [--list] [System service] or chkconfig[--level< rank code >][system service][on/off/reset]
Supplemental Note: This is a program developed by the Redhat company in accordance with the GPL rules, which can query the system services that the operating system performs in each execution level, including all kinds of resident services.
Parameters:
–add adds the specified system service, allows the chkconfig instruction to manage it, and adds the relevant data to the system-initiated narrative file.
–del deletes the specified system service, is no longer managed by the Chkconfig command, and deletes the relevant data in the system-initiated narration file.
–level< Level Code > Specify the system service to be opened or closed at which level of execution
The 1:chkconfig command can also be used to activate and deactivate a service. The chkconfig–list command displays a list of system services and whether these services have been started (on) or stopped (off) at run level 0 through 6.
Chkconfig–list
Chkconfig–list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2:chkconfig can also be used to set a service to be started or deactivated at a specified run level. For example, to deactivate the NSCD service at run Level 3, 4, 5, use the following command:
Chkconfig–level 345 NSCD off
3: Services managed by XINETD will immediately be chkconfig affected. For example, if XINETD is running, and finger is disabled, and after the chkconfig finger on command is executed, finger does not have to manually restart xinetd to be enabled immediately. Changes to other services will not take effect immediately after the use of chkconfig. You must use the service servicename Start/stop/restart command to restart services
The second method
Edit/etc/rc.d/rc.local File
Format is program name program path
such as a.sh/home/a.sh
Thank you for reading, I hope to help you, thank you for your support for this site!