Skip to content

Commit

Permalink
issue zulip#263
Browse files Browse the repository at this point in the history
  • Loading branch information
savaliyabhargav committed Nov 14, 2024
1 parent f445fc5 commit 8705221
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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}"
Expand Down
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
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

0 comments on commit 8705221

Please sign in to comment.