Omnis Technical Note TNEX0010Oct 2020. Updated Jul 2021
Creating a service for ODB on macOS
For Omnis Studio 8/10.x
By Andrei Augustin, Tech Support
Services are an amazing feature of Operating Systems which enable us to automatically launch programs at startup. As you can imagine, a service would be a perfect fit for unattended programs such as the Omnis Data Bridge.
In this Tech Note, we will explore how to create a service on macOS, also referred to as a launch daemon, for the ODB.
Launch daemons on macOS are described in a XML format stored in a .plist file. The contents of the plist file will be a dictionary with keys and value pairs; Apple goes into more detail about the possible key combinations in their launch daemon documentation available here.
We can start by creating a file name com.omnis.odb.plist and write the following XML to the file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
As you can see, we are using several keys:
this sets the working directory for the daemon
this tells use if the daemon is disabled or active
this is a piece of information to identify the daemon
this key receives an array and it’s perhaps the most important part. Here is where we pass it the path to our odb process as the first item of the array and the command “run” as the second item of the array. run tells the ODB to execute on daemon's main thread and should be used instead of start. start would incur a performance overhead if used here- because the daemon's main thread would exit immediately on attempting to start the ODB on a background thread. Use of <KeepAlive> means that the daemon would then continually re-execute.
The last key is <key>RunAtLoad</key> to which we pass yes, that way the daemon will start running once it’s loaded.
The next step is to place the launch daemon in a directory where macOS can load and run it from. We advise adding the plist you just create to /Library/LaunchDaemons/ (administrator privileges required).
Once the daemon is in /Library/LaunchDaemons/, we can load and start it by running the following command in the terminal:
sudo launchctl load -w /Library/LaunchDaemons/com.omnis.odb.plist
Now, on any future reboots of the machine, the ODB will be automatically started!
When running the Omnis Data Bridge as a daemon under the root user, you should make sure the permissions for the plist file are correct. You can set the file owner to root using the terminal command:
sudo chown root [path to com.omnis.odb.plist]
In addition, when running the odb daemon as the root user, the data file segments in a user's directory cannot be accessed unless Full Disk Access/File and Folders is granted to the odb. This means that if you have a datafile on your Desktop, the daemon cannot read it for security reasons. The alternative is to host your datafile somewhere outside the user's directory, for example, the Application Support directory is a good alternative, such as:
/Library/Application Support/Omnis/OmnisDataBridge 1.77/
Stopping ODB Service
Once you have rebooted the machine, you can check that the ODB is running from a terminal window by executing:
ps -A | grep odb
which will display the process ID on success, for example:
482 ?? 0:11.27 /Applications/OmnisDataBridge 1.77/odb start
In this example, you can kill the service by executing:
sudo kill -9 482
Please note: To avoid potential data file corruption, you should check that no clients are connected before killing the ODB process.