CentOS Boot Auto Run program script

Source: Internet
Author: User

Sometimes we need to set up a script on the server, so that he can boot on his own. Here's how:

Cd/etc/init.dvi youshell.sh   #将youshell. SH modified to your own foot name

Write your own script and save the exit.
When writing a script, please add the following comments first

#add for chkconfig#chkconfig:2345 30#description:the description of the shell   #关于脚本的简短描述 #processname:servicenam E                    #第一个进程名, the rear setting will be used when the boot

Description
2345 refers to the running level of the script, that is, in 2345 of the 4 modes can be run, 234 are text interface, 5 is the graphical interface x
70 refers to the future startup sequence number of the script, if the start sequence number of other programs is smaller than 70 (such as 44, 45), the script needs to wait until these programs are started before starting.
30 refers to the stop order number of the script when the system shuts down.

Add executable permissions to the script:

chmod +x youshell.sh

Use the Chkconfig command to set the script to self-start

Chkconfig--add ServiceName

This will allow your script to run automatically after booting.

In addition, this method can also be used in Redhat to enable boot-up.

How to use Chkconfig

Chkconfig (check config)

Function Description: Check, set the various services of the system.

Syntax: chkconfig

[--add] [--del] [--list] [System service] or chkconfig[--level< Class Code >][system service][on/off/reset]

Note: This is a program developed by the Redhat company in accordance with the GPL rules, which can query which system services the operating system performs at each level of execution, including various resident services.

Parameters:

–add adds the specified system service, allows the CHKCONFIG directive to manage it, and adds relevant data to the system-initiated narrative file.
–del deletes the specified system service, is no longer managed by the Chkconfig directive, and deletes the relevant data within the system-initiated narrative file.
–level< Class Code > Specify read system services to be turned on or off in which level of execution

The 1:chkconfig command can also be used to activate and deactivate services. 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 whether a service is started or deactivated within a specified runlevel. For example, to deactivate the NSCD service in RunLevel 3, 4, 5, use 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, then finger does not have to manually restart xinetd to be enabled immediately after chkconfig finger on command is executed. 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 of

Edit/etc/rc.d/rc.local File

Format is program name program path

such as a.sh/home/a.sh

CentOS Boot Auto Run program script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.