Skip to content

Commit f3f6287

Browse files
Fix /var/ filling up once and for all (#451)
* fix filling up /var/ with journal logs * Revert "fix filling up /var/ with journal logs" This reverts commit 5485630. * can't believe this is still an issue * and another time bug * one more * fix * revert that * cleanup
1 parent 931484b commit f3f6287

File tree

8 files changed

+116
-0
lines changed

8 files changed

+116
-0
lines changed

Dockerfile.agnos

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ COPY ./userspace/files/allow-modem-control.pkla /etc/polkit-1/localauthority/50-
166166
COPY ./userspace/files/*.rules /etc/udev/rules.d/
167167
COPY ./userspace/files/ssh*_config /etc/ssh/
168168
COPY ./userspace/files/logrotate.conf /etc/
169+
COPY ./userspace/files/rsyslog /etc/logrotate.d/
169170
RUN chmod 644 /etc/logrotate.conf
170171
RUN touch -r /lib/systemd/systemd /etc/fstab
171172

userspace/files/rsyslog

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/var/log/syslog
2+
/var/log/mail.log
3+
/var/log/kern.log
4+
/var/log/auth.log
5+
/var/log/user.log
6+
/var/log/cron.log
7+
{
8+
rotate 4
9+
size 10M
10+
missingok
11+
notifempty
12+
compress
13+
delaycompress
14+
sharedscripts
15+
postrotate
16+
/usr/lib/rsyslog/rsyslog-rotate
17+
endscript
18+
}

userspace/files/varwatch.service

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
After=multi-user.target
3+
4+
[Service]
5+
Restart=always
6+
ExecStart=/usr/local/venv/bin/python -u /usr/comma/varwatch.py
7+
8+
[Install]
9+
WantedBy=multi-user.target

userspace/services.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ systemctl enable sound.service
1616
systemctl enable weston.service
1717
systemctl enable weston-ready.service
1818
systemctl enable init-qcom.service
19+
systemctl enable varwatch.service
1920
systemctl enable power_drop_monitor.service
2021
systemctl enable brightnessd.service
2122
systemctl enable ssh-param-watcher.path
@@ -61,6 +62,7 @@ systemctl disable update-notifier-download.timer
6162
systemctl disable update-notifier-download.service
6263
systemctl disable update-notifier-motd.timer
6364
systemctl disable update-notifier-motd.service
65+
systemctl disable man-db.timer
6466

6567
# Disable NFS stuff by default
6668
systemctl disable rpcbind

userspace/usr/comma/fs_setup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
# tmpfiles
77
systemd-tmpfiles --create /usr/comma/tmpfiles.conf
88

9+
# /var/log/ tmpfs
10+
mkdir -p /var/log/
11+
chown root:syslog /var/log
12+
mount -t tmpfs -o rw,nosuid,nodev,size=128M,mode=755 tmpfs /var/log
13+
914
# setup /home
1015
mkdir -p /rwtmp/home_work
1116
mkdir -p /rwtmp/home_upper
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -e
3+
4+
RATE=${1:-1}
5+
6+
log_message() {
7+
# /var/log/syslog
8+
cat /usr/include/sqlite3.h | systemd-cat -t SPAM_TEST
9+
10+
# /var/log/kern.log
11+
#cat /usr/include/sqlite3.h | sudo tee /dev/kmsg > /dev/null
12+
}
13+
14+
#minutely verify config is good
15+
sudo logrotate -d /etc/logrotate.conf
16+
17+
sudo rm -rf /var/log/*
18+
sudo systemctl restart rsyslog
19+
sudo systemctl restart systemd-journald
20+
sudo systemctl restart logrotate-hourly.timer
21+
22+
while true; do
23+
for i in $(seq 1 $RATE); do
24+
log_message
25+
done
26+
27+
echo
28+
df -h /var/
29+
sudo du -hs /var/log/* || true
30+
31+
sleep 1
32+
done

userspace/usr/comma/varspam.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
set -e
3+
4+
RATE=${1:-1}
5+
6+
log_message() {
7+
# /var/log/syslog
8+
cat /usr/include/sqlite3.h | systemd-cat -t SPAM_TEST
9+
10+
# /var/log/kern.log
11+
#cat /usr/include/sqlite3.h | sudo tee /dev/kmsg > /dev/null
12+
}
13+
14+
# verify config is good
15+
sudo logrotate -d /etc/logrotate.conf
16+
17+
sudo rm -rf /var/log/*
18+
sudo systemctl daemon-reload
19+
sudo systemctl restart rsyslog
20+
sudo systemctl restart systemd-journald
21+
sudo systemctl restart logrotate-hourly.timer
22+
23+
while true; do
24+
for i in $(seq 1 $RATE); do
25+
log_message
26+
done
27+
28+
echo
29+
df -h /var/
30+
sudo du -hs /var/log/* || true
31+
32+
sleep 1
33+
done

userspace/usr/comma/varwatch.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import time
4+
5+
if __name__ == "__main__":
6+
# we are the last line of defense for /var/log filling up
7+
while True:
8+
usage = os.statvfs('/var/log')
9+
percent = (usage.f_blocks - usage.f_bavail) / usage.f_blocks * 100
10+
if percent > 70:
11+
for fn in os.listdir('/var/log'):
12+
file_path = os.path.join('/var/log', fn)
13+
if os.path.isfile(file_path):
14+
with open(file_path, 'w'):
15+
pass
16+
time.sleep(1)

0 commit comments

Comments
 (0)