diff --git a/.dockerignore b/.dockerignore index 5b95c29758..414c164a92 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,3 +9,7 @@ TODO.md kubernetes/ scripts/ docker-compose.yml +logs/ +supervisor-logs/ +zulip-data/ + diff --git a/Dockerfile b/Dockerfile index 2ace4c9008..c3c8ed85bb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 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" diff --git a/docker-compose.yml b/docker-compose.yml index 70249129ad..0772361d23 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/entrypoint.sh b/entrypoint.sh index 22fd3c7f80..d6650e004c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e if [ "$DEBUG" = "true" ] || [ "$DEBUG" = "True" ]; then set -x @@ -6,6 +7,18 @@ if [ "$DEBUG" = "true" ] || [ "$DEBUG" = "True" ]; then 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}" diff --git a/etc/logrotate.d.d/zulip-docker b/etc/logrotate.d.d/zulip-docker new file mode 100644 index 0000000000..f64f7e170d --- /dev/null +++ b/etc/logrotate.d.d/zulip-docker @@ -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 diff --git a/etc/logrotate.d/zulip b/etc/logrotate.d/zulip new file mode 100644 index 0000000000..9df933a153 --- /dev/null +++ b/etc/logrotate.d/zulip @@ -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 +} diff --git a/etc/supervisor/conf.d/zulip.conf b/etc/supervisor/conf.d/zulip.conf new file mode 100644 index 0000000000..b0ea903909 --- /dev/null +++ b/etc/supervisor/conf.d/zulip.conf @@ -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