Few ramlog/zram fixes/improvements

This commit is contained in:
ThomasKaiser 2018-07-09 11:55:39 -07:00
parent e78c66b3a9
commit 5c214b0cc1
4 changed files with 18 additions and 10 deletions

View File

@ -12,7 +12,7 @@
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
my_name="${0##*/}"
Log=/var/log/armbian-services.log
Log=/var/log/armbian-hardware-monitor.log
show_motd_warning() {
cat > /etc/update-motd.d/90-warning <<EOT

View File

@ -64,7 +64,6 @@ prepare_temp_monitoring() {
} # prepare_temp_monitoring
log_hardware_info() {
Log=/var/log/armbian-hardware-monitor.log
[ -f "/etc/logrotate.d/${0##*/}" ] || \
echo -e "${Log} {\n rotate 12\n weekly\n compress\n missingok\n notifempty\n}" \
> "/etc/logrotate.d/${0##*/}" ; chmod 644 "/etc/logrotate.d/${0##*/}"

View File

@ -6,8 +6,8 @@
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
SIZE=40M
USE_RSYNC=false
SIZE=50M
USE_RSYNC=true
ENABLED=false
[ -f /etc/default/armbian-ramlog ] && . /etc/default/armbian-ramlog
@ -27,7 +27,7 @@ isSafe () {
}
RecreateLogs (){
# in case of crash those services doesn't start if there are no dirs & logs
# in case of crash those services don't start if there are no dirs & logs
check_if_installed apache2 && [ ! -d /var/log/apache2 ] && mkdir -p /var/log/apache2
check_if_installed proftpd-basic && [ ! -d /var/log/proftpd ] && \
(mkdir -p /var/log/proftpd ; touch /var/log/proftpd/controls.log)
@ -39,6 +39,8 @@ RecreateLogs (){
syncToDisk () {
isSafe
echo -e "\n\n$(date): Syncing logs to storage\n" | $LOG_OUTPUT
if [ "$USE_RSYNC" = true ]; then
rsync -aXWv --exclude armbian-ramlog.log --links $RAM_LOG $HDD_LOG 2>&1 | $LOG_OUTPUT
else
@ -49,6 +51,8 @@ syncToDisk () {
syncFromDisk () {
isSafe
echo -e "\n\n$(date): Loading logs from storage\n" | $LOG_OUTPUT
if [ "$USE_RSYNC" = true ]; then
rsync -aXWv --delete --exclude armbian-ramlog.log --exclude *.gz --exclude='*.[0-9]' --links $HDD_LOG $RAM_LOG 2>&1 | $LOG_OUTPUT
else
@ -71,8 +75,13 @@ case "$1" in
[ -d $HDD_LOG ] || mkdir -p $HDD_LOG
mount --bind $RAM_LOG $HDD_LOG
mount --make-private $HDD_LOG
rm -f $LOG2RAM_LOG
# zram type
# preserve log and add logrotate rule
if [ ! -f $LOG2RAM_LOG ]; then
[ -f "/etc/logrotate.d/${0##*/}" ] || \
echo -e "${LOG2RAM_LOG} {\n rotate 1\n monthly\n compress\n missingok\n notifempty\n}" \
> "/etc/logrotate.d/${0##*/}" ; chmod 644 "/etc/logrotate.d/${0##*/}"
fi
# Check whether zram device is available or we need to use tmpfs
if [ "$(blkid -s TYPE /dev/zram0 | awk ' { print $2 } ' | grep ext4)" ]; then
mount /dev/zram0 $RAM_LOG | $LOG_OUTPUT
else
@ -90,7 +99,7 @@ case "$1" in
syncToDisk
;;
*)
echo "Usage: log2ram {start|stop|write}" >&2
echo "Usage: ${0##*/} {start|stop|write}" >&2
exit 1
;;
esac

View File

@ -42,7 +42,7 @@ activate_zram() {
mkswap /dev/zram${i}
swapon -p 5 /dev/zram${i}
done
echo -e "\n### Activated ${zram_devices} zram swap devices with ${mem_per_zram_device} MB each\n" >>${Log}
echo -e "\n### Activated ${zram_devices} zram swap devices with $(( ${mem_per_zram_device} / 1048576 )) MB each\n" >>${Log}
# Dedicate SIZE MB (uncompressed) /dev/zram0 device for log2ram and choose most efficient
# compression scheme available -- https://patchwork.kernel.org/patch/9918897/
@ -58,7 +58,7 @@ activate_zram() {
fi
mkfs.ext4 -O ^has_journal -s 1024 -L log2ram /dev/zram0
read algo </sys/block/zram0/comp_algorithm
algo=$(sed 's/.*\[\([^]]*\)\].*/\1/g' </sys/block/zram0/comp_algorithm)
echo -e "### Activated Armbian ramlog partition with ${algo} compression\n" >>${Log}
} # activate_zram