Jenkins with Publish over SSH插件,-1退出状态

时间:2016-02-09 19:35:20

标签: jenkins ssh

我使用Jenkins构建和插件来将我的工件部署到服务器。部署文件后,我通过在插件中调用eec来停止服务

SSH: EXEC: channel open
SSH: EXEC: STDOUT/STDERR from command [sudo service myservice stop]...
SSH: EXEC: connected
Stopping script myservice
SSH: EXEC: completed after 200 ms
SSH: Disconnecting configuration [172.29.19.2] ...
ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [-1]]
Build step 'Send build artifacts over SSH' changed build result to UNSTABLE
Finished: UNSTABLE

我收到来自Publish over SSH的答案:

#! /bin/sh
# /etc/init.d/myservice
#
# Some things that run always
# touch /var/lock/myservice
# Carry out specific functions when asked to by the system
case "$1" in
  start)
      echo "Starting myservice"
      setsid /opt/myservice/bin/myservice --spring.config.location=/etc/ezd/application.properties --server.port=8082 >> /opt/myservice/app.log &
  ;;
  stop)
      echo "Stopping script myservice"
      pkill -f myservice 
      #
  ;;
  *)
      echo "Usage: /etc/init.d/myservice {start|stop}"
      exit 1
  ;;
esac
exit 0

构建失败但服务已停止。

我的/etc/init.d/myservice

z-menu-item-inner-r"><span class="z-menu-item-space"></span></td></tr></tbody></table></a></td><td id="z_e6_mm" align="left" z.type="Menuit2" class="z-menu-item " style="padding-left:4px;padding-right:4px;" z.zcls="z-menu-item" z.top="true"><a href="/NTS/NTSBatchJobs.zul" class="z-menu-item-cnt"><table id="z_e6_mm!a" cellspacing="0" cellpadding="0" border="0" class="z-menu-item-body " style="width: auto;"><tbody><tr><td class="z-menu-item-inner-l"><span class="z-menu-item-space"></span></td><td class="z-menu-item-inner-m"><div><button id="z_e6_mm!b" type="button" class="z-menu-item-btn">**HIT ME**&nbsp;</button></div></td><td class="

请说我为什么得到-1退出状态?

2 个答案:

答案 0 :(得分:2)

嗯,该脚本名为/etc/init.d/myservice,因此它与myservice给出的pkill -f模式相匹配。并且因为脚本正在等待pkill完成,它仍处于活动状态并被杀死并因此返回-1(等待结果中也有杀死信号,但Jenkins奴隶守护程序不是&# 39;打印它。)

或者:

  • 为pkill提出了更具体的模式,
  • 使用正确的pid文件或
  • 切换到systemd,它可以可靠地完全杀死它开始的进程。

在这个时代,我推荐最后一个选项。 Systemd比init脚本更可靠。

答案 1 :(得分:1)

是的,Jan Hudec是对的。我通过SSH插件在Publish中调用ps ax | grep myservice

 83469 pts/5    Ss+    0:00 bash -c ps ax | grep myservice service myservice stop  

所以pkill -f myservice将影响PID 83469的过程,PID 83469是pkill的父级。据我所知,这是-1状态原因。

我将pkill -f myservice更改为pkill -f "java.*myservice",这解决了我的问题。