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.
This commit is contained in:
Andrea Dell'Amico 2015-08-05 19:14:03 +02:00
parent 72e03b7851
commit abf68e19e5
6 changed files with 42 additions and 32 deletions

View File

@ -16,6 +16,7 @@ mw_php_prereq:
- php5-mysqlnd - php5-mysqlnd
- php-apc - php-apc
- php-pear - php-pear
- php5-ldap
- imagemagick - imagemagick
# This choice is not recommended. The package has a poor list of dependencies. We do not want to deal with those # This choice is not recommended. The package has a poor list of dependencies. We do not want to deal with those

View File

@ -43,4 +43,5 @@ mysql_backup_logdir: '{{ mysql_log_dir }}'
mysql_backup_logfile: '{{ mysql_backup_logdir }}/my_backup.log' mysql_backup_logfile: '{{ mysql_backup_logdir }}/my_backup.log'
mysql_backup_retain_copies: 15 mysql_backup_retain_copies: 15
mysql_backup_destdir: /var/lib/mysql-backup mysql_backup_destdir: /var/lib/mysql-backup
mysql_backup_exclude_list: "performance_schema"

View File

@ -6,6 +6,8 @@ MY_BACKUP_USE_NAGIOS="False"
MY_BACKUP_DIR=/var/lib/mysql-backup MY_BACKUP_DIR=/var/lib/mysql-backup
MY_DATA_DIR=/var/lib/mysql MY_DATA_DIR=/var/lib/mysql
N_DAYS_TO_SPARE=7 N_DAYS_TO_SPARE=7
# Exclude list
EXCLUDE_LIST='performance_schema'
if [ -f /etc/default/mysql_backup ] ; then if [ -f /etc/default/mysql_backup ] ; then
. /etc/default/mysql_backup . /etc/default/mysql_backup
@ -33,33 +35,28 @@ fi
chmod 700 $MY_BACKUP_DIR chmod 700 $MY_BACKUP_DIR
LOCKFILE=$MY_DATA_DIR/.mysqldump.lock LOCKFILE=$MY_DATA_DIR/.mysqldump.lock
NAGIOS_LOG=$MY_BACKUP_DIR/.nagios-status NAGIOS_LOG=$MY_BACKUP_DIR/.nagios-status
# Exclude list
EXCLUDE_LIST='performance_schema'
if [ ! -f $LOCKFILE ] ; then if [ ! -f $LOCKFILE ] ; then
touch $LOCKFILE touch $LOCKFILE
if [ "${MY_BACKUP_USE_NAGIOS}" == "True" ] ; then if [ "${MY_BACKUP_USE_NAGIOS}" == "True" ] ; then
> $NAGIOS_LOG > $NAGIOS_LOG
fi fi
for db in $( /bin/ls -1 /var/lib/mysql/ | grep -v $EXCLUDE_LIST ) ; do for db in $( mysql -Bse "show databases;" | grep -v $EXCLUDE_LIST ) ; do
if [ -d /var/lib/mysql/$db ] ; then mysqldump -f --flush-privileges --opt $db > $MY_BACKUP_DIR/history/${db}.sql.${SAVE_TIME} 2> $MY_BACKUP_LOG_DIR/$db.log
#mysqldump -uroot -f --opt -p$MYSQLPASS $db > $MY_BACKUP_DIR/$db.sql 2> $MY_BACKUP_DIR/log/$db.log DUMP_RESULT=$?
mysqldump -f --opt $db > $MY_BACKUP_DIR/history/${db}.sql.${SAVE_TIME} 2> $MY_BACKUP_LOG_DIR/$db.log chmod 600 $MY_BACKUP_DIR/history/${db}.sql.${SAVE_TIME}
DUMP_RESULT=$? if [ "${MY_BACKUP_USE_NAGIOS}" == "True" ] ; then
chmod 600 $MY_BACKUP_DIR/history/${db}.sql.${SAVE_TIME} if [ $DUMP_RESULT -ne 0 ] ; then
if [ "${MY_BACKUP_USE_NAGIOS}" == "True" ] ; then echo "$db:FAILED" >> $NAGIOS_LOG
if [ $DUMP_RESULT -ne 0 ] ; then RETVAL=$DUMP_RESULT
echo "$db:FAILED" >> $NAGIOS_LOG else
RETVAL=$DUMP_RESULT echo "$db:OK" >> $NAGIOS_LOG
else fi
echo "$db:OK" >> $NAGIOS_LOG fi
fi pushd ${MY_BACKUP_DIR}/ >/dev/null 2>&1
fi rm -f $db.sql
pushd ${MY_BACKUP_DIR}/ >/dev/null 2>&1 ln -s $MY_BACKUP_DIR/history/${db}.sql.${SAVE_TIME} ./$db.sql
rm -f $db.sql popd >/dev/null 2>&1
ln -s $MY_BACKUP_DIR/history/${db}.sql.${SAVE_TIME} ./$db.sql
popd >/dev/null 2>&1
fi
done done
# Do a "flush-hosts" after the backup # Do a "flush-hosts" after the backup
mysqladmin flush-hosts 2> $MY_BACKUP_LOG_DIR/flush-hosts.log mysqladmin flush-hosts 2> $MY_BACKUP_LOG_DIR/flush-hosts.log

View File

@ -4,3 +4,5 @@ MY_BACKUP_LOG_FILE='{{ mysql_backup_logfile}}'
N_DAYS_TO_SPARE='{{ mysql_backup_retain_copies }}' N_DAYS_TO_SPARE='{{ mysql_backup_retain_copies }}'
MY_BACKUP_DIR='{{ mysql_backup_destdir }}' MY_BACKUP_DIR='{{ mysql_backup_destdir }}'
MY_DATA_DIR='{{ mysql_data_dir }}' MY_DATA_DIR='{{ mysql_data_dir }}'
# Exclude list
EXCLUDE_LIST='{{ mysql_backup_exclude_list }}'

View File

@ -5,6 +5,14 @@ nginx_ldap_uri: "ldap://ldap.sub.research-infrastructures.eu"
nginx_ldap_base_dn: "dc=research-infrastructures,dc=eu" nginx_ldap_base_dn: "dc=research-infrastructures,dc=eu"
nginx_enabled: "Yes" 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_buffering: "on"
nginx_proxy_redirect: "off" nginx_proxy_redirect: "off"
nginx_proxy_buffer_size: 128k nginx_proxy_buffer_size: 128k

View File

@ -4,25 +4,26 @@
with_items: with_items:
- nginx-full - nginx-full
when: not nginx_use_ldap_pam_auth when: not nginx_use_ldap_pam_auth
tags: tags: nginx
- nginx
- name: Install the nginx web server if we need ldap auth via pam - name: Install the nginx web server if we need ldap auth via pam
apt: pkg={{ item }} state=installed apt: pkg={{ item }} state=installed
with_items: with_items:
- nginx-extras - nginx-extras
when: nginx_use_ldap_pam_auth when: nginx_use_ldap_pam_auth
tags: tags: nginx
- nginx
- name: remove nginx default config - name: remove nginx default config
file: dest=/etc/nginx/sites-enabled/default state=absent file: dest=/etc/nginx/sites-enabled/default state=absent
notify: notify: Reload nginx
Reload nginx tags: [ 'nginx', 'nginx_conf', 'nginx_virtualhost' ]
tags:
- nginx - 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 - name: Ensure that the webserver is running
service: name=nginx state=started enabled={{ nginx_enabled }} service: name=nginx state=started enabled={{ nginx_enabled }}
tags: tags: nginx
- nginx