jenkins使用ssh remote插件执行shell后无法退出的问题处理

摘要:
=“apache”];netechexit1ficd/data/www/vhosts/test-api location.aa.me/httpdocs/geo&2exit1FIPT=$1case$OPT龄)echo“start`basename$0`”start_geo;重启)restart_ geoexit0;status)状态_地理;

现象:通过jenkins发布代码后,执行远程命令,一直卡在执行远程命令那里打转,无法退出

脚本

#!/bin/bash

# 根据参数,执行进程的启动 停止 重启等
#source /etc/profile

# 非apache用户运行脚本,则退出
if [ `whoami` != "apache" ];then
echo " only apache can run me"
exit 1
fi


process='bin/geo'

##############$process###############
#1.启动 $process
start_geo() {
    sleep 1
    pid=`ps -ef |grep $process |grep -v grep |awk '{print $2}'`
    if [ ! "$pid" ];then
        echo "Starting $process process is $process;pid is $pid "
        if [ $? -ne 0 ]; then
            echo
            exit 1
        fi
        cd /data/www/vhosts/test-api-location.aa.me/httpdocs/geo && nohup /data/www/vhosts/test-api-location.aa.me/httpdocs/geo/$process --config=config/uat_config.toml >/dev/null 2>&1 &
    sleep 2
    swoft_nu=`netstat -tnlp|grep 20109|wc -l`
        if [[ $? == 0 && ${swoft_nu} -ge 1 ]];then
            echo "start $process $process ok"
        else
            echo "start $process $process failed"
        fi
    else
        echo "$process $process is still running!"
        exit
    fi
}

#2.停止 $process
stop_geo() {
    echo -n $"Stopping $process $process: "
    pid=`ps -ef |grep $process |grep -v grep |awk '{print $2}'`
    if [ ! "$pid" ];then
    echo "$process $process is not running"
    else
        ps -ef|grep ${process}|grep -v grep|awk '{print $2}'|xargs kill -9
    sleep 2
    swoft_nu=`netstat -tnlp|grep 20109|wc -l`
    if [[ ${swoft_nu} -lt 1 ]];then
        echo "stop $process $process ok killed $pid"
    fi
    fi
}

#3.重启 restart_geo
restart_geo() {
    stop_geo
    start_geo
}

#4.查看 $process 状态
status_geo(){
    pid=`ps -ef |grep $process |grep -v grep |awk '{print $2}'`
    if [ ! "$pid" ];then
        echo "geo $process is not running"
    else
        echo "geo $process is running"
    fi
}

#####################  MAIN  ###############################
usage () {
        echo ""
        echo "  Please Input server infomation!"
        echo ""
        echo "  USAGE: `basename $0` [start|stop|restart|status]" 
        echo ""
}
    

if [ $# != 1 ]
then
        usage >&2
        exit 1
fi
OPT=$1
case $OPT in
 
start)
        echo "start `basename $0`"
        start_geo
    ;;
stop)
        stop_geo
    ;;
restart)
        restart_geo
    exit 0
    ;;
status)
        status_geo
    ;;
*)
    echo "Usage:`basename $0`  [start|stop|restart|status]"
    exit 1
esac

jenkins使用ssh remote插件执行shell后无法退出的问题处理第1张

网上有说加 exit 0,或者去掉 source /etc/profile,加nohup或者sleep 1都无效,是因为没有使用终端无法正常退出,否则程序会终止,勾选pty即可

jenkins使用ssh remote插件执行shell后无法退出的问题处理第2张

免责声明:文章转载自《jenkins使用ssh remote插件执行shell后无法退出的问题处理》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇python中 array 和 list 不同场景效率对比mysql的event(事件)用法详解下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

文件上传inputstream转为multipartfile

方式一 CommonsMultipartFile pom <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload --> <dependency> <groupId>commons-fileupload</g...

Vue-router(基础)_滚动行为和history模式

一、前言                                                                                                                   1、滚动事件                                2、h5 history模式 二、主要内容 ...

Prometheus自定义指标

1.  自定义指标 为了注册自定义指标,请将MeterRegistry注入到组件中,例如: public class Dictionary { private final List<String> words = new CopyOnWriteArrayList<>(); Dictionary(MeterRegi...

浅析muduo库中的线程设施

muduo是目前我在学习过程中遇到的最具有学习意义的网络库,下文将分析muduo库中的基础设施--Thread和ThreadPool. 首先,介绍在多线程编程中不可缺少的同步措施--Mutex和Condition. Mutex /***Mutex.h***/ class MutexLock : boost::noncopyable { public:...

node.js和express.js中添加验证码

验证码在平时访问网站中非常常见,能够有效的避免机器操作,恶意攻击 比如:学信网中https://www.chsi.com.cn/ 用户输入三次密码不正确的时候,再输入密码提交的时候就该提醒你输入验证码,那为什么会存在验证码,验证码是怎么运作的呢? 抱歉,画的有点像鬼画符,哈哈,总结来说就是,生成验证码后会在cookie中存储验证码,然后再用验证码生成一张...

ElementUI的el-select怎样实现下拉多选并实现给下拉框赋值和获取值

场景 要实现的效果如下 官方示例代码实现多选 为el-select设置multiple属性即可启用多选,此时v-model的值为当前选中值所组成的数组。 默认情况下选中值会以 Tag 的形式展现,你也可以设置collapse-tags属性将它们合并为一段文字。 <template> <el-select v-model="valu...