linux shell 启动脚本

1. 需求

启动java程序要带很多参数,所以要脚本化。
停掉指定的程序,需要先用ps aux查出来pid,再对其进行kill。这两步操作期望用脚本完成。
重启该服务,即上面两个脚本的组合。

2. 启动例子

#!/bin/bash
nohup java -server -Xms512m -Xmx512m -Xmn256m -XX:CMSInitiatingOccupancyFraction=60 -XX:SurvivorRatio=8 -cp BWGRecheckServer.jar com.likeyichu.search.antibot.bwgrecheck.entry.BWGRecheckServer >/dev/null 2>BWGRecheck.error.log 1>/dev/null 2>&1 &

3.停止例子

#!/bin/sh
server_name="BWGRecheckServer"
function killServer(){
	server_pid=`ps aux | grep ${server_name} | grep -F 'java' | head -1 | awk '{print $2}' `;
	kill ${server_pid};
	echo 'kill  '${server_pid}' done!';
}
function preJudge(){
	server_isExist=`ps aux | grep ${server_name} | grep -F 'java' | head -1 | awk '{print $2}'|wc -l`;
	if [ ${server_isExist} -eq 0 ];then
		echo 'not exists such process';
		exit;		
	fi;
}
preJudge; 
killServer;


#:deploy   24401  0.8  1.0 3326716 331504 pts/1  Sl   09:37   2:40 java -server -Xms512m -Xmx512m -Xmn256m -XX:CMSInitiatingOccupancyFraction=60 -XX:SurvivorRatio=8 -cp BWGRecheckServer.jar com.ctrip.search.antibot.bwgrecheck.entry.BWGRecheckServer

4.重启例子

#!/bin/bash

你可能感兴趣的:(Linux,java-打包,部署)