Restart Jenkins slave from master

后端 未结 3 2115
梦如初夏
梦如初夏 2021-02-13 15:06

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 P

3条回答
  •  没有蜡笔的小新
    2021-02-13 15:32

    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 :

    For Windows Machines :

    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.

    For Mac Machines :

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

    2. 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:

    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%
    

提交回复
热议问题