Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow doveadm to log into dovecot.conf configured facility (like syslog) #156

Closed
wants to merge 1 commit into from

Conversation

arekm
Copy link
Contributor

@arekm arekm commented Feb 11, 2021

Add -s option that causes doveadm log into configured facility instead of stderr.

Rationale:
doveadm can be run from system scripts to do some jobs like expiring folders. Unfortunately it doesn't log anything into syslog and instead forces stderr logging.

With this change doveadm can log into logging facility configured in dovecot.conf

Example:

protocol doveadm {
  mail_plugins = $mail_plugins mail_log notify acl
}
plugin {
  mail_log_events = delete undelete expunge copy mailbox_delete
mailbox_rename save
}

and

$ sudo doveadm -s expunge -u arekm mailbox INBOX.Test savedbefore 0d
$ tail -n 2 /var/log/maillog
Feb 11 18:36:11 ixion dovecot[875844]: doveadm(arekm): expunge: box=INBOX.Test, uid=47, msgid=<5b2e2a9c6e2fa387a89de052259248bc@example.com>, size=4693
Feb 11 18:36:12 ixion dovecot[875864]: doveadm(arekm): expunge: box=INBOX.Test, uid=48, msgid=<4b389ac5180b609c0e4b5bdaac76793e@example.coml>, size=5162

Add -s option that causes doveadm log into configured facility
instead of stderr.
@sirainen
Copy link
Contributor

Hmm. Alternatively you could run (most of) the commands via doveadm-server:

sudo doveadm expunge -S /var/run/dovecot/doveadm-server -u arekm mailbox INBOX.Test savedbefore 0d

@arekm
Copy link
Contributor Author

arekm commented Feb 12, 2021

That solutions partially works with few bugs.

When works:

Feb 12 08:16:14 mbox0 dovecot: doveadm: expunge: box=INBOX.Spam, uid=187, msgid=4b389ac5180b609c0e4b5bdaac76793e@example.com, size=5162

but no user is logged (should be like: dovecot: doveadm(someuser): ... right?)

When doesn't work it crashes:

/usr/bin/doveadm expunge -S /var/run/dovecot/doveadm-server -A mailbox INBOX.Test savedbefore 31d
doveadm(kaska): Error: remote(/var/run/dovecot/doveadm-server): Syncing mailbox 'INBOX.Test' failed: Mailbox doesn't exist: INBOX.Spam
doveadm(kaska): Error: doveadm server disconnected before handshake: EOF

doveadm(kaska): Error: /var/run/dovecot/doveadm-server: Command expunge failed for andrzejx: EOF
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(weird, logs on stdout/stderr as user "kaska" but reports failure for user "andrzejx")

doveadm(kaska): Error: doveadm server failure
doveadm: Error: Failed to iterate through some users
(gdb) bt
#0  0x00007fe285d7ccc8 in ?? () from /usr/lib64/libclucene-core.so.1
#1  0x00007fe285ce081f in _lucene_shutdown() () from /usr/lib64/libclucene-core.so.1
#2  0x00007fe28952e61a in module_dir_deinit () from /usr/lib64/dovecot/libdovecot.so.0
#3  0x00007fe28952e671 in module_dir_unload () from /usr/lib64/dovecot/libdovecot.so.0
#4  0x00007fe28963a6f9 in mail_storage_service_deinit () from /usr/lib64/dovecot/libdovecot-storage.so.0
#5  0x0000565301b16722 in ?? ()
#6  0x0000565301b17583 in doveadm_cmd_ver2_to_mail_cmd_wrapper ()
#7  0x0000565301b27aec in doveadm_cmd_run_ver2 ()
#8  0x0000565301b2bc0c in ?? ()
#9  0x00007fe289524069 in io_loop_call_io () from /usr/lib64/dovecot/libdovecot.so.0
#10 0x00007fe2895256a2 in io_loop_handler_run_internal () from /usr/lib64/dovecot/libdovecot.so.0
#11 0x00007fe289524110 in io_loop_handler_run () from /usr/lib64/dovecot/libdovecot.so.0
#12 0x00007fe2895242d0 in io_loop_run () from /usr/lib64/dovecot/libdovecot.so.0
#13 0x00007fe28949a403 in master_service_run () from /usr/lib64/dovecot/libdovecot.so.0
#14 0x0000565301b06791 in main ()

Even if there are mails to be expunged before crash it doesn't log with proper user on syslog and logs with wrong user on stdout/stderr:

example.com is in andrzejs/.Test folder and:

syslog:

Feb 12 08:51:38 mbox0 dovecot: doveadm: expunge: box=INBOX.Test, uid=1, msgid=<4b389ac5180b609c0e4b5bdaac76793e@example.com>, size=5162

stdout/stderr:

doveadm(kaska): Info: remote(/var/run/dovecot/doveadm-server): expunge: box=INBOX.Test, uid=1, msgid=<4b389ac5180b609c0e4b5bdaac76793e@example.com>, size=5162
(then it crashes like shown earlier)

@cmouse
Copy link
Contributor

cmouse commented Feb 12, 2021

The crash appears to happen in lucene deinit.

@sirainen
Copy link
Contributor

The lack of username in doveadm log prefix is annoying, yes. We've been tracking it internally in DOP-2184 but haven't had time to implement yet.

@arekm
Copy link
Contributor Author

arekm commented Mar 15, 2021

protocol doveadm {
  mail_plugins = $mail_plugins mail_log notify acl
}
# doveadm expunge -u wojtass mailbox INBOX.abc savedbefore 31d
doveadm(wojtass): Error: Syncing mailbox 'INBOX.abc' failed: Mailbox doesn't exist: INBOX.abc

started implementing logging in my own wrapper (so this pull request could be closed without merging) on top of doveadm (without doveadm-server) but doveadm logging is more broken or it runs wrong commands. Running expunge and it tells me it does syncing (uh?).

@cmouse
Copy link
Contributor

cmouse commented Mar 16, 2021

protocol doveadm {
  mail_plugins = $mail_plugins mail_log notify acl
}
# doveadm expunge -u wojtass mailbox INBOX.abc savedbefore 31d
doveadm(wojtass): Error: Syncing mailbox 'INBOX.abc' failed: Mailbox doesn't exist: INBOX.abc

started implementing logging in my own wrapper (so this pull request could be closed without merging) on top of doveadm (without doveadm-server) but doveadm logging is more broken or it runs wrong commands. Running expunge and it tells me it does syncing (uh?).

Mailbox indexes are usually syncronized when opened.

@arekm
Copy link
Contributor Author

arekm commented Mar 16, 2021

Ok, so my wrapper works fine and this pull request is not needed.

Nicer solution will be to use doveadm-server (when it gets fixed to work reliably).

@arekm arekm closed this Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants