v_update_sys_queue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. # Defining pipe functions
  23. restart_pipe() {
  24. for service in $(cat $V_QUEUE/restart.pipe |awk '!x[$0]++'); do
  25. $V_BIN/v_restart_$service
  26. done
  27. echo > $V_QUEUE/restart.pipe
  28. }
  29. stats_pipe() {
  30. bash $V_QUEUE/stats.pipe
  31. }
  32. disk_pipe() {
  33. bash $V_QUEUE/disk.pipe
  34. }
  35. traff_pipe() {
  36. bash $V_QUEUE/traffic.pipe
  37. }
  38. backup_pipe() {
  39. for user in $(cat $V_QUEUE/backup.pipe |awk '!x[$0]++' ); do
  40. sed -i "/^$user$/d" $V_QUEUE/backup.pipe
  41. bash $V_BIN/v_backup_user $user
  42. # Send notification to user
  43. done
  44. }
  45. #----------------------------------------------------------#
  46. # Verifications #
  47. #----------------------------------------------------------#
  48. # Checking arg number
  49. check_args '1' "$#" 'pipe'
  50. # Checking argument format
  51. format_validation 'pipe'
  52. #----------------------------------------------------------#
  53. # Action #
  54. #----------------------------------------------------------#
  55. case $pipe in
  56. restart) restart_pipe ;;
  57. stats) stats_pipe ;;
  58. backup) backup_pipe ;;
  59. disk) disk_pipe ;;
  60. traffic) traff_pipe ;;
  61. *) check_args '1' '0' 'pipe'
  62. esac
  63. #----------------------------------------------------------#
  64. # Vesta #
  65. #----------------------------------------------------------#
  66. # Logging
  67. log_event 'system' "$V_EVENT"
  68. exit