In a recent project I had the need for automatically starting a Datomic transactor when booting a Mac server. On Mac OS systems and some other Linux/BSD systems, starting and stopping programs is handled by the launchd
program.
In this post I will briefly describe the steps needed for setting up a Datomic transactor with launchd
to ensure that it is automatically started when booting the system.
Datomic comes in a free and a commercial version. Here I will assume you have downloaded the free version from http://www.datomic.com into the ~/Downloads
folder on your system.
In a terminal, create an appropiate place for your Datomic installation.
The Datomic process should run under a restricted privilege user. I recommend creating a dedicated user and group for this purpose. First, check that the group id and user id 109 is free on your system. If it is not, use another free id. You can check the numbers using dscl
The following commands will create the group _datomic
and the user _datomic
We need to make sure the user and group of the Datomic installation itself is root
and wheel
. We also need to make sure the _datomic
user which is going to run the process will have a place to write the logs and data from the database. In this tutorial, I have chosen to place the data and logs under /usr/local/
. If you have a dedicated place for data on your system, such as /opt
, you should put it there instead
You need to set the log and data directory in the transactor properties file. In this tutorial, I’ve used the template file from config/samples/free-transactor-template.properties
in the installed Datomic system. The edited file is placed in /usr/local/datomic/config/free-transactor.properties
.
launchd
reads plist files to determine which programs to start when booting the system. Save the following pice of code in the file /Library/LaunchDaemons/datomic.transactor.plist
.
The configuration will ensure that the transactor is started upon boot, that it is executed as the correct user, and that output will be written to the Datomic log directory. Please make sure that the locations of the Java framework etc. matches your system.
Before the configuration is used by the system, it must be loaded using launchctl
Use the unload
option if you need to remove the datomic transactor.
Since the transactor is configured to be up at all times, you can restart if by asking launchctl
to stop it
That should be all that is needed for setting up Datomic on a Mac OS system. Please check the logs to make sure your system is booted. Apart from the log files for standard out and error defined in the plist file, launchd
logs errors to /var/log/system.log
.