Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart Jenkins slave from master

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.

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?

How can we accomplish it?

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

like image 711
Praneeth Avatar asked Mar 20 '15 11:03

Praneeth


People also ask

How do I restart Jenkins master slave?

2) From a command window, “shutdown /r /t 0” will restart the machine. If you're not running as a service you'll need to log in before the slave reconnects.


1 Answers

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%
like image 55
Tushar Dwivedi Avatar answered Oct 23 '22 11:10

Tushar Dwivedi