Register a program as a LINUX system service and set it to a self-starting method

Source: Internet
Author: User
Register a program as a LINUX system service and set it as a self-starting method. here, redhatlinux is used as an example to set a JAVA program as a system service, manage it using the service command, and follow the system to start it. 1. write your own program into the SH script for ease of management. for example, java...
Register a program as a LINUX system service and set it as a self-starting method. here, we use red hat linux as an example to set a JAVA program as a system service, manage it using the service command, and follow the system to start it. 1. write your own program into the SH script for ease of management. for example, java-server-cp. :. /lib/* com. test. startup 2. enter/etc/init. d Directory, create a file, and name it with your own program. for example, the erp content is as follows: [plain] #! /Bin/sh # chkconfig: 35 99 1 # www.2cto.com # description: ERP service # ERP_HOME =/data/falconprobuf RETVAL = 0 ERP_PORT = 8099 # start and stop functions start () {pids = 'netstat-lnp | grep $ ERP_PORT | awk '{print $7} ''pids =$ {pids %/*} if [-n" $ pids "]; then echo "erp service already start" else echo "start erp service" cd $ ERP_HOME. /startup. sh & echo fi} stop () {pids = 'netstat-lnp | grep $ ERP_PORT | awk '{print $7}' 'pids =$ {pids %/*} www.2cto.com if [-n "$ pids"]; then echo "stop erp service" kill-9 $ pids echo "stop erp success" else echo "erp service already stop" fi} # See how we were called. www.2cto.com case "$1" in start) start; stop) stop; restart) stop sleep 2 start; *) echo "Usage: $0 {start | stop | restart} "exit 1 esac ① note that the second line: # chkconfig: 35 99 1 must be added, because the auto-start mode should be set later. ②. /startup. sh & www.2cto.com Plus &, mounted to the background for running, does not affect the current connection session. the full path is not used here, because the relative path is used in the execution script, the corresponding JAR package cannot be found,
The solution is to first jump to the Directory, cd $ ERP_HOME, and then execute the script.
③ ERP_PORT = 8099 set the port and end the program through port filtering, which will be more accurate and will not interfere with other program running. 3. confirm the execution permission of the service file and run the chmod + x erp without restarting. in this case, you can use the SERVCE start | stop | restart method to manage the service. finally, execute chkconfig -- add erp to include the running service and complete the configuration. from the column hxx688
Related Article

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.