Use service commands and chkconfig commands to manage service processes
Source: Internet
Author: User
Using service commands and chkconfig commands to manage service process service commands can quickly start and stop service programs in linux, which is very useful during debugging. the chkconfig command can be used to quickly set the service programs that need to be automatically started at startup. the functions of these two commands can be... using service commands and chkconfig commands to manage service process service commands can quickly start and stop service programs in linux, which is very useful during debugging. the chkconfig command can be used to quickly set the service programs that need to be automatically started at startup. the functions of these two commands can be implemented through other methods, but they are more convenient and easier to maintain. in debian linux, if you use the apt-get command to install mysql, nginx, and other service programs, the installation program will automatically go to/etc/init. d/create a shell script for managing the service process in the directory, such as: 1/etc/init. d/mysql2/ Etc/init. d/nginx3/etc/init. d/keepalived so that we can use/etc/init. d/{script file name} start or service {script file name} start to start a service, such as: 1 # start mysql service 2/etc/init. d/mysql start3service mysql start if the process management script supports restart command parameters, you can also use/etc/init. d/{script file name} restart or service {script file name} restart to restart a service, for example, 1 # restart mysql service 2/etc/init. d/mysql restart3service mysql restart the above two commands have the same effect, so that when you restart mysql or php-fpm, you do not have to kill the process each time, then write a large number of paths and parameters to start the service. just use servic E command, you only need to remember the script file name and do not need to write an absolute address. this is more convenient. the default script file name is the same as the service program name. if you compile and install a service program such as php-fpm,/etc/init. the script in the d directory needs to be added by yourself. fortunately, this script is included in the source code package of many service programs, for example, 1mysql5. 6. support-files/mysql in the source code. sapi/fpm/init in server2php5.4 source code. d. utils/redis_init_script in php-fpm3redis2.6 source code these are the process management scripts officially provided by the application, copy them to/etc/init. in the d directory, you can use the service command to manage the service process by changing the name. do not forget to copy to/etc/init. d. add the executable permission to the script. 1 chmod + x/etc/init. d/mysql/etc/init. d/nginx/etc/init. D/redis sometimes needs to modify the parameters in the script, such as the path name, for smooth execution. you need to perform a simple debugging. note that the first parameter after the service command following the service command must be/etc/init. d. The Script name is the same, otherwise the system will report an error. for simplicity, you can directly name the service program name. the second parameter of the service command, such as start, stop, and restart, is passed to the process management script. therefore, whether this parameter is supported is not determined by the service Command, but by the process management script. different process management scripts have different command parameters and functions. the process management script supports both start and stop command parameters, and may also support other command parameters. generally, you can use service {script name} to view the help information of the script. the supported command parameters include 1root @ lvmingming:/etc/init. d # service mysql2Usage:/etc/init. d/m Ysql start | stop | restart | reload | force-reload | status3root @ lvmingming:/etc/init. d # service redis4Please use start or stop as first argument5root @ lvmingming:/etc/init. d # service memcached6Usage:/etc/init. d/memcached {start | stop | restart | force-reload | status} also has some services. for example, you can use the keepalived management script installed with apt-get to view the help information. I want to know which command parameters are supported in this script. I can only read the script myself. the shell script syntax is simple and easy to understand. if you need to compile and install the service program, and there is no process management script in the source code, such as memcached. you can only check the Internet. You have written the script. Otherwise, it would be nice to write a process management script yourself ~ The chkconfig command and/etc/rc. the local script chkconfig command can be used to configure whether a service is automatically started upon startup. in some versions of linux, you need to manually install this command, such as the command to install chkconfig in debian linux: 1apt-get install chkconfig if you do not have the chkconfig command and want to add a service that is automatically started upon startup, you can put the command to/etc/rc. local, but the chconfig command is more convenient. the chkconfig command must also depend on/etc/init. d. Process Management script in the directory. chkconfig command example: 1 # The following script is used in debian linux to test through 2 chkconfig -- help # view the chkconfig command syntax 3 chkconfig-l # check whether all service programs start automatically at all running levels. 4 chkconfig -l mysql # Check the mysql service in Whether or not to automatically start 5 chkconfig-a mysql at the running level # Add a new service mysql in the service list and set it to automatically start 6 chkconfig-d mysql # cancel mysql service startup automatic startup settings 7 chkconfig-s mysql 2345 # enable mysql to automatically start up at the 2345 running level, if the link at a certain transportation level is not correctly added, you can use this command to add it. the principle of chkconfig/etc directory contains a set of rc prefix directories, which are used to store linux auto-start services at various running levels: 1/etc/rc. d/# some basic services that need to be automatically started after startup 2/etc/rc0.d/# services to be started in running mode 0 3/etc/rc1.d/# services to be started in running mode 1 services 4/etc/rc2.d/# services to be started in running mode 2 5/etc/rc3.d/# services to be started in running Mode 3 6/etc/rc4.d/# run module Type 4: services to be started 7/etc/rc5.d/# services to be started in running Mode 5 8/etc/rc6.d/# services to be started in running mode 6 in addition to the README instructions, there are some soft links (symbolic links ), these links point to the process management scripts of each service, and these process management scripts are stored in/etc/init. d directory. the default running level of debian linux is 2. check the content in/etc/rc2.d/01root @ lvmingming :~ # Ls-l/etc/rc2.d/02 total 403-rw-r -- r -- 1 root 677 Nov 17 2012 README04lrwxrwxrwx 1 root 17 May 30 2011 s011_sadm-> .. /init. d/inclusadm05lrwxrwxrwx 1 root 17 Feb 6 S16apache2-> .. /init. d/apache206lrwxrwxrwx 1 root 20 Jun 10 16:31 S17keepalived-> .. /init. d/keepalived07lrwxrwxrwx 1 root 19 Jun 13 13:54 S17memcached-> .. /init. d/memcached08lrwxrwxrwx 1 root 15 Fe B 6 S17mysql-> .. /init. d/mysql09lrwxrwxrwx 1 root 28 Feb 16 S17nagios-nrpe-server-> .. /init. d/nagios-nrpe-server10lrwxrwxrwx 1 root 15 Feb 6 S17nginx-> .. /init. d/nginx11lrwxrwxrwx 1 root 15 Feb 6 13:45 S17rsync-> .. /init. d/rsync12lrwxrwxrwx 1 root 16 Feb 6 13:45 S17vsftpd-> .. /init. d/vsftpd13lrwxrwxrwx 1 root 22 Apr 3 S18avahi-daemon-> .. /init. D/avahi-daemon14lrwxrwxrwx 1 root 15 Feb 6 S18exim4-> .. /init. d/exim1_lrwxrwxrwx 1 root 18 Feb 6 13:45 S20rc. local-> .. /init. d/rc. local we use the chkconfig command to add or delete the auto-start service program at startup, which is actually to create or delete soft links in these directories. the name of each soft link is "uppercase S + running sequence + script name", with a link "S20rc. local-> .. /init. d/rc. local ". open the script/etc/init. d/rc. local, you can see that it calls/etc/rc. local script. original/etc/rc. the commands in local are executed here. if we put the mysql service startup command in/etc/rc. local, The operating system will also execute this list, but its execution order is 20, which is later than that of S17mysql ~
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