2015-06-26 13:14:04 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
|
|
|
|
source "$(dirname $0)/../common/functions"
|
|
|
|
|
|
2015-06-26 15:12:55 +01:00
|
|
|
DOKKU_RSYSLOG_FILTER=/etc/rsyslog.d/99-dokku.conf
|
2015-06-28 23:25:50 +01:00
|
|
|
DOKKU_LOGROTATE_FILE=/etc/logrotate.d/dokku
|
|
|
|
|
|
|
|
|
|
flag_rsyslog_needs_restart=n
|
2015-06-26 15:12:55 +01:00
|
|
|
|
2015-07-01 18:25:11 +01:00
|
|
|
# This can be done unconditionally as mkdir -p
|
|
|
|
|
# exits gracefully if the path already exists
|
|
|
|
|
mkdir -m 775 -p "$DOKKU_LOGS_DIR"
|
|
|
|
|
chown syslog:dokku "$DOKKU_LOGS_DIR"
|
|
|
|
|
|
2015-06-26 13:14:04 +01:00
|
|
|
if [[ ! -f "$DOKKU_EVENTS_LOGFILE" ]]; then
|
|
|
|
|
touch "$DOKKU_EVENTS_LOGFILE"
|
|
|
|
|
# chown syslog:root might not work on SUSE
|
|
|
|
|
chown syslog:dokku "$DOKKU_EVENTS_LOGFILE"
|
|
|
|
|
chmod 664 "$DOKKU_EVENTS_LOGFILE"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ ! -f "$DOKKU_RSYSLOG_FILTER" ]]; then
|
|
|
|
|
cat >"$DOKKU_RSYSLOG_FILTER" <<EOF
|
|
|
|
|
:syslogtag, contains, "dokku" $DOKKU_EVENTS_LOGFILE
|
|
|
|
|
EOF
|
2015-06-28 23:25:50 +01:00
|
|
|
flag_rsyslog_needs_restart=y
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ ! -f "$DOKKU_LOGROTATE_FILE" ]]; then
|
|
|
|
|
cat >"$DOKKU_LOGROTATE_FILE" <<EOF
|
2015-07-01 18:25:11 +01:00
|
|
|
$DOKKU_LOGS_DIR/*.log {
|
2015-06-28 23:25:50 +01:00
|
|
|
daily
|
|
|
|
|
rotate 7
|
|
|
|
|
missingok
|
|
|
|
|
notifempty
|
|
|
|
|
su syslog dokku
|
|
|
|
|
compress
|
|
|
|
|
delaycompress
|
|
|
|
|
postrotate
|
|
|
|
|
reload rsyslog >/dev/null 2>&1 || true
|
|
|
|
|
endscript
|
|
|
|
|
create 664 syslog dokku
|
|
|
|
|
}
|
|
|
|
|
EOF
|
|
|
|
|
flag_rsyslog_needs_restart=y
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ "$flag_rsyslog_needs_restart" == "y" ]]; then
|
2015-06-27 10:20:07 +01:00
|
|
|
service rsyslog restart
|
2015-06-26 15:11:42 +01:00
|
|
|
fi
|
2015-06-26 13:14:04 +01:00
|
|
|
|
2015-07-01 19:48:09 +01:00
|
|
|
[[ ! "$DOKKU_EVENTS" ]] || dokku_log_pluginhook_call "$(basename $0)" "$@"
|
2015-06-26 13:14:04 +01:00
|
|
|
|
|
|
|
|
exit 0
|