daemontools on a nfs share

When the daemontools services reside on a nfs share and the nfs share becomes stale, sometimes the services won’t recover even when the nfs problem was solved.
This can be due to some stale nfs lock files. This script fixes that.

#!/bin/bash
IFS_BUFFER=$IFS
IFS="
";
for ENTRY in $(ls -l /service); do
	SERVICE_NAME=$(echo $ENTRY|awk '{print $9}')
	if [ "$SERVICE_NAME" == "" ]; then
		continue;
	fi
	LINK_TARGET=$(echo $ENTRY|awk '{print $11}')
	# take service down (even when it's broken)
	$(svc -d /service/$SERVICE_NAME)
	# deactivate service
	cd /service/$SERVICE_NAME && rm -f /service/$SERVICE_NAME && svc -dx . log
	# remove all supervise directories
	for SUPERVISE_DIR in $(find $LINK_TARGET -name supervise); do
		# check for nfs lock files
		if [ $(ls -lh $SUPERVISE_DIR/.nfs*|wc -l) -gt 0 ]; then
	   	     	# kill possible remaining supervise services
       			for OPEN_FILE in $(lsof $SUPERVISE_DIR/.nfs*); do
				if [ "OPEN_FILES" == "" ]; then
					continue;
				fi
				# get PID
				SERVICE_PID=$(echo $OPEN_FILE|awk '{print $2}');
				if [ "$SERVICE_PID" == "PID" ]; then
					continue
				fi
				kill -9 $SERVICE_PID
				break
			done
		fi
		# and delete directory 
		rm -r $SUPERVISE_DIR
	done
	# remove stale lock files
	for LOCK_FILE in $(find $LINK_TARGET -name lock -type f); do
		rm $LOCK_FILE
	done
	# reactivate service
	ln -s $LINK_TARGET /service/$SERVICE_NAME
done
Dieser Beitrag wurde unter /dev/administration veröffentlicht. Setze ein Lesezeichen auf den Permalink.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.