Linux boot-up program or script detailed

Source: Internet
Author: User

Many times we need to set up some services or scripts on Linux to boot from, which can avoid the service interruption caused by machine restart and so on. Let's take a look at how Linux is set to start from boot:

cd/etc/init.d vimyscript.sh #将myscript.sh修改为你自己的脚本名

Write your own script and save the exit.

When writing a script, please include the following comments

#add for chkconfig  #description:  #关于脚本的简短描述


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 myscript.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 –listchkconfig –list httpdhttpd 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


This article is from "Ghost" blog, please make sure to keep this source http://fangwei009.blog.51cto.com/5234706/1839505

Linux boot-up program or script detailed

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.