- 前提准备
- Build Steps
- 备注
- !/bin/bash
- PROJECT_PATH=/doc/program/smart/soul-admin.jar
- read -p “:” PROJECT_PATH
- echo “你输入的数是:$PROJECT_PATH”
- 设置环境参数
- -XX:+UseConcMarkSweepGC -XX:+UseParNewGC || -XX:+UseParallelGC -XX:+UseParallelOldGC
- 设置默认值
- shutdown
- startUp
- 判断jar包文件是否存在,如果存在启动jar包,并时时查看启动日志
- 启动jar包,指向日志文件,2>&1 & 表示打开或指向同一个日志文件
部署项目创建跟其他的部署相同,主要就是部署脚本
前提准备
- 登录VPN
- powershll 安装 Install-Module -Name Posh-SSH
- 参考 《PowerShell 脚本知识.md》
Build Steps
打包
clean package -DskipTests -Dmaven.javadoc.skip=true
上传JAR到服务器
function getCred ($username, $password) {
$pass = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $pass
return $cred
}
$server = '192.168.1.11'
$port = '11'
$username = '11'
$password = '1111'
$localFile = '%teamcity.build.workingDir%/target/detabes-file.jar'
$remotePath = '/peter/cqepc'
$cred = getCred -username $username -password $password
$session = New-SFTPSession -ComputerName $server -Port $port -Credential $cred -Force
Set-SFTPItem -SFTPSession $session -Destination $remotePath -Path $localFile -Force
Remove-SFTPSession -SFTPSession $session
- 参考 《PowerShell 脚本知识.md》
运行jar
function getCred ($username, $password) {
$pass = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $pass
return $cred
}
$server = '192.168.1.11'
$port = '11'
$username = '11'
$password = '11'
$cred = getCred -username $username -password $password
$session = New-SSHSession -ComputerName $server -Port $port -Credential $cred -Force
$javaPath = '/usr/local/java/'
## $cmd = 'uname -a'
## Invoke-SSHCommand -Command $cmd -SSHSession $session
Invoke-SSHCommand -Command 'cd /peter/cqepc/ && ./file-start-stop-auto.sh test' -SSHSession $session
#Start-Sleep -s 60
Remove-SSHSession -SSHSession $session
备注
PROJECT_PATH=/doc/program/smart/soul-admin.jar
read -p “:” PROJECT_PATH
echo “你输入的数是:$PROJECT_PATH”
export JAVA_HOME=/usr/local/java export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PROJECT_PATH=/peter/cqepc/detabes-file.jar PROJECT_PROPERTIES=${1} PROJECT_PORT=9002
设置环境参数
JAVA_OPTS=” -Xms512m “
-XX:+UseConcMarkSweepGC -XX:+UseParNewGC || -XX:+UseParallelGC -XX:+UseParallelOldGC
JAVA_OPTS=”${JAVA_OPTS} -Xmx1024m -Xmn512m -XX:+UseParallelGC -XX:+UseParallelOldGC “ JAVA_OPTS=”${JAVA_OPTS} -Dfile.encoding=UTF-8”
设置默认值
if [ ! $PROJECT_PATH ]; then PROJECT_PATH=”detabes-file.jar” fi
if [ ! $PROJECT_PORT ]; then SERVER_PORT=” —server.port=9002” else SERVER_PORT=” —server.port=${PROJECT_PORT}” fi
if [ ! $PROJECT_PROPERTIES ]; then SERVER_PROPERTIES=”—spring.profiles.active=prod” else SERVER_PROPERTIES=”—spring.profiles.active=${PROJECT_PROPERTIES}” fi
shutdown
pid=ps -ef|grep $PROJECT_PATH | grep -v grep | awk '{print $2}'
kill -9 $pid
echo “$pid进程终止成功”
sleep 1
startUp
sleep 2
判断jar包文件是否存在,如果存在启动jar包,并时时查看启动日志
if test -e $PROJECT_PATH then echo ‘文件存在,开始启动此程序…’
启动jar包,指向日志文件,2>&1 & 表示打开或指向同一个日志文件
echo “nohup java -jar $JAVA_OPTS “$PROJECT_PATH” $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &” nohup java -jar $JAVA_OPTS $PROJECT_PATH $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &
echo “$PROJECT_PATH 启动成功…”
else echo “$PROJECT_PATH 文件不存在,请检查。” fi ```