Automatically install periodic cleanup script on macOS and Linux
parent
47f63a488d
commit
305209e869
|
@ -0,0 +1 @@
|
|||
*/20 * * * * /Users/jenkins/cleanup-and-reboot.sh
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue