Unverified Commit ab993ac3 authored by Mattia Rizzolo's avatar Mattia Rizzolo
Browse files

reproducible: don't be so trigger-happy in deleting schroot internal stuff,...


reproducible: don't be so trigger-happy in deleting schroot internal stuff, call to schroot -e to terminate the schroots instead

Signed-off-by: Mattia Rizzolo's avatarMattia Rizzolo <mattia@debian.org>
parent 878ada14
Loading
Loading
Loading
Loading
+44 −27
Original line number Diff line number Diff line
@@ -405,35 +405,52 @@ fi
# remove too old schroot session data from diffoscope
if [ "$HOSTNAME" = "$MAINNODE" ] ; then
	echo "$(date -u) - Removing diffoscope schroot session data older than 2 days."
	for path in session union/underlay union/overlay ; do
		dir=/var/lib/schroot/$path/
		if [ "$path" = "session" ] ; then
			FILETYPE=f
			RM=rm
		else
			FILETYPE=d
			RM=rmdir
		fi
		OLDSTUFF=$(find "$dir" -name "jenkins-reproducible-*-diffoscope-*" -mindepth 1 -maxdepth 1 -type $FILETYPE -mtime +1 -exec ls -lad {} \; || true)
		if [ ! -z "$OLDSTUFF" ]; then
			echo
			echo "data in $dir older than 2 days found, which will be deleted:"
			echo "$OLDSTUFF" | sed "s#$dir#./#g"

	mapfile -t OLDSTUFF < <(find /var/lib/schroot/session -name "jenkins-reproducible-*-diffoscope-*" -type f -mtime +1 -exec ls -lad {} \;)
	if [ "${#OLDSTUFF[@]}" -ne 0 ]; then
		echo
			find "$dir" -name "jenkins-reproducible-*-diffoscope-*" -mindepth 1 -maxdepth 1 -type $FILETYPE -mtime +1 -exec sudo $RM -v {} \; || true
			OLDSTUFF=$(find "$dir" -name "jenkins-reproducible-*-diffoscope-*" -mindepth 1 -maxdepth 1 -type $FILETYPE -mtime +1 -exec ls -lad {} \; || true)
			if [ ! -z "$OLDSTUFF" ]; then
				echo
				echo "Warning: Tried, but failed to delete these in $dir:"
				echo "$OLDSTUFF" | sed "s#$dir#./#g"
				echo "Manual cleanup needed."
			fi
		echo "Found old schroot (from diffoscope) sessions, which will be terminated now:"
		echo "${OLDSTUFF[@]}"
		echo
		for session_path in "${OLDSTUFF[@]}"; do
			# don't use `basename` because session_path contains the whole output from ls -l, not just the path
			session=${session_path##*/}
			if ! schroot --end-session -c "$session" ; then
				echo "Warning: failed to end schroot session: $session"
			DIRTY=true
			fi
		done
	fi
	# TODO: rewrite the below to not mess with schroot internals so happily.
	#       (i.e., it should verify first )hat those files aren't referenced in sessions files first of all)
	#for path in session union/underlay union/overlay ; do
	#	dir=/var/lib/schroot/$path/
	#	if [ "$path" = "session" ] ; then
	#		FILETYPE=f
	#		RM=rm
	#	else
	#		FILETYPE=d
	#		RM=rmdir
	#	fi
	#	OLDSTUFF=$(find "$dir" -name "jenkins-reproducible-*-diffoscope-*" -mindepth 1 -maxdepth 1 -type $FILETYPE -mtime +1 -exec ls -lad {} \; || true)
	#	if [ ! -z "$OLDSTUFF" ]; then
	#		echo
	#		echo "data in $dir older than 2 days found, which will be deleted:"
	#		echo "$OLDSTUFF" | sed "s#$dir#./#g"

	#		echo
	#		find "$dir" -name "jenkins-reproducible-*-diffoscope-*" -mindepth 1 -maxdepth 1 -type $FILETYPE -mtime +1 -exec sudo $RM -v {} \; || true
	#		OLDSTUFF=$(find "$dir" -name "jenkins-reproducible-*-diffoscope-*" -mindepth 1 -maxdepth 1 -type $FILETYPE -mtime +1 -exec ls -lad {} \; || true)
	#		if [ ! -z "$OLDSTUFF" ]; then
	#			echo
	#			echo "Warning: Tried, but failed to delete these in $dir:"
	#			echo "$OLDSTUFF" | sed "s#$dir#./#g"
	#			echo "Manual cleanup needed."
	#		fi
	#		echo
	#		DIRTY=true
	#	fi
	#done
fi

# cleanup old schroots
cleanup_old_schroots() {
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ warning /Warning: .+ is not a source package, or was removed or renamed. Please
warning /Warning: Download of .+ sources failed./
warning /Warning: .+ contains invalid yaml, please fix./
warning /Warning: lock .+ still exists, exiting./
warning /^Warning: failed to end schroot session:/
warning /Warning: Tried, but failed to delete these/
warning /Warning: processes found which should not be there/
warning /Warning: found reproducible_build.sh processes which have pid 1 as parent.+/