Linux service boot settings, linux service boot
Linux also has a self-starting service similar to windows, which is mainly set through the chkconfig command. It is mainly used to update (start or stop) and query the running level information of the system service. Remember that chkconfig does not automatically disable or activate a service immediately, but simply changes the symbolic connection.
Parameter description:
[root@DB-Server rc2.d]# chkconfig --help
chkconfig version 1.3.30.2 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.
usage: chkconfig --list [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>
[root@DB-Server rc2.d]# chkconfig
chkconfig version 1.3.30.2 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.
usage: chkconfig --list [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>
-- List displays services that can be automatically started upon startup.
-- Add adds the specified auto-Start System Service.
-- Del: deletes the specified system service.
-- Level specifies the execution level in which the system service is enabled or disabled.
On/off/reset registers at the specified execution, enable/disable/reset the system service
Use Case:
Chkconfig -- list # displays services that can be automatically started upon startup
Chkconfig -- add *** # add the *** service that is automatically started upon startup
Chkconfig -- del *** # Delete the *** service automatically started upon startup
Chkconfig -- level mysql 2345 on # Set mysql to on when the running level is 2, 3, 4, and 5.
[root@DB-Server ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@DB-Server ~]#
-- Level <level code> specifies the execution level in which the system service is enabled or disabled.
Level 0: Shutdown
Level 1: Single User Mode
Level 2: multi-user command line mode without network connection
Level 3: multi-user command line mode with network connection
Level 4: Undefined
Level 5: multi-user mode with graphic interface
Level 6: restart
[root@DB-Server ~]# chkconfig --list mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@DB-Server ~]# chkconfig --del mysql
[root@DB-Server ~]# chkconfig --list | grep mysql
[root@DB-Server ~]# chkconfig --add mysql
You have new mail in /var/spool/mail/root
[root@DB-Server ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@DB-Server ~]#
If you want to enable mysql service on runlevel 3 and disable it at other runlevel, run the following command to set it.
[root@DB-Server ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@DB-Server ~]# chkconfig --level 3 mysql on
[root@DB-Server ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@DB-Server ~]# chkconfig --level 2 mysql off
[root@DB-Server ~]# chkconfig --level 4 mysql off
[root@DB-Server ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@DB-Server ~]#
Of course, you can also use the following command to enable and disable auto-start of the service.
Chkconfig service_name on
Chkconfig service_name on -- level runlevels
Chkconfig service_name off -- level runlevels
[root@DB-Server ~]# chkconfig mysql on --level 3
[root@DB-Server ~]# chkconfig mysql off --level 45
[root@DB-Server ~]#
After the MySQL service is automatically started upon startup, a file is generated under/etc/rc. d/rcn. d, for example,/etc/rc. d/rc3.d.
We will delete the mysql service that is automatically started upon startup and the corresponding files will be deleted.
[root@DB-Server rc3.d]# chkconfig --del mysql
[root@DB-Server rc3.d]# ls *mysql*
ls: *mysql*: No such file or directory
[root@DB-Server rc3.d]#
Three parameters after chkcofig: the first parameter, which tells chkconf what kind of running level the service starts. The second parameter specifies the startup priority. The last parameter, which specifies the priority of the service when it is stopped. In the instance above, it indicates that the service starts at levels 2, 3, 4, and 5. Its startup priority is 64, and its stop priority is 36.
[Root @ DB-Server rc3.d] # chkconfig -- add mysql
References:
Http://www.cnblogs.com/panjun-Donet/archive/2010/08/10/1796873.html
Http://network810.blog.51cto.com/2212549/1137972