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 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 <level code>] [System Service] [on/off/reset] supplementary instructions: 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 <level code> specifies the execution level in which the read system service is enabled or disabled. First, run the chkconfig -- list command to view all the added system services (the following results only part) [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: o Ffmicrocode_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: off 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 In the dynamic mode, whether the service is enabled (on) or disabled (off). For example, by default, the system automatically checks whether the service of the new hardware is started (the service name is kudzu ), it takes a period of time to detect each startup. we can close the service and call it with hardware changes. 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

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.