DavMail Monit HowTo
I recently started to monitor my servers with monit. As such, I started creating scripts for all services that needed monitoring until I got stuck on one of them DavMail. It did not write a pid file and didn't even had a specific process name!
This HowTo is meant to run on an ubuntu/debian system.
I started googling for a solution and it was not easy. The problem was with java not allowing or providing a way to change the process name of a jvm.
The solution I found was Java Service Wrapper and bellow are the steps on how to use it.
First of all, download the debian DavMail package:
Since this is to be installed on a headless server, we need to remove some of the dependencies of the package:
Now you’ll have a DEBIAN directory, cd
into it:
Now edit the control file:
Delete the line which starts with Depends:
, save and exit. Now we’ll
have to update the package with the new control file:
Now install the new package:
To configure DavMail, follow their server setup.
My davmail.properties
is saved on /etc/davmail/davmail.properties
Now comes the wrapper part. Download the community debian package from here.
For example:
Unpack it:
tar zxvf wrapper-linux-x86-64-3.5.7.tar.gz
The method I followed is the Simple App Wrapper.
So in baby steps…:
Now, let’s edit some files:
Here’s what I changed:
# Application
APP_NAME="davmail"
APP_LONG_NAME="DAVMail Exchange Gateway"
# Wrapper
WRAPPER_CMD="./davmail"
WRAPPER_CONF="../conf/wrapper.conf"
# Location of the pid file.
PIDDIR="/var/run/davmail"
# If specified, the Wrapper will be run as the specified user.
# IMPORTANT - Make sure that the user has the required privileges to write
# the PID file and wrapper.log files. Failure to be able to write the log
# file will cause the Wrapper to exit without any way to write out an error
# message.
# NOTE - This will set the user which is used to run the Wrapper as well as
# the JVM and is not useful in situations where a privileged resource or
# port needs to be allocated prior to the user being changed.
RUN_AS_USER=mail
Here’s what I changed:
# Java Main . This implement the WrapperListener WrapperManager initialized. Helper
# or guarantee that the # classes are provided to do this for you. See the Integration section
# of the documentation for details.
wrapper.java.main, disables log rolling. May abbreviate with the 'k' or
# 'm' suffix. For example: 10m
Let's test it:
It's running!!!!
Now, the monit configuration file:
check process davmail with pidfile /var/run/davmail/davmail.pid
group mail
start program = "/usr/share/davmail/bin/davmail-launcher start"
stop program = "/usr/share/davmail/bin/davmail-launcher stop"
if failed host YOUR_SERVER_PUBLIC_FQDN port IMAP_PORT protocol imap then restart
if 5 restarts within 5 cycles then timeout
Make sure you replace YOUR_SERVER_PUBLIC_FQDN
and IMAP_PORT
with
what’s you’ve setup on your davmail.properties
.
For the sake of completeness, here’s my davmail.properties
,
obviously obscured where needed :)
.allowRemote=true
.bindAddress=YOUR_PUBLIC_ADDRESS
.caldavPastDelay=90
.caldavPort=11080
.disableUpdateCheck=false
.enableEws=true
.enableProxy=false
.imapIdleDelay=
.imapPort=11143
.keepDelay=30
.ldapPort=11389
.logFilePath=/var/log/davmail.log
.popPort=11110
.proxyHost=
.proxyPassword=
.proxyPort=
.proxyUser=
.sentKeepDelay=90
.server=true
.server.certificate.hash=
.smtpPort=11025
.ssl.keyPass=
.ssl.keystoreFile=
.ssl.keystorePass=
.ssl.keystoreType=JKS
.url=https\://YOUR_EXCHANGE_DOMAIN/owa
.useSystemProxies=false
.logger.davmail=DEBUG
.logger.httpclient.wire=WARN
.logger.org.apache.commons.httpclient=WARN
.rootLogger=WARN
And that’s it, hope you find this useful. If you find anything confusing, let me know…