Sh script to start the Java program

Source: Internet
Author: User
# Start. shmain_class = $1 # function declaration usage () {echo "Please set startup ARGs string" Exit 1;} # note that spaces must be added on both sides of brackets. $ # indicates the number of input parameters, -lt indicates that the escape character is less than the number, and there is a semicolon outside the right parenthesis; if [$ #-lt 3]; then # Call the usagefi function # equal sign to determine if ['whoam' = "root"]; Then ECHO do not use root user to launch me. exit 1; FI #$0 Script Name CD 'dirname $0 '/.. base_dir = "'pwd'" # execute echo "$ base_dir" Here to print the absolute path, the configuration file is saved in the conf_dir directory. conf_dir = $ base_dir/conf # Cat shows the file content. Export java_home = 'cat $ base_dir/bin/javahome 'export Path = $ java_home/bin: $ pathexport lang = zh_cn.gb18030 # If the machine and OS support IPv4 and IPv6 Program The application uses ipv4java_opts = "$ java_opts -djava.net. preferipv4stack = true "java_opts =" $ java_opts-server-Example-xmx512m-XX: permsize = 64 m-XX: maxpermsize = 64 m-xss1m "java_opts =" $ java_opts-XX: newsize = 128 M-XX: maxnewsize = 128 M "# Use cmsjava_opts =" $ java_opts-XX: + useconcmarksweepgc "# GC log configuration java_opts =" $ java_opts-XX: + printgcdetails "java_opts =" $ java_opts-XX: + printgcdatestamps "java_opts =" $ java_opts-XX: + P Rintheapatgc "java_opts =" $ java_opts-XX: + printclasshistogram "# GC log java_opts =" $ java_opts-XX: + RunTime "java_opts =" $ java_opts-xloggc: $ base_dir/logs/GC-$ task_name.log "# enable the remote debugging port # java_opts =" $ java_opts-xdebug-xrunjdwp: Transport = dt_socket, address = 8181, Server = Y, suspend = y "# determine whether the file exists-Fif [! -F "$ java_home/bin/Java"]; then Echo "set java_home" Exit 1; filog_path = $ base_dir/logsstart_log = $ log_path/start. log # init logpath and logfile to determine whether the directory exists. If [! -D "$ log_path"]; then mkdir $ log_pathfi # Start the log file if [! -F "$ start_log"]; then # equals to the MK file creation touch $ start_logfi # Start Java Process # standard input. Output and error output are represented as stdin, stdout, stderr, it can also be expressed as 0, 1, or 2. # Command 2> & 1 |...: the error of command is redirected to standard output. Errors and standard output are both transmitted to the next command through the pipeline. # $ CAT test. sh> Test 2> & 1 put the file test. SH Content is appended to the file test # The Last One & indicates that the current shell is running in the background, similar to nohup # If you do not add & use the console to call your own script, the script calls Java, which is equivalent to the terminal's sun process and closes the console. Both the script process and Java Process exit $ java_home/bin/Java $ java_opts-classpath $ conf_dir: $ classpath :. $ main_class >>$ start_log 2> & 1 &

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.