Centos boot Custom Script
Sometimes we need to set a script on the server so that it can be started as soon as it is turned on. The method is as follows:
Cd/etc/init. dviyoushell. sh # Change youshell. sh to your own script name.
Write your own scripts and save and exit.
When writing a script, add it to the *** release
# Addforchkconfig # chkconfig: # description: # Brief description of the script # processname: # The first process name, which will be used when auto-start is set later
Note:
2345 indicates the script running level, that is, it can be run in the four modes of 2345, 234 is a text interface, and 5 is a graphical interface X
70 indicates the sequence number of the script to be started in the future. If the sequence number of other programs is smaller than 70 (such as 44 and 45), the script must be started after these programs are started.
30 indicates the stop sequence number of the script when the system is disabled.
Add executable permissions to the script:
chmod+xyoushell.sh
Use the chkconfig command to set the script to self-start
chkconfig--addservicename
In this way, your script runs automatically after it is started.
In addition, you can use this method in redhat to enable auto-start upon startup.
How to Use chkconfig
Chkconfig (check config)
Function Description: Check and set various services of the system.
Syntax: chkconfig
[-- Add] [-- del] [-- list] [System Service] Or chkconfig [-- level <level code>] [System Service] [on/off/reset]
Note: This is a program developed by RedHat following the GPL rules. It can query the system services that the operating system will execute at each execution level, including various resident services.
Parameters:
-Add adds the specified system service, enables the chkconfig command to manage it, and adds relevant data in the system startup description file.
-Del: deletes the specified system service. It is no longer managed by the chkconfig command, and relevant data is also deleted in the description file started by the system.
-Level <level code> specifies the execution level of the read System Service
1: The chkconfig command can also be used to activate and remove services. The chkconfig-list command displays the list of system services, and whether these services have been started (on) or stopped (off) in the running level from 0 to 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 whether a service is started or stopped at a specified running level. For example, to stop the nscd service in runlevel 3, 4, and 5, run the following command:
Chkconfig-level 345 nscd off
3: services managed by xinetd are immediately affected by chkconfig. For example, if xinetd is running and finger is disabled, after the chkconfig finger on command is executed, finger does not have to manually restart xinetd to be enabled immediately. Changes to other services do not take effect immediately after chkconfig is used. You must use the service servicename start/stop/restart command to restart the service.
Method 2
Edit the/etc/rc. d/rc. local file
Format: program name program path
For example, a. sh/home/a. sh