Omnis Technical Note TNEX0010 Oct 2020

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">
<plist version="1.0">
   <dict>
      <key>WorkingDirectory</key>
      <string>/Applications/OmnisDataBridge 1.75</string>
      <key>Disabled</key>
      <false/>
      <key>KeepAlive</key>
      <true/>
      <key>Label</key>
      <string>com.omnis.odb</string>
      <key>ProgramArguments</key>
      <array>
         <string>/Applications/OmnisDataBridge 1.75/odb</string>
         <string>start</string>
      </array>
      <key>RunAtLoad</key>
      <true/>
   </dict>
</plist>

As you can see, we are using several keys:

<key>WorkingDirectory</key>
this sets the working directory for the daemon

<key>Disabled</key>
this tells use if the daemon is disabled or active

<key>Label</key>
this is a piece of information to identify the daemon

<key>ProgramArguments</key>
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. This would also be the same commands we’d find ourselves running when starting the odb manually (/Applications/OmnisDataBridge 1.74/odb run)

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.75/

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.75/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.

Search Omnis Developer Resources

 

Hit enter to search

X