Setting up Joplin: WebDAV and FreeBSD rc.d
I originally wrote this post back in 2018 but actually getting around to publishing it never happened. Oops! I still use Joplin every day, so I figured I'd update and publish this post.
I've used so many notes systems over the years. OneNote and Google Keep immediately come to mind, and occasionally I use the Apple Notes app now that I've become a pleb Mac and iPhone owner. These systems are great -- for jotting down short thoughts. Anything larger than a Post-It winds up being hard to read and filter through.
Digging through GitHub, I found one called Joplin, that has desktop and mobile clients, and even supports markdown for creating the notes. Neat! Of course, the desktop client is built with Electron, but I'll try not to hold that against it 😂
There's a lot of cool applications built with Electron, but there's no denying Chrome is a memory-hungry beast.
Poking around the client, the first thing I went looking for was a way to remotely sync. There are a few cloud provider options included, such as OneDrive, Dropbox and Nextcloud. I'm not crazy about them though; I have this fancy private server, we may as well use it! Fortunately, Joplin also has support for WebDAV. Having already set up a web server for my blog, I figured setting up WebDAV couldn't be too difficult.
There's plenty of choices for WebDAV. Nginx even has support for it out of the box, but that seems a bit overkill. In the interest of keeping things simple, I turned to GitHub once again to see what else was out there. I found one that looked solid -- dave, and it's written in Go? Awesome!
Configuration is simple: the built repo includes a davecli
command to generate a hashed password for your WebDAV users.
A few extra fields are all you need to specify the port the server listens on and where to dump the files. My dave.yml looks something like this:
address: "0.0.0.0"
port: "80"
dir: "/var/db/webdav"
prefix: "/"
users:
aNotesUser:
subdir: "/a/notes/subdir"
password: <davecli hash here>
Simple, right?
I've written before about how awesome the jails mechanism in FreeBSD is. A few commands later and I had a nice-and-simple WebDAV server contained. But we're not done yet. Unfortunately the WebDAV server doesn't have a service script included. No problem! The FreeBSD website has an article on setting one up. Below is how I've configured the WebDAV service script in my jail:
#!/bin/sh
# PROVIDE: webdav
# REQUIRE: DAEMON
# KEYWORD: shutdown
. /etc/rc.subr
name=dave
rcvar=dave_enable
conf_path="/usr/local/etc/${name}.yml"
command="/usr/local/bin/${name}"
pidfile="/var/run/${name}.pid"
required_files="${conf_path}"
start_cmd="/usr/sbin/daemon -f -c -p ${pidfile} ${command} --config ${conf_path}"
load_rc_config $name
run_rc_command "$1"
With this script installed in /usr/local/etc/rc.d/dave
, all it takes to get started is a sysrc dave_enable="YES"
and a service dave start
. Easy!
Should the jail ever need to restart, we don't have to do any legwork to get our notes syncing again. The wonders of a proper init system!