Managing users and home dirs

deano-dovecot at deano-dovecot at
Sat Jun 21 15:12:16 UTC 2014


For those of you using virtual users, and SQL, how are you managing
your users and their home dirs ? That is, what process do you use for
adding/deleting users, creating their home dirs etc ? I suppose it's
easy enough to do manually, inserting rows in the database, creating
dirs, chown/chmod yada yada, but there must be a better way to do it ...
If you're doing dovecot replication then it gets even more cumbersome,
having to duplicate the effort in two places (and make sure it's

I have a nice test setup using Percona XtraDB Clustering in
a 3-node cluster which works swimmingly, albeit in VMs only at the
moment. A master DB node and two dovecot nodes. Dovecot replication is
up and running nicely too, and I almost have all the communications
going over ipsec tunnels, so it will be nice and secure. 

I'm thinking
of something like a cronjob with two tasks, the first would periodically
scan the home dirs and compare the users to what's in the database. When
it finds a new userdir (plus a file labeled PASSWD) the script would add
the user to the database, create the Maildir and whatever else, then
delete the PASSWD file. DB replication will push that to the other

The second task is scanning the user database and comparing to
the home dirs - basically opposite of the first cronjob. When it finds a
user in the DB that doesn't have a home dir, it would create it and
whatever else is needed. 

This way, to add a user one would just create
a PASSWD file in /var/mail/ on either of
the dovecot replication partner systems. The first cronjob task would
discover the newusername dir, create the user in the DB, create the
Maildir, chown/chmod etc. and delete the PASSWD file, so it's ready to
go on that system. DB replication pushes the user table to the other
nodes. The second task on the other dovecot system will discover a new
user in the DB that doesn't have a home dir, and do its thing to create
it all. 

So the whole create-a-new-user process becomes something like
this on either dovecot system : 

mkdir -p
/var/mail/ ; echo "changeme" >

A max of 5 minutes later the
user is added to the database, and the home dir/Maildir/etc/etc is
created on both dovecot systems. 


More information about the dovecot mailing list