Logrotate cgroups
Материал из noname.com.ua
Перейти к навигацииПерейти к поиску
Logrotate
логротейт с ограничением по дисковому вводу-выводу
#!/bin/bash # Clean non existent log file entries from status file cd /var/lib/logrotate test -e status || touch status head -1 status > status.clean sed 's/"//g' status | while read logfile date do [ -e "$logfile" ] && echo "\"$logfile\" $date" done >> status.clean mv status.clean status test -x /usr/sbin/logrotate || exit 0 GROUP_NAME="logrotate" DISK_NAME="/dev/xvda" DISK_SPEED_LIMIT_READ="419430400" #40 Mbites per second (in fact speed is limited by IOPS) DISK_SPEED_LIMIT_WRITE=${DISK_SPEED_LIMIT_READ} IOPS_LIMIT_READ=40 IOPS_LIMIT_WRITE=40 # Create CGroup /usr/bin/cgcreate \ -t root:root \ -g blkio:/${GROUP_NAME} for DISK_NAME in $(/sbin/fdisk -l | grep 'Disk /dev/xvd' | awk '{ print $2 }' | sed 's/://g'); do read -r MAJOR MINOR <<<$(file ${DISK_NAME} | awk -F '(' '{ print $2 }' | tr '/)' ' ') /usr/bin/cgset -r blkio.throttle.read_iops_device="${MAJOR}:${MINOR} ${IOPS_LIMIT_READ}" ${GROUP_NAME} /usr/bin/cgset -r blkio.throttle.write_iops_device="${MAJOR}:${MINOR} ${IOPS_LIMIT_WRITE}" ${GROUP_NAME} /usr/bin/cgset -r blkio.throttle.write_bps_device="${MAJOR}:${MINOR} ${DISK_SPEED_LIMIT_READ}" ${GROUP_NAME} /usr/bin/cgset -r blkio.throttle.read_bps_device="${MAJOR}:${MINOR} ${DISK_SPEED_LIMIT_WRITE}" ${GROUP_NAME} done /usr/bin/cgexec -g blkio:/${GROUP_NAME} \ /usr/sbin/logrotate -v /etc/logrotate.conf >/var/log/logrotate.log 2>/var/log/logrotate.err