DAViCal Calendar Server
19 Aug 2014
I run a local calendar server that allows my family members to share calendars between their devices.
The server is a Raspberry Pi running DAViCal and an additional web interface on top of Apache. More recently, I rebuilt the server using Ansible playbooks for configuration and maintenance. I also created my own certificate authority to allow client devices to connect over SSL.
Aside from my website, this is my longest-running project.
Below are my notes from when I first created the server, updated with some of the knolwedge I now have (and a bit of copy-editing).
Installation Notes
My current server is configured using my Ansible project, so these notes don’t completely match how my server currently runs, but they should be similar.
DAViCal is a simple Linux calendar server application that runs on top of any standard web server (such as Apache).
There are other CalDAV servers, but I chose DAViCal because I could install it from a repository. Lazy? Slightly, I’ll admit. (You might want to look into the other servers if you want a more feature rich interface or a built in calendar web app).
Several years later, DAViCal has been been pretty reliable, works well with all the devices my family owns, and has an active and helpful mailing list, so I think it was a good choice.
Since I had two Raspberry Pi’s lying around doing nothing, I decided to turn one into a calendar server.
Server
The DAViCal installation notes are pretty good, so I won’t repeat them here.
I installed Apache2 from the Raspbian repositories, and then DAViCal.
A few tips:
- make sure the prerequisites are installed before installing DAViCal
- make sure to add the permissions for DAViCal in the posgresql config file
- make sure to run the create-database.sh script as the postgresql user
- make sure to write down the admin password that this script prints out on your terminal!! (It's annoying to find otherwise.)
- put a config file in /etc/davical/config.php
- reboot the system to load the config (Yes, some Linux buffs might tell me that "It's, Linux. You never need to reboot." But DAViCal doesn't seem to want to fit that motto, as there is no sudo service restart davical, so restarting the system is the easiest option)
Configuring iOS Clients
- go to settings > mail, contacts, calendars > add account...
- select "other" and then "CalDAV"
- enter the server IP or domain, the user account to be used when connecting, the password, and any description you like
- Wait, wait, and wait some more! This could take a while! Its the worst part of the process, but don't leave this screen until the error message appears.
- When the error message appears, click "cancel".
- Go to the advanced settings.
- Set the port as 80 (or whatever the web server is on).
- Make the account URL look like this: http://[SERVER IP]/davical/caldav.php/[DAVICAL USER NAME] (If DAViCal is installed in your server root directory, remove davical from the URL. Or replace it with whatever your subdirectory is called.)
- Hopefully your device should start to load the calendars on the server (unless this is the first device to access the server and there really nothing there yet). When you have a lot of events, this could take some time.
The recent versions of iOS and Mac OS don’t like to authenticate over plaintext (thanks to the DAViCal mailing list for identifying this problem), so you’ll need to configure your server with a certificate. This is relatively easy to do if you follow the guides available online for creating your own certificate authority.
Configuring Other Clients
The built-in Calendars client in Mac OS works similar to the iOS configuration above. There are other desktop clients for other operating systems, but I couldn’t get them to behave as nicely as the iOS and Mac devices.
Note that before start creating events with a new calendar client, it is good idea to check the client’s default settings for event alerts. One Mac my family had kept adding reminders that went off the day before each. Default settings like these can cause a lot of irritation once those reminders sync to everyone else who connects to the server.
Getting a Desktop Client (sort of)
The desktop clients I tried just didn’t work well. So while looking for other ones to try, I found CalDAVzap, an open source CalDAV web application. So I downloaded it and unzipped the file into my web server. After some short configuration (use the readme file, Luke!), I got the client working.
Though I usually dislike web applications, I realized that web applications that you can run on your own server are awesome. This one is really nice, and works just as good as the iOS clients (though slower). Now I have an easy way to access and update my calendar from any device.
Making Database Backups
DAViCal stores everything in a SQL database; it’s a good idea to back this up once and a while.
Review the Backups guide on the DAViCal wiki before you start. The actual backup is as simple as:
sudo -u postgres pg_dump -Fc davical > /home/pi/davical-backup-$(date -u +"%FT%H%M%S%Z").pgdump
(The call to date
is not necessary, but gives the backup a filename that includes a date and timestamp.)
Backup Restoration
- Follow the installation guide to setup a new server if you are restoring your backup onto a different server.
- The database must be empty before a backup can be restored. Carefully run su postgres -c 'dropdb davical' Make sure you don't delete anything important.
- Create a new database createdb --owner davical_dba --encoding UTF8 --template template0 davical
- Restore your backup pg_restore -Fc -d davical davical.pgdump
Other Notes
- DAViCal is really easy to set up for your home network, where you trust all of the devices inside. There is a permissions structure that should allow you to host a calendar on the public internet while only giving certain users access, but it may be difficult to configure with various clients. Also, the server and DAViCal may require a bit more securing before using on a network you don’t trust.
- If the server is inside your home’s router and you leave your home (and don’t have a VPN), then your devices won’t be able to access the calendar server. However, a calendar client often has a local copy that it synchronises with the server, so when you are out and about, you can continue to edit your calendars like normal, and then later, when you return home, your device will synchronise the events you added or modified. It is likely, however, that if you have synchronization issues, it occurred when one or more devices were away from the local network for some period of time.