Run as a service on Linux on the Java command line

Source: Internet
Author: User

Now the framework of spring and so on can support the release of the war instead of using the jar, so that the server does not have to install containers, convenient. However, you do not have to install the container to write scripts to complete the service start, stop, restart.

The script is as follows:

#!/bin/bash## chkconfig:345 30# Description: ${description}# processname: ${processname}# Source function library.#!/ Bin/shservice_name=${servicename}path_to_jar=${jarfile}pid_path_name=/tmp/${servicename}-pidcase $ in Start) EC Ho "Starting $SERVICE _name ..." if [! -F $PID _path_name];                        Then Nohup Java-jar ${javaargs} $PATH _to_jar/tmp 2>>/dev/null >>/dev/null & Echo $! > $PID _path_name echo "$SERVICE _name started ..." Else echo "$SERVICE _name is already Runn    ing ... "fi;; Stop) if [-f $PID _path_name];            Then pid=$ (cat $PID _path_name);            echo "$SERVICE _name stoping ..." Kill $PID; echo "$SERVICE _name stopped ..." rm $PID _path_name Else echo "$SERVICE _name is not running.        ."    fi;; restart) If [-f $PID _path_name];            Then pid=$ (cat $PID _path_name); Echo "$SERVICE _name stopping ...";            Kill $PID;            echo "$SERVICE _name stopped ..."; RM $PID _path_name echo "$SERVICE _name starting ..." Nohup Java-jar ${javaargs} $PATH _to_jar/tmp 2& gt;>/dev/null >>/dev/null & Echo $! > $PID _path_name echo "$SERVICE _name started ..." Else echo "$SERVICE _name is not running ... "FI;; Esac

  

Run as a service on Linux on the Java command line

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.