Browse Source

fix: [logrotate] rotate files with ``create`` command and numeric uid given

rsync-stats
Valentin Lab 3 weeks ago
parent
commit
08beea697d
  1. 6
      bind/hooks/log_rotate-relation-joined
  2. 17
      logrotate/build/Dockerfile
  3. 5
      odoo-tecnativa/hooks/init
  4. 6
      odoo-tecnativa/hooks/log_rotate-relation-joined
  5. 4
      odoo-tecnativa/hooks/postgres_database-relation-joined
  6. 10
      odoo-tecnativa/lib/common
  7. 24
      rsync-backup-target/hooks/log_rotate-relation-joined

6
bind/hooks/log_rotate-relation-joined

@ -6,7 +6,9 @@
set -e
named_uid=$(docker_get_uid "$SERVICE_NAME" "named")
named_uid_gid=$(docker_get_uid_gid "$SERVICE_NAME" "named" "named")
uid=${named_uid_gid%%$'\n'*}
gid=${named_uid_gid#*$'\n'}
LOGS=/var/log/bind
mkdir -p "$SERVICE_DATASTORE/$LOGS"
@ -30,7 +32,7 @@ file_put "$DST" <<EOF
compress
delaycompress
notifempty
create 640
create 0640 :$uid :$gid
sharedscripts
postrotate
dc exec $SERVICE_NAME /usr/sbin/rndc reconfig > /dev/null 2>/dev/null || true

17
logrotate/build/Dockerfile

@ -1,4 +1,16 @@
FROM docker.0k.io/alpine
FROM docker.0k.io/alpine:3.20 as builder
## XXXvlab: see https://github.com/logrotate/logrotate/issues/650
## for why we need to build our own logrotate
RUN apk add --no-cache build-base git autoconf automake popt-dev libtool make xz
RUN cd /tmp && git clone https://github.com/logrotate/logrotate.git && \
cd /tmp/logrotate && git checkout d57dff56edce193abf7a660da3635be89e57fc8e && \
./autogen.sh && ./configure && make && make install
FROM docker.0k.io/alpine:3.20
## dependency of docker-send-signal
RUN apk add curl
@ -7,6 +19,9 @@ RUN apk add jq
RUN apk add logrotate && \
sed -ri 's/^(\/var\/log\/messages \{\})$/# \1/g' /etc/logrotate.conf
## Replace logrotate 3.21 from alpine with our 3.22+ version
COPY --from=builder /usr/local/sbin/logrotate /usr/sbin/logrotate
COPY src/ /
ENTRYPOINT ["/entrypoint.sh"]

5
odoo-tecnativa/hooks/init

@ -17,11 +17,12 @@ LIB="$SERVICE_DATASTORE/var/lib/odoo"
set -e
odoo_uid=$(get_odoo_uid)
odoo_uid_gid=$(docker_get_uid_gid "$SERVICE_NAME" "odoo" "odoo")
odoo_uid=${odoo_uid_gid%%$'\n'*}
mkdir -p "$LIB"
## XXXvlab: this one can fail if files are removed (from sessions dir)
find "$LIB" \! -user "$odoo_uid" -print0 | while read-0 f; do
find "$LIB" \! -uid "$odoo_uid" -print0 | while read-0 f; do
chown -v "$odoo_uid" "$f" || exit 1
done

6
odoo-tecnativa/hooks/log_rotate-relation-joined

@ -6,7 +6,9 @@
set -e
odoo_uid=$(get_odoo_uid)
uid_gid=$(docker_get_uid_gid "$MASTER_BASE_SERVICE_NAME" "odoo" "odoo")
uid=${uid_gid%%$'\n'*}
gid=${uid_gid#*$'\n'}
LOGS=/var/log/odoo
mkdir -p "$SERVICE_DATASTORE/$LOGS"
@ -33,7 +35,7 @@ file_put "$DST" <<EOF
compress
delaycompress
notifempty
create 640
create 0640 :$uid :$gid
sharedscripts
}
EOF

4
odoo-tecnativa/hooks/postgres_database-relation-joined

@ -52,7 +52,9 @@ db_user = $USER
db_password = $PASSWORD
EOF
odoo_uid=$(get_odoo_uid)
odoo_uid_gid=$(docker_get_uid_gid "$MASTER_BASE_SERVICE_NAME" "odoo" "odoo")
odoo_uid=${odoo_uid_gid%%$'\n'*}
chown "$odoo_uid" "$CONFIG" && chmod 600 "$CONFIG"

10
odoo-tecnativa/lib/common

@ -1,15 +1,5 @@
# -*- mode: shell-script -*-
get_odoo_uid() {
uid_label="odoo"
odoo_uid=$(cached_cmd_on_base_image "$SERVICE_NAME" "id -u \"$uid_label\"") || {
debug "Failed to query for '$uid_label' uid in ${DARKYELLOW}$SERVICE_NAME${NORMAL} base image."
return 1
}
info "openerp uid from ${DARKYELLOW}$SERVICE_NAME${NORMAL} is '$odoo_uid'"
echo "$odoo_uid"
}
sql() {
local dbname="$1"
(

24
rsync-backup-target/hooks/log_rotate-relation-joined

@ -2,17 +2,23 @@
## Should be executable N time in a row with same result.
. lib/common
set -e
uid=$(docker_get_uid "$SERVICE_NAME" "rsync")
uid_gid=$(docker_get_uid_gid "$SERVICE_NAME" "rsync" "rsync")
uid=${uid_gid%%$'\n'*}
gid=${uid_gid#*$'\n'}
LOGS=/var/log/rsync
mkdir -p "$SERVICE_DATASTORE/$LOGS"
touch "$SERVICE_DATASTORE/$LOGS/ssh-cmd-validate.log"
chown -v "$uid" "$SERVICE_DATASTORE/$LOGS" "$SERVICE_DATASTORE/$LOGS/ssh-cmd-validate.log"
chmod -v 0640 "$SERVICE_DATASTORE/$LOGS/ssh-cmd-validate.log"
touch "$SERVICE_DATASTORE/$LOGS/ssh-admin-cmd-validate.log"
chown -v "$uid:$gid" "$SERVICE_DATASTORE/$LOGS" "$SERVICE_DATASTORE/$LOGS/ssh-admin-cmd-validate.log"
chmod -v 0660 "$SERVICE_DATASTORE/$LOGS/ssh-admin-cmd-validate.log"
rotated_count=$(relation-get rotated-count 2>/dev/null) || true
rotated_count=${rotated_count:-52}
@ -33,7 +39,9 @@ file_put "$DST" <<EOF
compress
delaycompress
notifempty
create 640 $uid
## XXXvlab: see https://github.com/logrotate/logrotate/issues/650
## for the syntax headache (and it relies on correct version of logrotate)
create 0640 :$uid :0
sharedscripts
}
@ -49,7 +57,9 @@ file_put "$DST" <<EOF
compress
delaycompress
notifempty
create 660 $uid
## XXXvlab: see https://github.com/logrotate/logrotate/issues/650
## for the syntax headache (and it relies on correct version of logrotate)
create 0660 :$uid :$gid
sharedscripts
}
@ -65,7 +75,7 @@ file_put "$DST" <<EOF
compress
delaycompress
notifempty
create 640
create 0640 :0 :0
sharedscripts
}
EOF

Loading…
Cancel
Save