lmgrd as a Launchd Daemon - shawfdong/hyades GitHub Wiki
Prof. Stan Woosley's group has recently purchased a site license for Intel Compilers for Mac OS X. The site license is managed by the FLEXlm License Manager, lmgrd, which is also widely used to manage a lot of other commercial software. On a Linux server, lmgrd is typically run as a limited user flexlm, and is started as an init service when the server boots up. However, the User's Guide for Using the Intel FLEXlm License Manager offers no guide on running lmgrd in a similar fashion under Mac OS X. Google won't help either. Don't despair. In this article, I'll show you how to run lmgrd as a Launchd Daemon.
Here we assume that we've installed the tools and license file for FLEXlm License Manager under the directory /usr/local/flexlm. The User's Guide instructs us to start the License Manager by running the following command in a terminal on the server:
sudo /usr/local/flexlm/lmgrd.intel -c /usr/local/flexlm/server.lic -l /usr/local/flexlm/lmgrd.intel.log
But this is not ideal: the service is run as root, which is a security risk; and we would have to run the command manually each time the server reboots or the service crashes. The following command gives us some clue why lmgrd doesn't mingle well with launchd:
$ ps aux | grep lmgrd root 142 0.0 0.0 77924 1576 ?? Ss 8:04PM 0:00.01 INTEL -T server.example.com 10.8 4 -c /usr/local/flexlm/server.lic --lmgrd_start 4fbda54b root 141 0.0 0.0 77656 1332 ?? Ss 8:04PM 0:00.01 /usr/local/flexlm/lmgrd.intel -z -c /usr/local/flexlm/server.lic -l /usr/local/flexlm/lmgrd.intel.log
We see that lmgrd puts itself in the background, and spawns another process. This conflicts with the launchd mechanism, which insists on its absolute right of handling such tasks for the daemons. Is there any chance for a happy marriage between lmgrd and launchd?
The answer is YES! The secret love potion is the little known option -z to lmgrd, which keeps lmgrd running in the foreground. So we should set up launchd to run the following command instead:
/usr/local/flexlm/lmgrd.intel -z -c /usr/local/flexlm/server.lic -l /usr/local/flexlm/lmgrd.intel.log
Let's wrap things up.
Start an interactive shell for root:
$ sudo -s
Create the group flexlm:
# gid=$(dscl . -list /Groups PrimaryGroupID | awk '{print $2}' | sort -n | tail -1) # gid=$(($gid + 1)) # dscl . -create /Groups/flexlm # dscl . -create /Groups/flexlm PrimaryGroupID $gid
Create the user flexlm:
# uid=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -n | tail -1) # uid=$(($uid + 1)) # dscl . -create /Users/flexlm NFSHomeDirectory /usr/local/flexlm # dscl . -create /Users/flexlm UserShell /usr/bin/false
Change the ownership of /usr/local/flexlm:
# chown -R flexlm:flexlm /usr/local/flexlm
Create a launchd plist file (/Library/LaunchDaemons/com.intel.lmgrd.plist), with the following content:
<?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.intel.lmgrd</string> <key>ProgramArguments</key> <array> <string>/usr/local/flexlm/lmgrd.intel</string> <string>-z</string> <string>-c</string> <string>/usr/local/flexlm/server.lic</string> <string>-l</string> <string>/usr/local/flexlm/lmgrd.intel.log</string> </array> <key>RunAtLoad</key> <true/> <key>UserName</key> <string>flexlm</string> <key>GroupName</key> <string>flexlm</string> <key>StandardErrorPath</key> <string>/dev/null</string> <key>KeepAlive</key> <true/> </dict> </plist>
The key RunAtLoad will cause FLEXlm License Manager to be started when the server boots up; and the key KeepAlive will have the License Manager automatically restarted if it is killed or crashes. For further details, consult the manual page for launchd.plist.
Now we can stop the FLEXlm License Manager we manually started earlier:
# /usr/local/flexlm/lmdown -c /usr/local/flexlm/server.lic
and relaunch it as a launchd daemon (still as root):
# launchctl load /Library/LaunchDaemons/com.intel.lmgrd.plist
We can run the following command to verify that the FLEXlm License Manager is indeed up and running:
$ /usr/local/flexlm/lmstat -c /usr/local/flexlm/server.lic