UWSGI logrotation

2019-08-08 15:28发布

问题:

I have running uwsgi server. i need log rotation for daily and file size based log rotation.

uwsgi configuration:

# file: /etc/init/uwsgi.conf
description "uWSGI starter"

start on (local-filesystems and runlevel [2345])
stop on runlevel [016]

respawn

# home - is the path to our virtualenv directory
# pythonpath - the path to our django application
# module - the wsgi handler python script

exec /home/testuser/virtual_environments/teatapp/bin/uwsgi \
--uid testuser \
--home /home/testuser/virtual_environments/teatapp \
--pythonpath /home/testuser/sci-github/teatapp\
--socket /tmp/uwsgi.sock \
--chmod-socket \
--module wsgi \
--logdate \
--optimize 2 \
--processes 2 \
--master \
--logto /var/log/uwsgi/uwsgi.log

logrotate configuration:

# file : /etc/logrotate.conf

"/var/log/uwsgi/*.log" {
    copytruncate
    daily
    maxsize 5k
    dateext
    rotate 5
    compress
    missingok
    create 777 root root
}

But log rotation is not working please give the solution for if any wrong configuration in logrotaion.conf.

回答1:

there is logrotation in uwsgi, based on the log file size, for example (uwsgi.ini directive):

log-maxsize = 100000

if you want to use logrotated, you have to restart uwsgi (logrotate directives):

postrotate
           stop uwsgi
           start uwsgi
endscript


回答2:

It's not needed to restart uwsgi service if you use copytruncate option in logrotate file (as stated by Tamar).

But the problem may be that you forgot to enable logrotate in cron. Please, make sure you have a entry in /etc/cron.daily called logrotate.



回答3:

Just put this on your uwsgi configuration file :

daemonize = /var/log/uwsgi/uwsgi-@(exec://date +%%Y-%%m-%%d).log

This will create a log each day, but be carefull don't daemonize if you are using master our emperror. Then if the logs are big you can control it with a script attatched to a cron to clean the folder.