levanta_freeradius 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. PATH="$PATH:/usr/local/sbin:/usr/sbin"
  3. udomain=`hostname -d`
  4. uhostname=`hostname`
  5. uFecha=`date +%b" "%_d" "%H:%M:%S`
  6. uNameService="freeradius"
  7. uSubject="subject: $uhostname $uNameService not running correctly?"
  8. uState="/tmp/$uNameService.down"
  9. uLog="/var/log/levanta_$uNameService"
  10. if [ ! -w $uLog ];
  11. then
  12. echo "WARNING: Archivo $uLog no existe. Creando..." ; touch $uLog;
  13. else
  14. if [ `du -k $uLog | cut -f 1` -gt 2000 ]; then echo "Archivo $uLog muy grande, vaciando" ; >$uLog; fi
  15. fi
  16. usendmail=$(which sendmail)
  17. if [ -z $usendmail ]; then echo "ERROR: Sendmail no detectado en el sistema. Sendmail instalado? Sendmail no detectado"; fi
  18. [ -r "$uState" ] && secondtime=$(cat $uState)
  19. greplines=`ps axc | awk '{print $NF}' | grep -c "$uNameService"`
  20. function show_status {
  21. echo "Number of proccess $uNameService=$greplines"
  22. }
  23. output="
  24. $uFecha: $uNameService RESTARTED:
  25. Log:
  26. $(show_status)
  27. $uNameService not running?. Restarting $uNameService."
  28. show_status
  29. if [ "$greplines" = 0 ]; then
  30. if [ "x$secondtime" == "x" ]
  31. then
  32. echo "$uNameService down!"
  33. echo "1" >$uState
  34. else
  35. echo $output >> $uLog
  36. #echo "$uSubject
  37. #$output
  38. #"| $usendmail -f root@$udomain soporte@cablenet.com.ar
  39. /etc/init.d/$uNameService restart || (/etc/init.d/$uNameService stop ; sleep 5 ; /etc/init.d/$uNameService start)
  40. echo "Restarting $uNameService!!!"
  41. fi
  42. else
  43. [ -r "$uState" ] && rm -f "$uState"
  44. echo "$uNameService OK"
  45. fi