macOS launchd LaunchAgent daemon

  • Updated

Introduction

Using macOS LaunchAgents, it is possible to automatically link to a LucidLink Filespace upon logging in to a local user account on macOS. 

Workflow Overview

  1. Create the script to launch the lucid2 daemon
  2. Create the LaunchAgent .plist file
  3. Test loading and unloading the LaunchAgent

Launch Script Setup

  1. Create a script directory in /usr/local/bin:

 
 
sudo mkdir -p /usr/local/bin
  1. Create the lucidlaunch.sh bash script in /usr/local/bin using your preferred text editor.
sudo nano /usr/local/bin/lucidlaunch.sh

Using the text editor, add the following content. Be sure to change the Filespace, username, and password to your own details (omitting the <> brackets).

#!/bin/bash
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
lucid2 daemon --fs <filespace.domain> --user <username> --password <password> --mount-point ~/Lucid
  1. Save lucidlaunch.sh and make it executable:

 
 
  chmod +x ~/Scripts/lucidlaunch.sh

LaunchAgent Property List Setup

1. Create the property list file in /Library/LaunchAgents:

 
 
sudo nano /Library/LaunchAgents/com.lucidlink.startup.plist

Inside the nano editor, add the following:

<?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>Label</key>
<string>com.lucidlink.startup</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/lucidlaunch.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/com.lucidlink.startup.out</string>
<key>StandardErrorPath</key>
<string>/tmp/com.lucidlink.startup.err</string>
</dict>
</plist>

Test Loading and Unloading the LaunchAgent

1. Load the LaunchAgent plist:

 
 
launchctl bootstrap gui/$(id -u) /Library/LaunchAgents/com.lucidlink.startup.plist

Verify the Filespace has mounted.

If it hasn’t, check the logs generated at: /tmp/com.lucidlink.startup.err.

2. To unload the LaunchAgent.

 
 
launchctl bootout gui/$(id -u) /Library/LaunchAgents/com.lucidlink.startup.plist

3. Perform a Final Test by logging out and back into the macOS user account and verify that the LaunchAgent has successfully mounted the Filespace.

Was this article helpful?

0 out of 0 found this helpful