#!/bin/bash # # only-one-cfexecd.cron # # Description: This script cleans up Cfengine cf-execd processes, in # case there are more than one of them running. # # Author: Trond Hasle Amundsen # # Set proper path PATH=/bin:/sbin:/usr/bin:/usr/sbin export PATH # Find the number of cf-execd processes num=$(pidof cf-execd | wc -w) # Fix if needed if [ $num -gt 1 ]; then hostname=$(hostname) tmpfile=$(mktemp) ( echo "DEBUG: Stopping cf-execd (service cf-execd stop):" service cf-execd stop echo "DEBUG: Killing remaining cf-execd processes (killall cf-execd):" killall -v cf-execd echo "DEBUG: Starting cf-execd (service cf-execd start):" service cf-execd start ) >$tmpfile 2>&1 new_num=$(pidof cf-execd | wc -w) if [ $new_num -gt 1 ]; then echo "$hostname had $num cf-execd processes running." echo "There should be only one." echo echo "Tried restarting cf-execd, but something went wrong." echo "After restart there are $new_num cf-execd processes running.." echo "Debug output follows:" echo cat $tmpfile fi rm $tmpfile fi # Exit properly exit 0