Advertisement
deseven

isbilling

Sep 4th, 2015
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.62 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. _script="$(readlink -f ${BASH_SOURCE[0]})"
  4. _base="$(dirname $_script)"
  5. cd $_base
  6.  
  7. . isbilling.conf
  8.  
  9. if [ ! -z "$1" ]; then
  10.     echo $1 | /usr/bin/nc $bindhost $bindport
  11.     exit
  12. fi
  13.  
  14. cd $workdir
  15.  
  16. # redirecting errors to file
  17. exec 2>> logs/error.log
  18.  
  19. # functions
  20. . inc/func.sh
  21.  
  22. toLog INFO "started"
  23.  
  24. function checksum_tables() {
  25.     # checking tarifs,vgroups,staff in lb_base
  26.     action=$(execExt scripts/checksum_tables)
  27.     if [ "$action" == "1" ]; then
  28.         toLog INFO "tables has changed"
  29.     fi
  30.     catchError "checksum_tables"
  31. }
  32.  
  33. function asr_tasks() {
  34.     # checking asr tasks from asr_tasks in lb_base
  35.     tasks=$(execExt scripts/asr_tasks)
  36.     if [ "$tasks" != "0" ]; then
  37.         toLog INFO "executed $tasks tasks on ASR"
  38.     fi
  39.     catchError "asr_tasks"
  40. }
  41.  
  42. function dpi_tasks() {
  43.     # checking dpi tasks from dpi_tasks in lb_base
  44.     tasks=$(execExt scripts/dpi_tasks)
  45.     if [ "$tasks" != "0" ]; then
  46.         toLog INFO "executed $tasks tasks on DPI"
  47.     fi
  48.     catchError "dpi_tasks"
  49. }
  50.  
  51. function wrapper() {
  52.     while true; do
  53.         signal=""
  54.         read -t 1 signal
  55.         case "$signal" in
  56.             all)
  57.                 toLog INFO "forced all by signal"
  58.                 checksum_tables
  59.                 asr_tasks
  60.                 dpi_tasks
  61.                 ;;
  62.             asr_tasks)
  63.                 toLog INFO "forced asr_tasks by signal"
  64.                 asr_tasks
  65.                 ;;
  66.             dpi_tasks)
  67.                 toLog INFO "forced dpi_tasks by signal"
  68.                 dpi_tasks
  69.                 ;;
  70.         esac
  71.         sleep 1
  72.         sleeping=$((sleeping+2))
  73.         if [ "$sleeping" == "$sleeptime" ]; then
  74.             checksum_tables
  75.             asr_tasks
  76.             dpi_tasks
  77.             sleeping=0
  78.         fi
  79.     done
  80. }
  81.  
  82. coproc WRAP { wrapper; }
  83. writePID $$
  84.  
  85. while true; do
  86.     nc -l -k $bindhost $bindport <&${WRAP[0]} >&${WRAP[1]}
  87.     sleep 1
  88. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement