Linux chkconfig add boot start service

Source: Internet
Author: User
Tags stop script

--add: Adds the specified system service, allows the chkconfig instruction 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 instruction, and deletes the relevant data in the system-initiated narrative file ;--level< Class Code: Specifies which execution level the read system service is to open or close.

Rank code list:

    • Level 0 means: shutdown
    • Level 1 means: Single user mode
    • Level 2: Multi-user command line mode with no network connection
    • Level 3 means: Multi-user command line mode with network connection
    • Level 4 means: not available
    • Level 5 means: Multi-user mode with graphical interface
    • Level 6 means: reboot

It is necessary to note that the level option can specify the run levels to view and not necessarily the current run level. 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.

Run-level files:

Each service managed by Chkconfig 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 does not start at any run level by default, then use - instead of run-level. The second line describes the service and can be \ commented on across lines.

For example, Random.init contains three rows:

# chkconfig:2345 80# description:saves and restores system entropy pool for # higher quality random number generation .

Instance
Chkconfig--list             httpd        #增加httpd服务. Chkconfig--del httpd        #删除httpd服务. Chkconfig--level httpd 2345 on        #设置httpd在运行级别为2, 3, 4, 5 are on (open) state. Chkconfig--list               #列出系统所有的服务启动情况. Chkconfig--list mysqld        #列出mysqld服务设置情况. Chkconfig--level mysqld on #设定mysqld在等级3和5为开机运行服务,--level 35 means that the operation is performed only on levels 3 and 5, on indicates start, and off indicates off. Chkconfig mysqld on            #设定mysqld在各等级为on, "Each level" includes 2, 3, 4, 5 grades. 

How to add a service:

    1. The service script must be stored in the /etc/ini.d/ directory;
    2. chkconfig --add servicenameAdd this service to the list of Chkconfig tool services, at which point the service is /etc/rc.d/rcN.d given the k/s portal;
    3. chkconfig --level 35 mysqld onModifies the default startup level of the service.


[[email protected] ~]# chkconfig--list Show start-up services [[email protected] ~]# chkconfig--add * * * Add boot auto-start * * * service [[[email protected] ~]# chkconfig--del * * * * Delete boot autostart service [[email protected] ~]# Setup can be in the Shell graphics terminal Face configuration command, go to service SELECT [[[email protected] ~]# ntsysv in shell Terminal graphics Configuration Boot service command, option not above that multiple setup, rc.local And chkconfig three ways can be set first) enter the #setup command into the System service menu, select the service you want to start, such as httpd, and then restart the machine or/etc/rc.d./init.d/httpd start the second kind) to put the startup commands in/etc /rc.d/rc.local file so that you can start the service automatically each time, for example, Apache, after compiling Apache will be in the installation directory of the bin generated apachectl file, this is a startup script, We just need to add this command to Rc.local (SuSE has no rc.local.) SuSE can define its own scripts so that if you want to run your own scripts before and after switching the run level, you can create them separately:/etc/init.d/before.local/etc/init.d/after.local) echo/usr/ Local/apache/bin/apachectl>>/etc/rc.d/rc.local, the way to set up the service to start automatically is to include some scripts like the following in rc.local: #sshd/usr/local/sbin /sshd #proftpd/usr/local/sbin/proftpd #apache/home/apache/bin/apachectl start #mysql/home/mysql/bin/safe_mysqld--p ort=3306 & #start oracle8i Listener First Su-oRacle-c ' lsnrctl start ' #start oracle8i su-oracle-c ' Dbstart ' third) through the Chkconfig directive. Use the Chkconfig command to add a service to the operating levels of the system, as follows, 1 to create a startup script. For the apache,mysql,ssh such software is self-brought, we just have to modify a little bit to support chkconfig can be 2 modify the script we need to add 2 lines before the script to support the Chkconfig command # chkconfig:2345 Description:automates A packet filtering firewall withipchains. # Chkconfig: Later defines the runlevel that enables the service to start (in the example, 2345 to start the service), and the order in which the services are closed and started (the order in which the services are turned off in the example above 8, the order in which they are started) descriptions: Description of the Change service ( In the example above is the IPChains packet filter), you can switch to the one you want to do after the implementation of CP your script/etc/rc.d/init.d/script name chmod 700/etc/rc.d/init.d/script name chkconfig--add script name for example: Will It joins the Linux boot process and runs only at level 3 and Levels 5 [[email protected] init.d]/sbin/chkconfig--add apache-httpd [[email  Protected] Init.d]/sbin/chkconfig--level after the Apache-httpdon will be available, each time you restart the server will automatically start and shut down our services

Linux chkconfig Add boot-up service

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.