Skip to content
Snippets Groups Projects
Commit 7f01135b authored by William (Bill) E. Allcock's avatar William (Bill) E. Allcock
Browse files

adding the node clean up script; provided by HPE, modified by me

parent 7b033389
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
shopt -s extglob
RET=0
AVOIDUIDS="messagebus|nobody|nscd|ntp|postfix|root|USER|dbus|nslcd|polkitd|rpc|rpcuser|munge|nvidia-persistenced|chrony|pbsdata|statd"
# Print usage banner
function usage ()
{
echo "Usage: $0 [OPTION]"
echo " -p run prologue modules"
echo " -e run epilogue modules"
echo " -c run cleaning modules"
}
###############################################################################
# Clean up functions
###############################################################################
function clean_tmp ()
{
logger "Cleaning /tmp"
find /tmp ! -user root -exec rm -rf {} \; &> /dev/null
}
function clean_shared_mem ()
{
logger "Cleaning shared memory"
# Clean semaphores
for i in `ipcs -s | grep -v root | grep -v pbsdata | awk '{print $2}' | grep ^[0-9]`
do
ipcrm -s $i &> /dev/null
done
# Clean shared mem
for i in `ipcs -m | grep -v root | grep -v pbsdata | awk '{print $2}' | grep ^[0-9]`
do
ipcrm -m $i &> /dev/null
done
}
function clean_user_procs ()
{
logger "Cleaning stray processes" -semaphores
for i in `ps --no-headers -eo euser | egrep -v "${AVOIDUIDS}" | sort | uniq`
do
logger "Killing $i processes..."
pkill -9 -u $i &>/dev/null
done
}
function clean_dev_shm ()
{
cwd=$PWD
cd /dev/shm
rm -rf -v !("lldpad.state") &>/dev/null
cd $cwd
}
function clean_memory_cache ()
{
logger "Flushing caches"
# sync; echo 1 > /proc/sys/vm/drop_caches
# sync; echo 2 > /proc/sys/vm/drop_caches
sync; echo 3 > /proc/sys/vm/drop_caches
}
function print_job_start ()
{
logger -t PBSJOBSTART_$1 "PBS Job $1 started by $2"
}
function print_job_end ()
{
logger -t PBSJOBEND_$1 "PBS Job $1 completed by $2"
}
###############################################################################
# Main Script
###############################################################################
# Verify and process cmd line options
if [ $# -lt 1 ]
then
usage
exit 1
fi
case $1 in
-p)
logger -t PROLOGUE_CLEANUP_START_$2 "Starting prologue cleanup"
# Add the user to the list of user procs to avoid
AVOIDUIDS+="|$3"
clean_tmp
clean_shared_mem
clean_user_procs
clean_dev_shm
clean_memory_cache
logger -t PROLOGUE_CLEANUP_END_$2 "Completed prologue cleanup"
print_job_start "$2" "$3"
;;
-e)
logger -t EPILOGUE_CLEANUP_START_$2 "Starting epilogue cleanup"
print_job_end "$2" "$3"
clean_tmp
clean_shared_mem
clean_user_procs
clean_dev_shm
clean_memory_cache
logger -t EPILOGUE_CLEANUP_END_$2 "Completed epilogue cleanup"
;;
-c)
echo "Running epilogue modules..."
clean_tmp
clean_shared_mem
clean_user_procs
clean_dev_shm
clean_memory_cache
logger -t EPILOGUE_CLEANUP_END "The epilogue cleanup has completed"
;;
*)
usage
RET=1
;;
esac
exit $RET
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment