Files
dokku/plugins/20_events/install
Jose Diaz-Gonzalez d55ba8e189 fix: detect correct init when interacting with rsyslog on install
This change also skips running a restart of rsyslog as during install, the service isn't properly initiated. While this breaks upgrades of Dokku within containers, that is not how upgrades of container-based Dokku should work, so this is a fine trade-off.
2024-09-21 17:20:19 -04:00

116 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
trigger-events-install() {
declare desc="20_events install plugin trigger"
declare trigger="install"
DOKKU_RSYSLOG_FILTER_DIR=/etc/rsyslog.d
DOKKU_RSYSLOG_FILTER=$DOKKU_RSYSLOG_FILTER_DIR/99-dokku.conf
DOKKU_LOGROTATE_FILE=/etc/logrotate.d/dokku
flag_rsyslog_needs_restart=n
# This can be done unconditionally as mkdir -p
# exits gracefully if the path already exists
mkdir -m 775 -p "$DOKKU_LOGS_DIR"
case "$DOKKU_DISTRO" in
arch | debian | raspbian)
chgrp dokku "$DOKKU_LOGS_DIR"
;;
*)
chown syslog:dokku "$DOKKU_LOGS_DIR"
;;
esac
if [[ ! -f "$DOKKU_EVENTS_LOGFILE" ]]; then
touch "$DOKKU_EVENTS_LOGFILE"
case "$DOKKU_DISTRO" in
arch | debian | raspbian)
chgrp dokku "$DOKKU_EVENTS_LOGFILE"
;;
*)
# chown syslog:root might not work on SUSE
chown syslog:dokku "$DOKKU_EVENTS_LOGFILE"
;;
esac
chmod 664 "$DOKKU_EVENTS_LOGFILE"
fi
if [[ -d "$DOKKU_RSYSLOG_FILTER_DIR" && ! -f "$DOKKU_RSYSLOG_FILTER" ]]; then
cat >"$DOKKU_RSYSLOG_FILTER" <<EOF
:syslogtag, contains, "dokku-event" $DOKKU_EVENTS_LOGFILE
EOF
flag_rsyslog_needs_restart=y
fi
if [[ -f "$DOKKU_RSYSLOG_FILTER" ]] && ! grep -q "dokku-event" "$DOKKU_RSYSLOG_FILTER"; then
cat >"$DOKKU_RSYSLOG_FILTER" <<EOF
:syslogtag, contains, "dokku-event" $DOKKU_EVENTS_LOGFILE
EOF
flag_rsyslog_needs_restart=y
fi
if [[ ! -f "$DOKKU_LOGROTATE_FILE" ]]; then
cat >"$DOKKU_LOGROTATE_FILE" <<EOF
$DOKKU_LOGS_DIR/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
copytruncate
}
EOF
if [[ "$DOKKU_DISTRO" == "debian" ]] || [[ "$DOKKU_DISTRO" == "raspbian" ]]; then
sed -i 's/ syslog dokku$/ root dokku/g' $DOKKU_LOGROTATE_FILE
fi
flag_rsyslog_needs_restart=y
fi
local systemctl_path=/bin/systemctl
if [[ -x /usr/bin/systemctl ]]; then
systemctl_path=/usr/bin/systemctl
fi
if [[ -f "$DOKKU_RSYSLOG_FILTER" ]] && [[ "$flag_rsyslog_needs_restart" == "y" ]]; then
case "$DOKKU_DISTRO" in
debian | raspbian)
if [[ -x "$systemctl_path" ]]; then
systemctl restart rsyslog
else
/usr/sbin/invoke-rc.d rsyslog restart
fi
;;
ubuntu)
if [[ "$DOKKU_INIT_SYSTEM" == "sv" ]]; then
# avoid failing runit init calls on install
# the runit binaries are not yet available during dockerfile building
true
elif [[ -x "$systemctl_path" ]]; then
systemctl restart rsyslog
elif [[ -x /usr/bin/sv ]]; then
# avoid failing runit init calls on install
# the runit binaries are not yet available during dockerfile building
true
else
invoke-rc.d rsyslog restart
fi
;;
arch)
systemctl restart rsyslog
;;
esac
fi
[[ ! "$DOKKU_EVENTS" ]] || dokku_log_plugn_trigger_call "$(basename "$0")" "$@"
exit 0
}
trigger-events-install "$@"