Automatically install periodic cleanup script on macOS and Linux

pull/5648/head
Thomas Stromberg 2019-10-17 12:19:43 -07:00
parent 47f63a488d
commit 305209e869
8 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1 @@
*/20 * * * * /Users/jenkins/cleanup-and-reboot.sh

View File

@ -0,0 +1,39 @@
#!/bin/bash
# Periodically cleanup and reboot if no Jenkins subprocesses are running.
#
# Installation:
# install cleanup-and-reboot.linux /etc/cron.hourly/cleanup-and-reboot
function check_jenkins() {
jenkins_pid="$(pidof java)"
if [[ "${jenkins_pid}" = "" ]]; then
return
fi
pstree "${jenkins_pid}" \
| grep -v java \
&& echo "jenkins is running at pid ${jenkins_pid} ..." \
&& exit 1
}
check_jenkins
logger "cleanup-and-reboot running - may shutdown in 60 seconds"
wall "cleanup-and-reboot running - may shutdown in 60 seconds"
sleep 60
check_jenkins
logger "cleanup-and-reboot is happening!"
# kill jenkins to avoid an incoming request
killall java
# disable localkube, kubelet
systemctl list-unit-files --state=enabled \
| grep kube \
| awk '{ print $1 }' \
| xargs systemctl disable
# update and reboot
apt update -y \
&& apt upgrade -y \
&& reboot

View File

@ -30,5 +30,7 @@ VM_DRIVER="kvm2"
JOB_NAME="KVM_Linux"
PARALLEL_COUNT=4
install cron/cleanup-and-reboot.linux /etc/cron.hourly/cleanup-and-reboot
# Download files and set permissions
source ./common.sh

View File

@ -50,5 +50,7 @@ systemctl is-active --quiet kubelet \
&& echo "stopping kubelet" \
&& sudo systemctl stop kubelet
install cron/cleanup-and-reboot.linux /etc/cron.hourly/cleanup-and-reboot
# Download files and set permissions
source ./common.sh

View File

@ -30,5 +30,7 @@ VM_DRIVER="virtualbox"
JOB_NAME="VirtualBox_Linux"
PARALLEL_COUNT=4
install cron/cleanup-and-reboot.linux /etc/cron.hourly/cleanup-and-reboot
# Download files and set permissions
source ./common.sh

View File

@ -33,5 +33,8 @@ EXTRA_ARGS="--bootstrapper=kubeadm"
EXTRA_START_ARGS=""
PARALLEL_COUNT=3
install cron/cleanup_and_reboot_Darwin.sh $HOME/cleanup_and_reboot.sh
crontab < cron/Darwin.crontab
# Download files and set permissions
source common.sh

View File

@ -31,5 +31,8 @@ JOB_NAME="VirtualBox_macOS"
EXTRA_ARGS="--bootstrapper=kubeadm"
PARALLEL_COUNT=3
install cron/cleanup_and_reboot_Darwin.sh $HOME/cleanup_and_reboot.sh
crontab < cron/Darwin.crontab
# Download files and set permissions
source common.sh