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 :
- Create a job that simply runs "shutdown -r -f" on windows machines.
It will restart the machines.
- 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)
- Now the job restarts the machine and the Windows machine bring
itself online on Jenkins itself right after restart.
For Mac Machines :
The process is comparatively easier on mac. First, make a job to run
"shutdown -r now" on Mac node
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%