Linux Add boot Script

Source: Internet
Author: User
Tags stop script

First, add in/etc/rc.local if you do not want to glue the script, or create a link, then: Step1. First, modify the script so that all of its modules can be executed normally when any directory is started; Step2. At the end of the/etc/rc.local, add a row with the absolute path to start the script, such as: $ vim/etc/rc.local#!/bin/sh## This script will is executed *after* all the other init scripts.# you can put your own initialization stuff on here if you don ' t# want to do the full Sys V style init Stuff.touc H/var/lock/subsys/local. /etc/rc.d/rc.tune/opt/pjt_test/test.pl Save and exit, and then restart the test, after the other programs are started, the script will be started, and the advanced boot-up script 1 can be set to start priority. See if the service is starting to view the current status of the service #service servicename status View the boot-up status of the service #chkconfig--list servicename2. Write a good script like MySQL, put it under/ETC/INIT.D, modify the properties: $ sudo chmod x mysql3. To create a symbolic connection: $ cd/etc Below are a few directories worth noting: RCS.D rc0.d rc1.d ... rc6.d, (0,1 ... 6 for Start Level 0 for stop, 1 for single user mode, 2-5 for multiuser mode, 6 for restart) they are equivalent to Redhat RC.D, you can put the script into RCS.D, and then modify the file name, give it a start sequence number, such as: S88mysql. But the best way to do this is to put it under the appropriate boot level. Practice: Step1: First put MySQL in the/ETC/INIT.D directory Step2: View the current system's boot level $ sudo runlevel N 3STEP3: Set startup level $ UPDATE-RC.D MySQL start 98 2. 98 is the starting sequence number, 2 is the operating level of the system, you can adjust yourself, be careful not to forget the end of the period. Now we go to the/etc/rc2.d, there is a s98mysql such a symbolic link. 4. Then start the system and test to see if the settings are valid. Third, remove the symbolic link when you need to remove the symbolic connection, there are three ways: 1. It is not the best method 2 to delete the corresponding link directly under/ETC/RC2.D. $ update-rc.d-f S10 Remove//Recommended procedure 3. If UPDATE-RC.D command you unfamiliar, you can also try rcconf This command, also very convenient. Iv. source of quotations: Http://hi.baidu.com/hosewen/blog/item/e77e27dbf4da4d68d0164e8e.htmllinux Boot Automatic startup script method 1. Redhat Startup and execution order is: Load kernel execution init program/etc/rc.d/rc.sysinit # The first script executed by Init/ETC/RC.D/RC $RUNLEVEL # $RUNLEVEL is the default run mode/ETC/RC . d/rc.local #相应级别服务启动之后, execute the file (you can actually write the command you want to execute in the file)/sbin/mingetty # Waiting for the user to log in to Redhat,/etc/rc.d/ Rc.sysinit mainly do the same initialization work in each mode of operation, including: Dial-in Keymap and system font start swapping set hostname setting NIS domain name check (fsck) and Mount file system open Quota load sound card module set system clock and so on. /ETC/RC.D/RC executes the script under the corresponding directory according to the run mode specified by its parameters (run level, which you can set in the Inittab file). Any kxx beginning with a stop is called by the call to the argument, and all the sxx begins with the start argument. The order of calls is performed by XX from small to large. (where xx is a number, which is the start order) For example, assuming the default run mode is 3,/ETC/RC.D/RC, the script under/etc/rc.d/rc3.d/is called as described above. It is worth mentioning that the Redhat in the operating mode 2, 3, 5 are the/etc/rc.d/rc.local as the last of the initialization script, so users can add themselves in this file some need to be executed after the other initialization of the command before logging in. When Init waits for/ETC/RC.D/RC to finish executing (because the action/ETC/RC.D/RC in/etc/inittab is wait), the/sbin/mingetty is run on the specified virtual terminal, waiting for the user to sign in. So farLinux startup is complete. 2. Init runlevel and Instruction 2.1 What is Init:init is one of the indispensable programs in Linux system operation. The so-called Init process, which is a user-level process initiated by the kernel. After the kernel has booted itself (already loaded into memory, started running, and has initialized all device drivers and data structures, etc.), the boot process is completed by starting a user-level program init. As a result, Init is always the first process (its process number is always 1). The kernel will find it in several places in the past that used Init, and its correct location (for Linux systems) is/sbin/init. If the kernel cannot find Init, it will try to run/bin/sh, and if it fails, the boot of the system will fail. 2.2 RunLevel So, what is the run level? Simply put, the run level is the functional level that the operating system is currently running. This level is from 1 to 6 and has different functions. The different run level definitions are as follows: # 0-Stop (do not set Initdefault to 0) # 1-Single user mode # s init s = init # 2-multiuser, no nfs# 3-full multiuser mode (standard run level) # 4-No Use # 5-X11 Multi-user graphics mode (xwindow) # 6-reboot (never set the Initdefault to 6) These levels are specified in the/etc/inittab file. This file is the main file that the INIT program looks for, and the first service to run is the file that is placed in the/ETC/RC.D directory. In most Linux distributions, startup scripts are located in/etc/rc.d/init.d. These scripts are connected to the/ETC/RC.D/RCN.D directory with the ln command. (n here is the run level 0-6) 3. Chkconfig command (redhat OS) Unlike DOS or windows,linux can have multiple run levels. Common is multi-user 2,3,4,5, many people know that 5 is the level of running X-windows, and 0 is the shutdown. Changes to the run level can be toggled with the init command. For example, if you want to maintain the system into a single-user state, you can use init to switch. During the switching process of Linux running level, the system will automatically find files corresponding to the/etc/rc[0-6].d of K and S under the directory of Run level, and execute these scripts in the following numerical order. The maintenance of these scripts is a very tedious thing, Linux provides the chkconfig command to update and query the different operationsSystem services at the row level. Syntax: Chkconfig--list [name]chkconfig--add namechkconfig--del namechkconfig [--level levels] Namechkconfig [--level leve LS] Namechkconfig has five features: adding services, deleting services, listing services, changing startup information, and checking the startup status of a particular service. Chkconfig displays usage when no parameters are run. If the service name is added, check that the service is started at the current run level. If it is, returns True, otherwise, returns false. The--level option allows you to specify the run level you want to view, not necessarily the current run level. If On,off or reset is specified after the service name, Chkconfig will change the startup information for the specified service. On and off refer to the start and stop of the service at the time of changing the operating level. Reset refers to initializing the service information, regardless of what is specified by the problematic initialization script. For the on and off switches, the system is only valid for run Level 3, 4, and 5 by default, but reset can be valid for all run levels. When you specify the--level option, you can select a specific run level. It is necessary to note that for each run level, there can be only one startup script or stop script. When you switch the run level, Init does not restart the service that is already started, nor does it stop the service that has stopped. Option Description:--level levels Specifies the run level, a string consisting of numbers 0 through 7, such as:--level 35 for the specified run level 3 and 5. To deactivate the NFS service at run Level 3, 4, 5, use the following command: Chkconfig--level 345 NFS off--add Name This option adds a new service, Chkconfig ensures that each run level has a start (S) or Kill (K) entry. If one is missing, it is automatically created from the default init script. --del name is used to delete the service and to remove the associated symbolic connection from/ETC/RC[0-6].D. --list Name list, if name is specified, then only displays the specified service name, otherwise, lists the status of all services at different run levels. Run-level files each Chkconfig managed service needs to add two or more lines of comments to the script under the corresponding INIT.D. The first line tells Chkconfig the run level of the default startup and the priority of start and stop. If a service is not started by default at any run level, use the-Replace the run level. The second line describes the service and can be commented on across lines. For example, Random.init contains three rows: # chkconfig:2345 # description:saves and restores system entropy pool for # higher quality RA Ndom number generation. Indicates that the random script should start at run Level 2, 3, 4, 5, start with a priority of 20, and stop priority 80. Well, the introduction is here, to see your own directory under the/etc/rc.d/init.d of the script bar. Set up self-starting services: Chkconfig--level 345 NFS On4. Example: Install Apache service under Linux (compile installation by downloading binaries, not RPM package), Apache service start command: $/server/apache/bin/apachectl Start lets the Apache service run below run Level 3. The command is as follows: $ touch/etc/rc.d/init.d/apache$ vim/etc/rc.d/init.d/apacheapache content: #!/bin/bash #Start httpd service/server/ Apache/bin/apachectl start$ chown-r root/etc/rc.d/init.d/apache$ chmod 700/etc/rc.d/init.d/apache$ ll/etc/rc.d/rc3.d /view the start order of all services under this level; $ ln-s/etc/rc.d/init.d/apache/etc/rc.d/rc3.d/s60apache S is a shorthand for start, and a representative for startup; K is the shorthand for kill, the representative closes; 60 numbers represent the order in which they are started. After 60 is usually the more insured number, since the other services are started; The Apache service can be automatically started at run Level 3 at random. (Can be combined with chkconfig to adjust the start-up service accordingly)

Linux Add power-on self-boot script

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.