这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dokku
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export PLUGIN_PATH=${PLUGIN_PATH:="/var/lib/dokku/plugins"}
export DOKKU_NOT_IMPLEMENTED_EXIT=10
export DOKKU_VALID_EXIT=0

export DOKKU_LOGS_DIR=${DOKKU_LOGS_DIR:="/var/log/dokku"}
export DOKKU_EVENTS_LOGFILE=${DOKKU_EVENTS_LOGFILE:="$DOKKU_LOGS_DIR/events.log"}

source "$PLUGIN_PATH/common/functions"

[[ -f $DOKKU_ROOT/dokkurc ]] && source $DOKKU_ROOT/dokkurc
Expand Down
1 change: 1 addition & 0 deletions plugins/20_events/backup-check
1 change: 1 addition & 0 deletions plugins/20_events/backup-export
1 change: 1 addition & 0 deletions plugins/20_events/backup-import
1 change: 1 addition & 0 deletions plugins/20_events/bind-external-ip
1 change: 1 addition & 0 deletions plugins/20_events/check-deploy
55 changes: 55 additions & 0 deletions plugins/20_events/commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"

PLUGIN_DIR="$(dirname $0)"

case "$1" in
events)
if [[ -f $DOKKU_EVENTS_LOGFILE ]] ; then
if [[ $2 == "-t" ]]; then
tail -f $DOKKU_EVENTS_LOGFILE
else
tail -n 100 $DOKKU_EVENTS_LOGFILE
fi
fi
;;

events:on)
echo "Enabling dokku events logger"
[[ -d $DOKKU_ROOT/.dokkurc ]] || mkdir -p $DOKKU_ROOT/.dokkurc
echo "export DOKKU_EVENTS=1" > $DOKKU_ROOT/.dokkurc/DOKKU_EVENTS
;;

events:off)
echo "Disabling dokku events logger"
rm -f $DOKKU_ROOT/.dokkurc/DOKKU_EVENTS
;;

events:list)
if [[ "$DOKKU_EVENTS" ]]; then
logged="$(find $PLUGIN_DIR -type l -printf '%f ' | sort)"
dokku_col_log_info2_quiet "Events currently logged"
for hook in $logged ; do
dokku_col_log_msg "$hook"
done
else
dokku_log_warn "Events logger disabled"
fi
;;

help | events:help)
cat && cat<<EOF
events [-t] Show the last events (-t follows)
events:list List logged events
events:on Enable events logger
events:off Disable events logger
EOF
;;

*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;

esac

1 change: 1 addition & 0 deletions plugins/20_events/dependencies
1 change: 1 addition & 0 deletions plugins/20_events/docker-args-build
1 change: 1 addition & 0 deletions plugins/20_events/docker-args-deploy
1 change: 1 addition & 0 deletions plugins/20_events/docker-args-run
1 change: 1 addition & 0 deletions plugins/20_events/git-post-pull
1 change: 1 addition & 0 deletions plugins/20_events/git-pre-pull
5 changes: 5 additions & 0 deletions plugins/20_events/hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"

[[ ! "$DOKKU_EVENTS" ]] || dokku_log_pluginhook_call "$(basename $0)" "$@"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This question may be naive, but any reason we're doing a double negative here. More directly why not do this?

[[ "$DOKKU_EVENTS" ]] && dokku_log_pluginhook_call "$(basename $0)" "$@"

EDIT: This would also be consistent with plugins/20_events/install.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Wed, Jul 1, 2015 at 6:50 PM, Michael Hobbs notifications@github.com wrote:

This question may be naive, but any reason we're doing a double negative here. More directly why not do this?

It's just my personal preference, but if that breaks the code style
I'm more than happy to fix it then.

Alessio Treglia | www.alessiotreglia.com
Debian Developer | alessio@debian.org
Ubuntu Core Developer | quadrispro@ubuntu.com
0416 0004 A827 6E40 BB98 90FB E8A4 8AE5 311D 765A

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, actually due set -e if $DOKKU_EVENTS is unset the hook would return 1, and that would break the plugins chain, wouldn't it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 😄

54 changes: 54 additions & 0 deletions plugins/20_events/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"

DOKKU_RSYSLOG_FILTER=/etc/rsyslog.d/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"
chown syslog:dokku "$DOKKU_LOGS_DIR"

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
flag_rsyslog_needs_restart=y
fi

if [[ ! -f "$DOKKU_LOGROTATE_FILE" ]]; then
cat >"$DOKKU_LOGROTATE_FILE" <<EOF
$DOKKU_LOGS_DIR/*.log {
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
service rsyslog restart
fi

[[ ! "$DOKKU_EVENTS" ]] || dokku_log_pluginhook_call "$(basename $0)" "$@"

exit 0
1 change: 1 addition & 0 deletions plugins/20_events/nginx-hostname
1 change: 1 addition & 0 deletions plugins/20_events/nginx-pre-reload
1 change: 1 addition & 0 deletions plugins/20_events/post-build-buildstep
1 change: 1 addition & 0 deletions plugins/20_events/post-build-dockerfile
1 change: 1 addition & 0 deletions plugins/20_events/post-delete
1 change: 1 addition & 0 deletions plugins/20_events/post-deploy
1 change: 1 addition & 0 deletions plugins/20_events/post-domains-update
1 change: 1 addition & 0 deletions plugins/20_events/post-release-buildstep
1 change: 1 addition & 0 deletions plugins/20_events/post-release-dockerfile
1 change: 1 addition & 0 deletions plugins/20_events/pre-build-buildstep
1 change: 1 addition & 0 deletions plugins/20_events/pre-build-dockerfile
1 change: 1 addition & 0 deletions plugins/20_events/pre-delete
1 change: 1 addition & 0 deletions plugins/20_events/pre-deploy
1 change: 1 addition & 0 deletions plugins/20_events/pre-release-buildstep
1 change: 1 addition & 0 deletions plugins/20_events/pre-release-dockerfile
1 change: 1 addition & 0 deletions plugins/20_events/receive-app
1 change: 1 addition & 0 deletions plugins/20_events/update
11 changes: 11 additions & 0 deletions plugins/common/functions
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ dokku_log_fail() {
exit 1
}

dokku_log_event() {
logger -t dokku -i -- "$@"
}

dokku_log_pluginhook_call() {
local l_hook

l_hook="$1" ; shift
dokku_log_event "INVOKED: ${l_hook}( $@ )"
}

dokku_container_log_verbose_quiet() {
CID=$1;
shift
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/events.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bats

load test_helper

setup() {
create_app
}

teardown() {
destroy_app
}

@test "(events) check conffiles" {
run bash -c "test -f /etc/logrotate.d/dokku"
echo "output: "$output
echo "status: "$status
assert_success
run bash -c "test -f /etc/rsyslog.d/99-dokku.conf"
echo "output: "$output
echo "status: "$status
assert_success
run bash -c "stat -c '%U:%G:%a' /var/log/dokku/"
echo "output: "$output
echo "status: "$status
assert_output "syslog:dokku:775"
run bash -c "stat -c '%U:%G:%a' /var/log/dokku/events.log"
echo "output: "$output
echo "status: "$status
assert_output "syslog:dokku:664"
}

@test "(events) log commands" {
run dokku events:on
deploy_app
run dokku events
echo "output: "$output
echo "status: "$status
assert_success
run dokku events:off
}