All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
[Script] Stop container if loadavg is > x
Hi,
we have implemented this script in a cron every 15 minutes,
if some container has a high overload, we stop it.
I put here if someone is interested on it.
We have other version that checks the CTID in the SolusVM database and send a email to the customer.
Regards.
#! /bin/bash export PATH="/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin" maxload="10"; # put here the max loadavg permitted cat /dev/null > loads.txt; vzlist -o ctid,laverage > loads.txt; cat loads.txt | while read line; do vm=$(echo ${line:0:5}); load=$(echo ${line} | cut -d'/' -f3); load2=$(echo ${load} | cut -d'.' -f1); if [ $load2 -gt $maxload ] then echo "stopping $vm - $load"; vzctl stop $vm; echo "$vm - $load" | mail -s "$vm stopped for overload" [email protected] fi done
Comments
Why are you setting path?
@Daniel
because vzlist in not in the cron shell, you need export.
Fair enough.
Or... you could use the absolute path to vzlist...? It doesn't really matter, but you don't need to at all.
Also, you don't need to cat /dev/null >loads.txt because vzlist >loads.txt will truncate it automatically if it already has data.
Also, you don't need loads.txt anyway. Just "vzlist | while" instead of "vzlist >loads.txt; cat loads.txt | while"
@DimeCadmium
Again, he said this ">" operator does it already, and you don't need that line.
I meant vzlist. /usr/sbin/vzlist -o ctid,laverage (or wherever vzlist is).
It is. It is also empty on vzlist >loads.txt, as I said. (Thanks yomero)
(Also, temporary files traditionally go in /tmp instead of wherever the cronjob happens to be.)