从主机重启Jenkins从机 [英] Restart Jenkins slave from master

查看:127
本文介绍了从主机重启Jenkins从机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jenkins主从配置来捕获产品的性能指标.我们已经观察到詹金斯-奴隶倾向于积累内存,从而影响捕获的性能指标.

I use jenkins master-slave configuration for capturing Performance metrics of a product. We have observed that jenkins-slave tends to accumulate memory and thus influences the Performance metrics being captured.

为了确保所捕获指标的一致性,我们正在考虑在从属服务器上没有任何作业运行时,每天从主服务器重新启动jenkins从属服务器.这可行吗?

To ensure consistency of the metrics being captured, we are thinking of restarting jenkins slave every day from the master, when there are no jobs running on the slave. Is this feasible?

我们如何做到呢?

注意:不能将jenkins-slave作为服务使用,因为我们还有其他安全访问问题.

Note: Using jenkins-slave as a service is not an option because we are having other security access issues with it.

推荐答案

我知道这个答案来得有点晚:

I know this answer is coming in a bit late :

出于相同的原因,这是我做同样的事情,不确定这是否是实现此目的的最佳方法,但是它解决了我们的许多问题:

This is how I did the same for the same reasons, not sure if this is the best way to achieve this, but it solved many of our problems :

对于Windows计算机:

  1. 创建一个仅在Windows计算机上运行"shutdown -r -f"的作业. 它将重新启动计算机.
  2. 现在将其恢复为在线状态.出于与您类似的原因,我 没有使用詹金斯-奴隶即服务".相反,我配置了 节点通过JNLP客户端进行连接,然后添加slave.jar Windows的任务计划程序中每个节点的命令(在 启动)
  3. 现在,作业将重新启动计算机,Windows计算机将重新启动计算机. 重新启动后立即在Jenkins自身上在线运行.
  1. Create a job that simply runs "shutdown -r -f" on windows machines. It will restart the machines.
  2. Now bringing it back online part. For similar reasons as yours, I didn't use "jenkins-slave as a service". Instead I configured the nodes to connect via JNLP client, and then added the slave.jar command for each node in Window's task scheduler (to run on startup)
  3. Now the job restarts the machine and the Windows machine bring itself online on Jenkins itself right after restart.

对于Mac计算机:

  1. 在Mac上,该过程相对容易一些.首先,做好一份工作 在Mac节点上立即关闭-r"

  1. The process is comparatively easier on mac. First, make a job to run "shutdown -r now" on Mac node

应该仅将节点设置为通过ssh进行连接.那会 请注意将其在Jenkins上在线发布.

The node should simply be setup to get connected via ssh. That will take care of bringing it up online on Jenkins.

这是我脚本的执行外壳"部分,用于重新启动用于自动化的所有计算机:

This was the "execute shell" part of my script to restart all the machines used for our automation :

distro=`uname`
if [ "$distro" = "Windows_NT" ] || [ "$distro" = "WindowsNT" ] ;then
echo "Restarting Windows Machine...."
shutdown -r -f
else
echo "Restarting Mac Machine...."
sudo shutdown -r now
fi

PS:

它与问题不完全相关,但对于您指定的情况可能有用.在Windows计算机启动时添加批处理脚本以清理临时文件可能是一个好主意. 在Windows机器的启动文件夹中,将以下内容添加到批处理脚本中(例如,cleanTemp.bat). (对于Windows 10,C:\ Users \\ AppData \ Roaming \ Microsoft \ Windows \开始菜单\ Programs \ Startup)

It's not exactly related to the question, but may be useful for the situation that you specified. It may be a good idea to add a batch script to clean temp files on startup of Windows machines. Add following to a batch script (Say, cleanTemp.bat) in the startup folder of your Windows machine. (For Windows 10, C:\Users\\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup)

rmdir %temp% /s /q

md %temp%

这篇关于从主机重启Jenkins从机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆