new: [opensem] add charm
This commit is contained in:
86
opensem/hooks/log_rotate-relation-joined
Executable file
86
opensem/hooks/log_rotate-relation-joined
Executable file
@@ -0,0 +1,86 @@
|
||||
#!/bin/bash
|
||||
|
||||
## Should be executable N time in a row with same result.
|
||||
|
||||
. lib/common
|
||||
|
||||
set -e
|
||||
|
||||
LOGS=/var/log/opensem
|
||||
|
||||
php_fpm_service=$(service:traverse "$SERVICE_NAME":php-fpm) || {
|
||||
err "Could not find php-fpm service for $SERVICE_NAME"
|
||||
exit 1
|
||||
}
|
||||
|
||||
uid_gid=$(get_service_base_image_dir_uid_gid "$php_fpm_service" /var/www/html) || {
|
||||
err "Could not determine uid:gid for $php_fpm_service of dir /var/www/html"
|
||||
exit 1
|
||||
}
|
||||
|
||||
gid="${uid_gid#* }"
|
||||
|
||||
dirs=(
|
||||
"$LOGS"
|
||||
)
|
||||
|
||||
to_create=()
|
||||
volumes=""
|
||||
for d in "${dirs[@]}"; do
|
||||
fdir="${SERVICE_DATASTORE}$d"
|
||||
if [ -d "$fdir" ]; then
|
||||
find "$fdir" \! -gid "$gid" -print0 | while read-0 f; do
|
||||
chgrp -v "$gid" "$f" || return 1
|
||||
done
|
||||
find "$fdir" \! -perm -g+rwx -print0 | while read-0 f; do
|
||||
chmod -v g+rwx "$f" || return 1
|
||||
done
|
||||
else
|
||||
to_create+=("$fdir")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "${#to_create[@]}" -gt 0 ]; then
|
||||
mkdir -p "${to_create[@]}" || return 1
|
||||
chgrp -v "${gid}" "${to_create[@]}" || return 1
|
||||
chmod g+rwx "${to_create[@]}" || return 1
|
||||
fi
|
||||
|
||||
|
||||
rotated_count=$(relation-get rotated-count 2>/dev/null) || true
|
||||
rotated_count=${rotated_count:-52}
|
||||
|
||||
## XXXvlab: a lot of this intelligence should be moved away into ``logrotate`` charm
|
||||
DST="$CONFIGSTORE/$TARGET_SERVICE_NAME/etc/logrotate.d/$SERVICE_NAME"
|
||||
file_put "$DST" <<EOF
|
||||
/var/log/docker/$SERVICE_NAME/laravel.log {
|
||||
weekly
|
||||
missingok
|
||||
dateext
|
||||
dateyesterday
|
||||
dateformat _%Y-%m-%d
|
||||
extension .log
|
||||
rotate $rotated_count
|
||||
compress
|
||||
delaycompress
|
||||
notifempty
|
||||
create 640 root root
|
||||
sharedscripts
|
||||
}
|
||||
EOF
|
||||
|
||||
opensem:config-set "LOG_CHANNEL" "single" || {
|
||||
err "Could not set LOG_CHANNEL=single in opensem config"
|
||||
exit 1
|
||||
}
|
||||
|
||||
config-add "\
|
||||
services:
|
||||
$MASTER_TARGET_SERVICE_NAME:
|
||||
volumes:
|
||||
- $DST:/etc/logrotate.d/docker-${SERVICE_NAME}:ro
|
||||
- $SERVICE_DATASTORE$LOGS:/var/log/docker/$SERVICE_NAME:rw
|
||||
$php_fpm_service:
|
||||
volumes:
|
||||
- $SERVICE_DATASTORE$LOGS:/opt/apps/$SERVICE_NAME/storage/logs:rw
|
||||
"
|
||||
Reference in New Issue
Block a user