Redis logrotate config - redis

Does anyone have a sample logrotate config for redis? This is what I have so far
/var/log/redis/*.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
...
endscript
}
But I'm not sure what to do on the postrotate step. This is on Ubuntu 10.04 LTS.

This will probably suffice:
/var/log/redis/*.log {
weekly
rotate 10
copytruncate
delaycompress
compress
notifempty
missingok
}

I went with
/var/log/redis/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 0660 redis redis
}
because I don't want copytruncate.
I'm not sure the create line is necessary. It matches the file mode and ownership of the log files typically created by redis-server on Ubuntu (or Debian).

Related

WSL2 mount VHDX virtual disk issue with Windows docker Volumes

On Windows 10 Insider Preview (prerelease.201207-1443) I have mounted successfully a vhdx file with WSL2.
PS C:\Users> wmic diskdrive list brief
Caption DeviceID Model Partitions Size
..
Microsoft virtuális lemez \\.\PHYSICALDRIVE2 Microsoft virtuális lemez 1 5362882560
PS C:\Users> wsl --mount \\.\PHYSICALDRIVE2 --bare
Inside the Ubuntu 20.20 it looks OK, I could mounted and format (ext4) the virtual disk.
/dev/sde1 4.9G 20M 4.6G 1% /mnt/docker/vol/pg_disk_1
I can use it, read, write without any problem. Performance is good.
Issue: I want to use this disk when I create docker container for application data, it is not visible inside the container.
docker run -d -it --name devtest --mount type=bind,source=/mnt/docker/vol/pg_disk_1/nginx,target=/app nginx:latest
docker inspect shows the volume bind mounted:
"Mounts": [
{
"Type": "bind",
"Source": "/mnt/docker/vol/pg_disk_1/nginx",
"Destination": "/app",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
when I create a file on the host eg. example_host.html
User#Pince:/mnt/docker/vol/pg_disk_1/nginx$ ls -l
total 0
-rw-r--r-- 1 r858 r858 0 Jan 3 11:30 example_host.html
not visible when I check inside the container
root#078e4d7007a8:/app# ls -la
total 8
drwxr-xr-x 2 root root 4096 Jan 3 10:32 .
drwxr-xr-x 1 root root 4096 Jan 3 10:15 ..
root#078e4d7007a8:/app# pwd
/app
and if I create a file here inside the container it will be persistent when recreate the container but not in Linux mounted disk. I found it here:
\\wsl$\docker-desktop\mnt\host\wsl\docker-desktop-bind-mounts\Ubuntu-20.04\...
Question: this is normal and I missed something or it is not ready yet in this stage of the development. And do you know anybody a workaround how to use vhdx mounted disk for docker application data on Windows?
The problem is that /dev/sde1 is created and managed by wsl, so not (easily?) accessible by Windows programs like Docker Desktop.
One workaround is to mount \.\PHYSICALDRIVE2 as drive D: and mounted as :
docker run -v 'D:\data:/data' ...
This way, you can access it both on Windows and wsl.

I've been trying to use logrotate utility and move the compressed logs to s3, however, it rotates only when done forcefully

I've configured it to run hourly, it rotates logs hourly but not sending it to s3, what could be the reason?
/var/log/newlog
{
rotate 5
hourly
missingok
notifempty
compress
dateext
dateformat -%Y-%m-%d-%H%M%S
postrotate
/usr/lib/newlog/new
endscript
/usr/lib/newlog/new is a script, using s3cmd to sync .gz files to s3
From the above code it is seen that, there is no mention of S3 bucket to which the log files should be compressed.
Your script should add the following lines:
/var/log/newlog {
postrotate
/usr/lib/newlog/new > /dev/null 2>&1 || true
BUCKET=logging-bucket
INSTANCE_ID=`curl --silent http://169.254.169.254/latest/meta-data/instance-id | sed -e "s/i-//"`
/usr/bin/s3cmd -m text/plain sync /var/log/messages-* s3://${BUCKET}/${INSTANCE_ID}/var/log/
endscript
}
where logging-bucket is name of the bucket in which the compressed files will be stored.
Also make sure the user has permissions to the S3.
Thanks

How to enable logrotation for traefik?

How do I enable log rotation for log files e.g. access.log.
Is this built in ?
Docs only say "This allows the logs to be rotated and processed by an external program, such as logrotate"
If you are running Traefik in a Docker container then you can do something like this:
Check that logrotate is installed on the Docker host:
logrotate --version
Create file in /etc/logrotate.d/:
vi /etc/logrotate.d/traefik
Put the following script, do not forget to fill with the container name.
/var/log/traefik/*.log {
size 10M
rotate 5
missingok
notifempty
postrotate
docker kill --signal="USR1" <container-name>
endscript
}
Run!
logrotate /etc/logrotate.conf --debug
logrotate /etc/logrotate.conf
It seems like there's no logrotation built-in so i enabled logrotation on the Host that traefik_access.log is mounted to.
In order for this to work when traefik is running in a docker container, you must volume mount the directory containing the log file (/opt/traefik/logs), not the log file itself (/traefik_access.log).
volumes:
- /opt/traefik/logs:/logs
My logrotate-config for traefik 1.7.4 running in a container with volume mount to "/opt/traefik/logs":
/opt/traefik/logs/*.log {
daily
rotate 30
missingok
notifempty
compress
dateext
dateformat .%Y-%m-%d
create 0644 root root
postrotate
docker kill --signal="USR1" $(docker ps | grep traefik | awk '{print $1}')
endscript
}
Log Rotation
Traefik will close and reopen its log files, assuming they're configured, on receipt of a USR1 signal. This allows the logs to be rotated and processed by an external program, such as logrotate.
https://docs.traefik.io/v1.6/configuration/logs/#log-rotation

Apache2 logging in access.log1 instead of access.log

My ubuntu server, few days ago the access.log and error.log files created under /var/log/apache2, but they still empty,
Currently apache is logging into access.log.1 and error.log.1, this issue is happening for all the virtual hosts on my server.
all permision are normally "rw-r--r--" and owner root:adm under the /var/log/apache2
here is my /etc/logrotate.d/apache2 "we didn't change it"
/var/log/apache2/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 644 root adm
sharedscripts
postrotate
if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
/etc/init.d/apache2 reload > /dev/null
fi
endscript
Did you check permission on the /var/log/apache2 directory?
$ ls -l /var/log/
drwxr-x--- 2 root adm 4096 Apr 12 06:55 apache2
I Found the issue was because the apache2 daemon file under /etc/init.d was "some how" erased!!,
I replaced that file from backup and it is logging normally now.

logrotate deleted the file instead of rotating

Why would logrotate delete the file instead of rotating it?
Here's the config:
/var/log/httpd/*log {
size 1G
missingok
notifempty
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}
Your config looks ok, there is likely some default in your /etc/logrotate.conf that is deleting files.
If you have rotate 0 in your config file, old files will be deleted rather than rotated.
It may be that the files are being rotated but you are looking in the wrong place.
Check the logrotate logs with cat /var/lib/logrotate/status to verify that logrotate is running as expected.
And of course, familiarize yourself with logrotate by reading the man page