Giter VIP home page Giter VIP logo

Comments (3)

BIBOLV avatar BIBOLV commented on September 25, 2024

There are multiple options

  • Disable logging if there is not some specific need for logs. In case you would need them - can enable back later.
  • Use logrotate functionality on QNAP, not sure if there is such, maybe there are some 3rd party packages that would enable such functionality.
  • Write script that would do rotation - it should be possible to write scripts and schedule execution on QNAP?!
  • Use specific container that would provide such functionality.

from wmbusmeters.

jens62 avatar jens62 commented on September 25, 2024

Thanks for your reply.
I thought I missed something, because it is mentioned in the documentation that make install installs a. o. /etc/logrotate.d/wmbusmeters. I expected that it is a matter of configuration to use logrote in the docker environment as well.

I like docker because it reduces dependencies and complexity.
I want to avoid having additional dependencies/connections/relations to the wmbusmeters container from outside the container.

I looked into the wmbusmeters container with docker exec -it wmbusmeters sh and realized that logrotate is not part of it.
cat /etc/os-release gave me Alpine Linux v3.14.

With

apk update
apk upgrade
apk add logrotate

I added logrotate to the container.

I created a /wmbusmeters_data/etc/logrotate.conf according to scripts/prepare_logfiles.sh:

cat  /wmbusmeters_data/etc/logrotate.conf

/wmbusmeters_data/logs/meter_readings/*
/wmbusmeters_data/logs/*.log {
    su root root
    rotate 12
    daily
    compress
    missingok
    postrotate
        /usr/bin/killall -HUP /wmbusmeters/wmbusmeters
    endscript
}

logrotate needs a cron daemon.
The standard cron daemon appears to be not the best solution inside a docker container.
I decided to use supercronic and installed it with

export SUPERCRONIC_URL='https://github.com/aptible/supercronic/releases/download/v0.2.24/supercronic-linux-amd64'
export SUPERCRONIC='supercronic-linux-amd64'
export SUPERCRONIC_SHA1SUM='6817299e04457e5d6ec4809c72ee13a43e95ba41'

curl -fsSLO "$SUPERCRONIC_URL" \
 && echo "${SUPERCRONIC_SHA1SUM}  ${SUPERCRONIC}" | sha1sum -c - \
 && chmod +x "$SUPERCRONIC" \
 && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
 && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic

I created a crontab for logrotate:

cat /wmbusmeters_data/etc/supercronic_crontab

0 * * * * /usr/sbin/logrotate /wmbusmeters_data/etc/logrotate.conf --state /wmbusmeters_data/etc/logrotate-state

Finally I adjusted /wmbusmeters/docker-entrypoint.sh to

#!/bin/sh

[ ! -d /wmbusmeters_data/logs/meter_readings ] && mkdir -p /wmbusmeters_data/logs/meter_readings
[ ! -d /wmbusmeters_data/etc/wmbusmeters.d ] && mkdir -p /wmbusmeters_data/etc/wmbusmeters.d
[ ! -f /wmbusmeters_data/etc/wmbusmeters.conf ] && echo -e "loglevel=normal\ndevice=auto:t1\ndonotprobe=/dev/ttyAMA0\nlogtelegrams=false\nformat=json\nmeterfiles=/wmbusmeters_data/logs/meter_readings\nmeterfilesaction=overwrite\nlogfile=/wmbusmeters_data/logs/wmbusmeters.log" > /wmbusmeters_data/etc/wmbusmeters.conf

/usr/local/bin/supercronic /wmbusmeters_data/etc/supercronic_crontab &
/wmbusmeters/wmbusmeters --useconfig=/wmbusmeters_data

in oder to run the supercronic cron daemon in the background.

This solution works for me.
I am aware that I will have an issue when I update the container from the repository - my changes will be lost.
Maybe the container maintainers decide to add logrotate, logrotate.conf, supercronic, a supercronic_crontab and an adjusted docker-entrypoint.sh to the next wmbusmeters container version ;-)

from wmbusmeters.

BIBOLV avatar BIBOLV commented on September 25, 2024

I will close second opened issue regarding this topic - let`s keep discussion and tracking under one issue.

There is indeed logrotate configs included, but that all is for standalone version and was not included in docker. Another reason logrotate not being in docker is that IMO it is much simpler to manage logs from host side and leave docker only for app purposes, but I understand why this is issue for you. You have already done great job on making necessary changes and testing them so I do not see big issue if we would add it to container with few buts:

  • Can you test if logrotate config is removed if it will not cause issues for docker functionality. Idea is - if someone would like to disable logrotate functionality withing docker, how it should be done correctly that does not compromise container functionality.
  • I`m not fond of including some specific version of software in docker file - it would mean that constant followup and updates would be needed, It will make thing even more complex to build for multiple architectures.

supercronic is included as package starting from Alpline 3.15, so let`s give some time for multiarch/alpine repo to update their base image to more latest one and then we could implement this properly. If you notice this happening you are more then welcome to create PR, meanwhile I will mark this issue as planned.

Regarding your local changes - you can use wmbusmeters/wmbusmeters:release-1.13.1 docker image for example, if everything is working for you and you do not need latest changes, that way your local container would not be recreated and you would not lose local changes.

from wmbusmeters.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.