将java程序打包成一个service并开机自启动

#!/bin/sh
#chkconfig: 345 99 61
#Source function library.
#description: zweb
if [ -f /etc/rc.d/init.d/functions ]; then
{
	. /etc/rc.d/init.d/functions
}
fi

. /etc/profile.d/zh9000.sh
cd $ZH9000_HOME/zweb


checkJavaStatus()
{
	pid=$(jps -lv | grep $2 | grep -v grep | awk '{print $1}' | xargs)
	if [ "x${pid}" != "x" ]; then
	{
		echo "$1 (pid $pid) is running..."
	}
	else
	{
		echo "$1 is dead..."
	}
	fi
}



case "$1" in
start)
	./wf.sh start
	;;
stop)
	./wf.sh stop
	;;
restart)
	$0 stop
	$0 start
	;;
status)
	./wf.sh status
	;;
esac

写好后,将该文件放置到/etc/init.d/中。
协商好cd $ZH9000_HOME/zweb 路径,具体启动脚本wf.sh的目录

最后,service zweb start;启动服务

你可能感兴趣的:(后端)