freedombone-logging 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Turn logging on or off
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. if [ ! "$1" ]; then
  30. exit 1
  31. fi
  32. if [[ "$1" == "on" || "$1" == "On" || "$1" == "ON" ]]; then
  33. if [ -d /etc/nginx ]; then
  34. for filename in /etc/nginx/sites-available/* ; do
  35. filename_domain=$(echo "$filename" | awk -F '/' '{print $5}')
  36. sed -i "s|access_log.*|access_log /var/log/nginx/$filename_domain.access.log;|g" $filename
  37. sed -i "s|warn_log.*|warn_log /var/log/nginx/$filename_domain.warn.log;|g" $filename
  38. sed -i "s|error_log.*|error_log /var/log/nginx/$filename_domain.err.log;|g" $filename
  39. done
  40. fi
  41. if [ -f /etc/init.d/spamassassin ]; then
  42. sed -i 's|DOPTIONS="-s null -d --pidfile=$PIDFILE"|DOPTIONS="-d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
  43. fi
  44. if [ -d /etc/prosody ]; then
  45. sed -i 's|info = "/dev/null";|info = "/var/log/prosody/prosody.log";|g' /etc/prosody/prosody.cfg.lua
  46. sed -i 's|error = "/dev/null";|error = "/var/log/prosody/prosody.err";|g' /etc/prosody/prosody.cfg.lua
  47. fi
  48. if [ -d /etc/exim4 ]; then
  49. sed -i 's|log_selector =.*|log_selector = MAIN_LOG_SELECTOR|g' /etc/exim4/conf.d/main/90_exim4-config_log_selector
  50. fi
  51. else
  52. if [ -d /etc/nginx ]; then
  53. for filename in /etc/nginx/sites-available/* ; do
  54. sed -i 's|access_log.*|access_log off;|g' $filename
  55. sed -i 's|warn_log.*|warn_log off;|g' $filename
  56. sed -i 's|error_log.*|error_log off;|g' $filename
  57. done
  58. fi
  59. if [ -f /etc/init.d/spamassassin ]; then
  60. sed -i 's|DOPTIONS="-d --pidfile=$PIDFILE"|DOPTIONS="-s null -d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
  61. fi
  62. if [ -d /etc/prosody ]; then
  63. sed -i 's|info = "/var/log/prosody/prosody.log";|info = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  64. sed -i 's|error = "/var/log/prosody/prosody.err";|error = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  65. fi
  66. if [ -d /etc/exim4 ]; then
  67. sed -i 's|log_selector =.*|log_selector = -all|g' /etc/exim4/conf.d/main/90_exim4-config_log_selector
  68. fi
  69. fi
  70. if [ -d /etc/nginx ]; then
  71. service php5-fpm restart
  72. service nginx restart
  73. fi
  74. if [ -f /etc/init.d/spamassassin ]; then
  75. service spamassassin restart
  76. fi
  77. if [ -d /etc/prosody ]; then
  78. service prosody restart
  79. fi
  80. if [ -d /etc/exim4 ]; then
  81. service exim4 restart
  82. fi
  83. exit 0