#!/bin/sh
umask 0027

echo "exec started post "

CheckPidFile()
{
	ps -ef | grep "/usr/sbin/keepalived -D --all" | while read line;
	do
		PID=$(echo $line | awk '{print $2}')
		FATHER=$(echo $line | awk '{print $3}')
		CMD=$(echo $line| awk '{print $8}')
		if [ $CMD = "/usr/sbin/keepalived" ] && [ $FATHER = "1" ]; then
			echo $PID > /run/keepalived.pid
		fi
	done
}

if [ -f /run/keepalived.pid ]; then
	echo $(/usr/bin/cat /run/keepalived.pid) > /run/keepalived.pid.save
else
	CheckPidFile
fi

if [ -f /run/checkers.pid ]; then
        echo $(/usr/bin/cat /run/checkers.pid) >> /run/keepalived.pid.save
else
	echo 0 >> /run/keepalived.pid.save

fi

if [ -f /run/vrrp.pid ]; then
        echo $(/usr/bin/cat /run/vrrp.pid) >> /run/keepalived.pid.save
else
	echo 0 >> /run/keepalived.pid.save
fi

exit 0

