#!/bin/sh
echo "STATUS: Getting Storage Controller logs ..."

# This is to keep the systracker from cleaning up the getlogs.progress file while
# we're still trying to get sc logs.
echo "[action:post]" >> /mnt/ramdisk/getlogs.progress

cd /mnt/ramdisk
source /app/etc/app.env
mydate=`date +%Y_%m_%d__%H_%M_%S`
logfifo=store_$mydate.logs
mkfifo /mnt/ramdisk/$logfifo
zip -q logs.zip $logfifo &
zippid=$!
su -c "wrapcli --cmd 'get logs /mnt/ramdisk/$logfifo $1 $2 $3 $4'" -s /bin/sh admin > /dev/null
rc=$?
if [ $rc -eq 0 ]
then
    echo "STATUS: Finished getting Storage Controller logs"
else
    # This is required to make the zip file process end.
    pidof zip | grep -q "$zippid"
    if [ $? -eq 0 ]
    then 
        test -p $logfifo && echo "ERROR: Failed to obtain Storage Controller logs - Application not responding." > $logfifo
    fi
    
    echo "ERROR: Failed to obtain Storage Controller logs - Application not responding."
    echo ""
    echo "Wait a few minutes and then retry the get logs operation."
    echo "If it fails again, restart the Management Controller that you are logged into"
    echo "and then retry the get logs operation."
    echo "If it fails again and the partner controller is accessible, log into that"
    echo "controller and retry the getlogs operation."
    echo ""
    echo "STATUS: The system will continue to collect available logs."
fi
rm /mnt/ramdisk/$logfifo
exit $rc

