Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #263: Implement log rotation for server/error logs in docker-zulip #473

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -9,3 +9,7 @@ TODO.md
kubernetes/
scripts/
docker-compose.yml
logs/
supervisor-logs/
zulip-data/

14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -3,6 +3,20 @@
# tools/build-release-tarball to generate a production release tarball
# from the provided Git ref.
FROM ubuntu:24.04 AS base
# Install required packages
RUN apt-get update && apt-get install -y \
logrotate \
cron \
&& rm -rf /var/lib/apt/lists/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We install dependencies via puppet, you shouldn't need to add anything here. I expect these files are already present, and the actual bug is needing to actually run logrotate via supervisord (like how we do cron), since it likely is installed but not running.


# Copy logrotate configuration
COPY zulip-docker /etc/logrotate.d/zulip-docker
RUN chmod 644 /etc/logrotate.d/zulip-docker

# Set up log directories with proper permissions
RUN mkdir -p /var/log/zulip /var/log/supervisor \
&& chown -R zulip:zulip /var/log/zulip \
&& chmod 755 /var/log/zulip

# Set up working locales and upgrade the base image
ENV LANG="C.UTF-8"
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -97,7 +97,14 @@ services:
# comma-separated set of IP addresses to trust here.
# LOADBALANCER_IPS: "",
volumes:
- ./logs:/var/log/zulip:rw
- ./supervisor-logs:/var/log/supervisor:rw
- "zulip:/data:rw"
depends_on:
- database
- memcached
- rabbitmq
- redis
ulimits:
nofile:
soft: 1000000
13 changes: 13 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
#!/bin/bash
set -e

if [ "$DEBUG" = "true" ] || [ "$DEBUG" = "True" ]; then
set -x
set -o functrace
fi
set -e
shopt -s extglob
# === ADD NEW LOG ROTATION CODE RIGHT HERE ===
echo "Setting up log rotation..."
service cron start
touch /var/lib/logrotate/status

echo "Creating log directories..."
mkdir -p /var/log/zulip /var/log/supervisor

echo "Setting correct permissions..."
chown -R zulip:zulip /var/log/zulip
chmod 755 /var/log/zulip
# === END OF NEW LOG ROTATION CODE ===

# DB aka Database
DB_HOST="${DB_HOST:-127.0.0.1}"
29 changes: 29 additions & 0 deletions etc/logrotate.d.d/zulip-docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
docker exec -it zulip bash -c 'cat > /etc/logrotate.d/zulip-docker' << 'EOF'
/var/log/zulip/*.log {
daily
rotate 7
compress
delaycompress
notifempty
missingok
create 644 zulip zulip
sharedscripts
postrotate
supervisorctl reopen-logs
endscript
}

/var/log/supervisor/*.log {
daily
rotate 7
compress
delaycompress
notifempty
missingok
create 644 root root
sharedscripts
postrotate
supervisorctl reopen-logs
endscript
}
EOF
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zulip ships with a logrotate configuration file; I don't think we should need to provide this in the container image as well, as zulip itself should have installed it already. Would be good to avoid duplicating, as the copy here will get stale.

16 changes: 16 additions & 0 deletions etc/logrotate.d/zulip
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/var/log/zulip/server.log
/var/log/zulip/workers.log
/var/log/zulip/errors.log
{
rotate 7
daily
missingok
compress
delaycompress
notifempty
create 644 zulip zulip
sharedscripts
postrotate
/usr/bin/supervisorctl reopen-logs
endscript
}
23 changes: 23 additions & 0 deletions etc/supervisor/conf.d/zulip.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info

[program:zulip]
command=/usr/local/bin/zulip start
stdout_logfile=/var/log/zulip/server.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
redirect_stderr=true
autostart=true
autorestart=true
priority=10
startsecs=10
startretries=3

[program:cron]
command=/usr/sbin/cron -f
autostart=true
autorestart=true