Automatically start a specified application by modifying the Linux service
Source: Internet
Author: User
By modifying the Linux service to automatically start the specified application in Linux, the command for modifying the system service is chkconfig (checkconfig). The command is explained in detail as follows: chkconfig function description: check and set various system services. Syntax: chkconfig [-- add] [-- del] [-- li... by modifying the Linux service to automatically start the specified application in Linux, the command for modifying system services is chkconfig (check config). The command is explained in detail as follows: chkconfig function description: check, set various services of the system. Syntax: chkconfig [-- add] [-- del] [-- list] [system service] or chkconfig [-- level <等级代号> ] [System service] [on/off/reset] Note: This is a program developed by Red Hat following the GPL rules, it can query which system services the operating system will execute in each execution level, including various resident services. Parameter: -- add adds the specified system service, enables the chkconfig command to manage it, and adds relevant data in the system startup description file. -- Del: deletes the specified system service. it is no longer managed by the chkconfig command, and relevant data is also deleted in the description file started by the system. -- Level <等级代号> Specify the execution level of the Read system service. first, run the chkconfig -- list command to view all added system services. (the following result is only part of the result) [root @ fd init. d] # chkconfig -- listdiskdump 0: off 1: off 2: off 3: off 4: off 5: off 6: offxfs 0: off 1: off 2: on 3: on 4: on 5: on 6: offrhnsd 0: off 1: off 2: off 3: on 4: on 5: on 6: offcups-config-daemon 0: off 1: off 2: off 3: on 4: on 5: on 6: offnetfs 0: off 1: off 2: off 3: on 4: on 5: on 6: offnfs 0: off 1: off 2: off 3: off 4: off 5: off 6: offmicrocode_ctl 0: off 1: off 2: on 3: on 4: on 5: on 6: offnetplugd 0: off 1: off 2: off 3: off 4: off 5: off 6: offnetdump 0: off 1: off 2: off 3: off 4: off 5: off 6: offcpuspeed 0: off 1: on 2: on 3: on 4: on 5: on 6: offsyslog 0: off 1: off 2: on 3: on 4: on 5: on 6: offsmb 0: off 1: off 2: off 3: off 4: off 5: off 6: offntpd 0: off 1: off 2: off 3: off 4: off 5: off 6: offrawdevices 0: off 1: off 2: off 3: on 4: on 5: on 6: offpsacct 0: off 1: off 2: off 3: off 4: o Ff 5: off 6: offvncserver 0: off 1: off 2: off 3: off 4: off 5: off 6: offsaslauthd 0: off 1: off 2: off 3: off 4: off 5: off 6: offdc_server 0: off 1: off 2: off 3: off 4: off 5: off 6: offmdmonitor 0: off 1: off 2: on 3: on 4: on 5: on 6: offhttpd 0: off 1: off 2: off 3: off 4: off 5: off 6: offibmasm 0: off 1: off 2: off 3: off 4: off 5: off 6: offdc_client 0: off 1: off 2: off 3: off 4: off 5: off 6: off, the first column indicates the service name, and the value 0-6 indicates that the service is started (on) or Is to close (off). For example, by default, the service that automatically detects new hardware is started (the service name is kudzu). we can disable the service for a period of time after each start, you can call it with hardware changes later. Chkconfig kudzu off chkconfig -- list kudzukudzu 0: off 1: off 2: off 3: off 4: off 5: off 6: off you can see that all services of new hardware are disabled, the new hardware will not be detected when it is started again. If you have made hardware changes, you can choose to open the service (chkconfig kudzu on). In fact, there is a simpler way to enter service kudzu start to manually start the detection of new hardware services. These services are stored in/etc/init. d Directory, they are all executable shell files. for example, the new hardware service [root @ fd/] # ls-l/etc/init. d/kudzu-rwxr-xr-x 1 root 2095 Aug 23 2005/etc/init. d/kudzu the shell file we have written can also be placed here and then added as a system service, but we must follow a simple reservation. Let's take a look at the specific content of kudzu. compile a simple service script to start tomcat in this mode, vi/etc/init. d/tomcat, content: [root @ fd/] # cat/etc/init. d/kudzu #! /Bin/bash # kudzu This scripts runs the kudzu hardware probe. # chkconfig: 345 05 95 # description: This runs the hardware probe, and optionally configures \ # changed hardware. # This is an interactive program, we need the current locale content omitted # chkconfig: 2345 20 80 # description: simple example to start tomcat export JAVA_HOME =/usr/java/jdk1.5.0 _ 16 export CLASS_PATH =/usr/java/jdk1.5.0 _ 16/libexport P ATH = $ JAVA_HOME/bin: $ PATH/usr/Tomcat/bin/startup. sh: add tomcat to the service. The chkconfig -- add tomcat state is set to start chkconfig tomcat on. the comments in the first few lines of the tomcat file must contain two parts: chkconfig and description, otherwise, the error message "tomcat service does not support chkconfig" appears when "chkconfig -- add tomcat" is executed. This line of chkconfig indicates the default startup running level and the priority of start and stop. if the service is not started at any running level by default, "-" is used instead of "Run level. In tomcat, the script is started at runtime level 2, 3, 4, and 5. the priority for starting is 20 (the higher the priority, the later the service starts) and the priority for stopping is 80. If the service has been set, you can modify the startup priority by editing the tomcat file. delete the service and add it. I mimic the content of the new hardware service to write a complicated tomcat service, start tomcat at system startup, and disable tomcat when the system is disabled. The content is as follows # chkconfig: 2345 30 70 # description: Starts and Stops Tomcat. export JAVA_HOME =/usr/java/jdk1.5.0 _ 16 export CLASS_PATH =/usr/java/jdk1.5.0 _ 16/libexport PATH = $ JAVA_HOME/bin: $ PATH case "$1" in start)/usr/Tomcat/bin/startup. sh touch/var/lock/subsys/tomcat; status) if [-f/var/lock/subsys/tomcat]; then echo $ "tomcat is running" exit 0 fi echo $ "tomcat has stopped" exit 3; stop)/usr/Tomcat/bin/shutdown. sh rm-f/var/lock/subsys/tomcat; restart)/usr/Tomcat/bin/shutdown. sh/usr/Tomcat/bin/startup. sh; *) echo "Usage: tomcat {start | stop | restart | status}" exit 1 esac exit 0
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