From abf68e19e5c2daf98ccb494e2bcdf609b269cbe1 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Wed, 5 Aug 2015 19:14:03 +0200 Subject: [PATCH] library/roles/mysql: Fix the backup script. Now it finds the installed databases in a sane way. library/roles/nginx: Option to activate the gzip compression. --- mediawiki/defaults/main.yml | 1 + mysql/defaults/main.yml | 1 + mysql/files/mysql-backup.sh | 39 ++++++++++++------------- mysql/templates/mysql_backup-default.j2 | 2 ++ nginx/defaults/main.yml | 8 +++++ nginx/tasks/nginx.yml | 23 ++++++++------- 6 files changed, 42 insertions(+), 32 deletions(-) diff --git a/mediawiki/defaults/main.yml b/mediawiki/defaults/main.yml index 26dc76c3..47b87079 100644 --- a/mediawiki/defaults/main.yml +++ b/mediawiki/defaults/main.yml @@ -16,6 +16,7 @@ mw_php_prereq: - php5-mysqlnd - php-apc - php-pear + - php5-ldap - imagemagick # This choice is not recommended. The package has a poor list of dependencies. We do not want to deal with those diff --git a/mysql/defaults/main.yml b/mysql/defaults/main.yml index 21a3e9e6..cdea08a8 100644 --- a/mysql/defaults/main.yml +++ b/mysql/defaults/main.yml @@ -43,4 +43,5 @@ mysql_backup_logdir: '{{ mysql_log_dir }}' mysql_backup_logfile: '{{ mysql_backup_logdir }}/my_backup.log' mysql_backup_retain_copies: 15 mysql_backup_destdir: /var/lib/mysql-backup +mysql_backup_exclude_list: "performance_schema" diff --git a/mysql/files/mysql-backup.sh b/mysql/files/mysql-backup.sh index e08cbb74..463bebad 100644 --- a/mysql/files/mysql-backup.sh +++ b/mysql/files/mysql-backup.sh @@ -6,6 +6,8 @@ MY_BACKUP_USE_NAGIOS="False" MY_BACKUP_DIR=/var/lib/mysql-backup MY_DATA_DIR=/var/lib/mysql N_DAYS_TO_SPARE=7 +# Exclude list +EXCLUDE_LIST='performance_schema' if [ -f /etc/default/mysql_backup ] ; then . /etc/default/mysql_backup @@ -33,33 +35,28 @@ fi chmod 700 $MY_BACKUP_DIR LOCKFILE=$MY_DATA_DIR/.mysqldump.lock NAGIOS_LOG=$MY_BACKUP_DIR/.nagios-status -# Exclude list -EXCLUDE_LIST='performance_schema' if [ ! -f $LOCKFILE ] ; then touch $LOCKFILE if [ "${MY_BACKUP_USE_NAGIOS}" == "True" ] ; then > $NAGIOS_LOG fi - for db in $( /bin/ls -1 /var/lib/mysql/ | grep -v $EXCLUDE_LIST ) ; do - if [ -d /var/lib/mysql/$db ] ; then - #mysqldump -uroot -f --opt -p$MYSQLPASS $db > $MY_BACKUP_DIR/$db.sql 2> $MY_BACKUP_DIR/log/$db.log - mysqldump -f --opt $db > $MY_BACKUP_DIR/history/${db}.sql.${SAVE_TIME} 2> $MY_BACKUP_LOG_DIR/$db.log - DUMP_RESULT=$? - chmod 600 $MY_BACKUP_DIR/history/${db}.sql.${SAVE_TIME} - if [ "${MY_BACKUP_USE_NAGIOS}" == "True" ] ; then - if [ $DUMP_RESULT -ne 0 ] ; then - echo "$db:FAILED" >> $NAGIOS_LOG - RETVAL=$DUMP_RESULT - else - echo "$db:OK" >> $NAGIOS_LOG - fi - fi - pushd ${MY_BACKUP_DIR}/ >/dev/null 2>&1 - rm -f $db.sql - ln -s $MY_BACKUP_DIR/history/${db}.sql.${SAVE_TIME} ./$db.sql - popd >/dev/null 2>&1 - fi + for db in $( mysql -Bse "show databases;" | grep -v $EXCLUDE_LIST ) ; do + mysqldump -f --flush-privileges --opt $db > $MY_BACKUP_DIR/history/${db}.sql.${SAVE_TIME} 2> $MY_BACKUP_LOG_DIR/$db.log + DUMP_RESULT=$? + chmod 600 $MY_BACKUP_DIR/history/${db}.sql.${SAVE_TIME} + if [ "${MY_BACKUP_USE_NAGIOS}" == "True" ] ; then + if [ $DUMP_RESULT -ne 0 ] ; then + echo "$db:FAILED" >> $NAGIOS_LOG + RETVAL=$DUMP_RESULT + else + echo "$db:OK" >> $NAGIOS_LOG + fi + fi + pushd ${MY_BACKUP_DIR}/ >/dev/null 2>&1 + rm -f $db.sql + ln -s $MY_BACKUP_DIR/history/${db}.sql.${SAVE_TIME} ./$db.sql + popd >/dev/null 2>&1 done # Do a "flush-hosts" after the backup mysqladmin flush-hosts 2> $MY_BACKUP_LOG_DIR/flush-hosts.log diff --git a/mysql/templates/mysql_backup-default.j2 b/mysql/templates/mysql_backup-default.j2 index 3eccc710..b189f3d6 100644 --- a/mysql/templates/mysql_backup-default.j2 +++ b/mysql/templates/mysql_backup-default.j2 @@ -4,3 +4,5 @@ MY_BACKUP_LOG_FILE='{{ mysql_backup_logfile}}' N_DAYS_TO_SPARE='{{ mysql_backup_retain_copies }}' MY_BACKUP_DIR='{{ mysql_backup_destdir }}' MY_DATA_DIR='{{ mysql_data_dir }}' +# Exclude list +EXCLUDE_LIST='{{ mysql_backup_exclude_list }}' diff --git a/nginx/defaults/main.yml b/nginx/defaults/main.yml index 657faf3e..b6000f04 100644 --- a/nginx/defaults/main.yml +++ b/nginx/defaults/main.yml @@ -5,6 +5,14 @@ nginx_ldap_uri: "ldap://ldap.sub.research-infrastructures.eu" nginx_ldap_base_dn: "dc=research-infrastructures,dc=eu" nginx_enabled: "Yes" +nginx_enable_compression: True +nginx_gzip_vary: "on" +nginx_gzip_proxied: any +nginx_gzip_comp_level: 6 +nginx_gzip_buffers: 16 8k +nginx_gzip_http_version: 1.1 +nginx_gzip_types: "text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript" + nginx_proxy_buffering: "on" nginx_proxy_redirect: "off" nginx_proxy_buffer_size: 128k diff --git a/nginx/tasks/nginx.yml b/nginx/tasks/nginx.yml index cf62d3f3..f5df3143 100644 --- a/nginx/tasks/nginx.yml +++ b/nginx/tasks/nginx.yml @@ -4,25 +4,26 @@ with_items: - nginx-full when: not nginx_use_ldap_pam_auth - tags: - - nginx + tags: nginx - name: Install the nginx web server if we need ldap auth via pam apt: pkg={{ item }} state=installed - with_items: + with_items: - nginx-extras when: nginx_use_ldap_pam_auth - tags: - - nginx + tags: nginx - name: remove nginx default config file: dest=/etc/nginx/sites-enabled/default state=absent - notify: - Reload nginx - tags: - - nginx + notify: Reload nginx + tags: [ 'nginx', 'nginx_conf', 'nginx_virtualhost' ] + +- name: Install the gzip compression configuration if enabled + template: src=nginx-compression.conf.j2 dest=/etc/nginx/conf.d/compression.conf owner=root group=root mode=0444 + when: nginx_enable_compression + notify: Reload nginx + tags: [ 'nginx', 'nginx_conf' ] - name: Ensure that the webserver is running service: name=nginx state=started enabled={{ nginx_enabled }} - tags: - - nginx + tags: nginx