v_update_sys_queue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # info: update system queue
  3. # options: pipe
  4. #
  5. # This function is responsible queue processing. Restarts of services,
  6. # scheduled backups, web log parsing and other heavy resource consuming
  7. # operations are handled by this script. It helps to optimize system behaviour.
  8. # In a nutshell Apache will be restarted only once even if 10 domains are
  9. # added or deleted.
  10. #----------------------------------------------------------#
  11. # Variable&Function #
  12. #----------------------------------------------------------#
  13. # Argument defenition
  14. pipe=$1
  15. # Importing system enviroment as we run this script
  16. # mostly by cron wich not read it by itself
  17. source /etc/profile.d/vesta.sh
  18. # Importing variables
  19. source $VESTA/conf/vars.conf
  20. source $V_CONF/vesta.conf
  21. source $V_FUNC/shared.func
  22. # Export PATH for cron
  23. PATH=$PATH:$V_BIN
  24. # Defining pipe functions
  25. restart_pipe() {
  26. for service in $(cat $V_QUEUE/restart.pipe |awk '!x[$0]++'); do
  27. v_restart_$service
  28. done
  29. echo > $V_QUEUE/restart.pipe
  30. }
  31. stats_pipe() {
  32. bash $V_QUEUE/stats.pipe
  33. }
  34. disk_pipe() {
  35. bash $V_QUEUE/disk.pipe
  36. }
  37. traff_pipe() {
  38. bash $V_QUEUE/traffic.pipe
  39. }
  40. backup_pipe() {
  41. for user in $(cat $V_QUEUE/backup.pipe |awk '!x[$0]++' ); do
  42. sed -i "/^$user$/d" $V_QUEUE/backup.pipe
  43. v_backup_user $user
  44. # Send notification to user
  45. done
  46. }
  47. #----------------------------------------------------------#
  48. # Verifications #
  49. #----------------------------------------------------------#
  50. # Checking arg number
  51. check_args '1' "$#" 'pipe'
  52. # Checking argument format
  53. format_validation 'pipe'
  54. #----------------------------------------------------------#
  55. # Action #
  56. #----------------------------------------------------------#
  57. case $pipe in
  58. restart) restart_pipe ;;
  59. stats) stats_pipe ;;
  60. backup) backup_pipe ;;
  61. disk) disk_pipe ;;
  62. traffic) traff_pipe ;;
  63. *) check_args '1' '0' 'pipe'
  64. esac
  65. #----------------------------------------------------------#
  66. # Vesta #
  67. #----------------------------------------------------------#
  68. # Logging
  69. log_event 'system' "$V_EVENT"
  70. exit