简单介绍:
说明: Jsvc主要用于非Windows操作系统上以非ROOT用户运行绑定到特权端口的Java服务器,专门由C编写的服务封装器,很容易结合SHELL脚本编写守护脚本.运行后以独立进程存在.
快速安装:
yum -y install gcc autoconfcd /xm-workspace/xm-webs/xmcloud/tomcat8081/bintar -zxvf commons-daemon-native.tar.gz && cd commons-daemon-1.0.15-native-src/unix/bash support/buildconf.sh./configure --with-java=/xm-workspace/xm-webs/xmcloud/jdk && make# bin目录下默认自带daemon.sh调用的就是jsvc命令mv -f jsvc /xm-workspace/xm-webs/xmcloud/tomcat8081/bin/cd ../../ && rm -rf commons-daemon-1.0.15-native-src
守护脚本:
#!/bin/sh # tomcat run/start/stop/restart/version tomcat # # chkconfig: 2345 85 15 # description: apache tomcat daemon script# run/start/stop/restart/version tomcat using jsvc. # Source function library.. /etc/init.d/functionsPORT=8081HOME=/xm-workspace/xm-webs/xmcloudTOMCAT_USER=tomcatJAVA_HOME=${HOME}/jdk/jreCATALINA_HOME=${HOME}/tomcat${PORT}CATALINA_PID=/var/run/tomcat${PORT}.pidJAVA_OPTS="-server -Xms1024m -Xmx1024m -Xmn384m -XX:PermSize=64m -XX:MaxPermSize=128m -XX:+UseParallelOldGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -Xloggc:${HOME}/tomcat${PORT}/logs/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${HOME}/tomcat${PORT}/heapdump.bin"export JAVA_HOME CATALINA_HOME CATALINA_PID TOMCAT_USER JAVA_OPTSstart(){ ${CATALINA_HOME}/bin/daemon.sh start prog_ppid=`(cat ${CATALINA_PID}|grep -o "[^ ]\+\( \+[^ ]\+\)*") 2>/dev/null` echo -e "Host: $(hostname) Pid: ${prog_ppid:-"None"} Prog: ${CATALINA_HOME} Status: start"}stop(){ prog_ppid=`(cat ${CATALINA_PID}|grep -o "[^ ]\+\( \+[^ ]\+\)*") 2>/dev/null` ${CATALINA_HOME}/bin/daemon.sh stop echo -e "Host: $(hostname) Pid: ${prog_ppid:-"None"} Prog: ${CATALINA_HOME} Status: stop"}status(){ prog_ppid=`(cat ${CATALINA_PID}|grep -o "[^ ]\+\( \+[^ ]\+\)*") 2>/dev/null` if [[ "X${prog_ppid}" == "X" ]];then echo -e "Host: $(hostname) Pid: ${prog_ppid:-"None"} Prog: ${CATALINA_HOME} Status: stop" else echo -e "Host: $(hostname) Pid: ${prog_ppid:-"None"} Prog: ${CATALINA_HOME} Status: start" fi}version(){ ${CATALINA_HOME}/bin/daemon.sh version}case "$1" in start) start exit $? ;; stop) stop exit $? ;; restart)stopstartexit $?;; status) status exit $? ;; version) versionexit $?;; *)echo "Usage: tomcat${PORT} {start|stop|restart|status|version}" exit $? esacexit 1
访问测试:
说明: 测试前修改/xm-workspace/xm-webs/xmcloud/tomcat8081/conf/server.xml中将Connector的port值改为80,尝试/etc/init.d/tomcat8081 restart重启访问测试