freedombone-logging 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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-2016 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 Affero 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 Affero General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU Affero General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. PROJECT_NAME='freedombone'
  30. export TEXTDOMAIN=${PROJECT_NAME}-logging
  31. export TEXTDOMAINDIR="/usr/share/locale"
  32. WEBSERVER_LOG_LEVEL='warn'
  33. if [ ! "$1" ]; then
  34. exit 1
  35. fi
  36. if [[ "$1" == "on" || "$1" == "On" || "$1" == "ON" ]]; then
  37. if [ -d /etc/nginx ]; then
  38. for filename in /etc/nginx/sites-available/* ; do
  39. filename_domain=$(echo "$filename" | awk -F '/' '{print $5}')
  40. sed -i "s|access_log.*|access_log /var/log/nginx/$filename_domain.access.log;|g" $filename
  41. sed -i "s|error_log.*|error_log /var/log/nginx/$filename_domain.err.log $WEBSERVER_LOG_LEVEL;|g" $filename
  42. done
  43. fi
  44. if [ -f /etc/init.d/spamassassin ]; then
  45. sed -i 's|DOPTIONS="-s null -d --pidfile=$PIDFILE"|DOPTIONS="-d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
  46. fi
  47. if [ -d /etc/prosody ]; then
  48. sed -i 's|info = "/dev/null";|info = "/var/log/prosody/prosody.log";|g' /etc/prosody/prosody.cfg.lua
  49. sed -i 's|error = "/dev/null";|error = "/var/log/prosody/prosody.err";|g' /etc/prosody/prosody.cfg.lua
  50. fi
  51. if [ -d /etc/exim4 ]; then
  52. sed -i 's|log_selector =.*|log_selector = MAIN_LOG_SELECTOR|g' /etc/exim4/conf.d/main/90_exim4-config_log_selector
  53. fi
  54. else
  55. if [ -d /etc/nginx ]; then
  56. for filename in /etc/nginx/sites-available/* ; do
  57. sed -i 's|access_log.*|access_log off;|g' $filename
  58. sed -i 's|warn_log.*|warn_log off;|g' $filename
  59. sed -i 's|error_log.*|error_log off;|g' $filename
  60. done
  61. shred -zu /var/log/nginx/*
  62. fi
  63. if [ -f /etc/init.d/spamassassin ]; then
  64. sed -i 's|DOPTIONS="-d --pidfile=$PIDFILE"|DOPTIONS="-s null -d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
  65. fi
  66. if [ -d /etc/prosody ]; then
  67. sed -i 's|info = "/var/log/prosody/prosody.log";|info = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  68. sed -i 's|error = "/var/log/prosody/prosody.err";|error = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  69. shred -zu /var/log/prosody/prosody.log
  70. shred -zu /var/log/prosody/prosody.err
  71. fi
  72. if [ -d /etc/exim4 ]; then
  73. sed -i 's|log_selector =.*|log_selector = -all|g' /etc/exim4/conf.d/main/90_exim4-config_log_selector
  74. fi
  75. fi
  76. if [ -d /etc/nginx ]; then
  77. service php5-fpm restart
  78. service nginx restart
  79. fi
  80. if [ -f /etc/init.d/spamassassin ]; then
  81. service spamassassin restart
  82. fi
  83. if [ -d /etc/prosody ]; then
  84. service prosody restart
  85. fi
  86. if [ -d /etc/exim4 ]; then
  87. service exim4 restart
  88. fi
  89. exit 0