Skip to content

Instantly share code, notes, and snippets.

@hudon
Last active November 9, 2016 06:06
Show Gist options
  • Save hudon/8974ef2cbfc5b7e53865 to your computer and use it in GitHub Desktop.
Save hudon/8974ef2cbfc5b7e53865 to your computer and use it in GitHub Desktop.
Automatically truncate docker logs on a coreos machine
cat > /var/tmp/log-truncate <<EOF
#!/bin/sh
set -eux
cd /var/lib/docker/containers
for id in *
do
logfile="\${id}/\${id}-json.log"
[ -e "\${logfile}" ] && truncate -s 0 "\${logfile}"
done
btrfs balance start -v -dusage=20 /var/lib/docker/btrfs
EOF
chmod 0755 /var/tmp/log-truncate
cat > /etc/systemd/system/log-truncate.service <<EOF
[Unit]
Description=Log truncator
[Service]
ExecStart=/var/tmp/log-truncate
[Install]
WantedBy=log-truncator.timer
EOF
cat > /etc/systemd/system/log-truncate.timer<<EOF
[Unit]
Description=Run truncator every two days
[Timer]
OnUnitActiveSec=2d
[Install]
WantedBy=multi-user.target
EOF
systemctl start log-truncate.timer
systemctl enable log-truncate.timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment