3

I've read through the man pages for plist and launchd.plist, as well as posts about using plist files to run scripts at login; but I can seem to get things working.

My script location and permissions:

sshfs_mounts.sh:

ls -al Library/scripts/

-rwxr-xr-x   1 jason  staff   288 May 10 17:06 sshfs_mounts.sh

cat Library/scripts/sshfs_mounts.sh

#!/bin/bash
#
## automounting of sshfs directories
mount_cosmic ()
{
    /usr/local/bin/sshfs [email protected]:/media/NetworkShare/spacedock-1 /Users/jason/share;
}
mount |grep "/Users/jason/share/"
if [ $? == 1 ] && [ -d "/Users/jason/share" ] && [ $USER == "jason" ]; then
    mount_cosmic
fi

EDITED FROM ORIGINAL POST:

If I run the script manually, it executes as expected. I can load the plist (launchctl load ~/Library/LaunchAgents/local.sshfs.plist) and launch it (launchctl start ~/Library/LaunchAgents/local.sshfs), but it does not run the script. In the logs (cat /var/log/system.log |grep local.sshfs) I get:

May 11 09:30:26 rover com.apple.launchd.peruser.504[305] (local.sshfs.plist): Throttling respawn: Will start in 10 seconds

Here's my location and permissions for the plist file:

ls -al Library/LaunchAgents/local.sshfs.plist

-rw-r--r--  1 jason  staff  419 May 10 18:14 Library/LaunchAgents/local.sshfs_mounts.plist

And the file (EDITED after taking Gordon's advice^2):

<?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>KeepAlive</key>
        <true/>
        <key>Label</key>
        <string>local.sshfs.plist</string>
        <key>ProgramArguments</key>
        <array>
            <string>/bin/sh</string>
            <string>/Users/jason/Library/scripts/sshfs_mounts.sh</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StandardErrorPath</key>
        <string>/tmp/sshfs_mounts.err</string>
        <key>StandardOutPath</key>
        <string>/tmp/sshfs_mounts.out</string>
</dict>
</plist>

Mahalo in advance.

2 Answers 2

5

The "no plist was returned" error means that it was unable to parse the .plist file. I see two problems offhand: Lable should be Label, and </true> should be <true/>. You can use the command plutil -lint ~/Library/LaunchAgents/local.sshfs_mounts.plist to check the plist syntax, although it will not detect whether the data in the plist is valid as a launchd item.

4
  • your post was most helpful. The plist file is now loading without issue, and I can start it with lanchctl. I'll post my edited code. The issue now is every time I start the plist file it fails and I get the following in the system.log: Exited with code: 127
    – jason
    May 11, 2013 at 17:41
  • 1
    Exit status 127 generally means command not found -- is the sshfs command in one of the standard PATH directories, or in one you add in your e.g. .bash_profile? If that's the problem, either specify its full path in the script (e.g. /usr/local/bin/sshfs jason@...) or set PATH appropriately in the script. If that's not the problem, try capturing the script's output by adding <key>StandardOutPath</key><string>/tmp/sshfs_mounts.out</string><key>StandardErrorPath</key><string>/tmp/sshfs_mounts.err</string> to the .plist file, and see if that illuminates the problem. May 11, 2013 at 17:54
  • you help me get rid of all the errors, but the script still does not run. I changed the script as you suggested, also redirected the output. I get nothing into sshfs.out or sshfs.err. Moreover the output to /var/log/system.log is Throttling respawn: Will start in 10 seconds. Example code updated.
    – jason
    May 11, 2013 at 19:34
  • 1
    I just noticed you have KeepAlive set to <true/>, meaning that if the script exits for any reason, launchd will restart it. Does sshfs exit after mounting the server? If so (or if the if statement isn't executed), this means launchd will run the script over & over, although it throttles the relaunch rate to every 10 seconds. Other than that, is the script successfully mounting the server? If not, you should add some "echo" commands to give debugging output so you can figure out what's wrong? May 11, 2013 at 21:05
4

Thanks to Gordon helping me troubleshoot I was able to get the plist file properly formatted (I ended up using plistEdit pro because plists are picky about formatting and using a text editor didn't work for me) and determining that there was an issue in the script that I was attempting to have ran at login.

There were two things that were jamming me up. The first is that launchd was not letting my script spawn sub-process needed to mount an sshfs directory. This was fixed by adding the following key value pair:

<key>AbandonProcessGroup</key>
<true/>

(thanks to tw from macworld.com's forum post)

Again thanks to Gordon's suggestions I was able to read errors from /tmp/sshfs_mounts.err to find that there was something wrong with the way my command was written. I did some searching on sshfs mounts and found information on a couple Linux sites that helped me draft a better mount command.

So here's what works.

Script:

mount | grep /Users/jason/share
if [ $? == 1 ] && [ -d /Users/jason/share ]; then
    /usr/local/bin/sshfs -o idmap=user [email protected]:/spacedock-1 /Users/jason/share
fi

plist

<?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>AbandonProcessGroup</key>
    <true/>
    <key>Label</key>
    <string>local.sshfs.plist</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/jason/Library/scripts/sshfs_mounts.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>
1
  • Cool, I didn't know I needed the AbandonProcessGroup key.
    – Mikuz
    Feb 16, 2016 at 7:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .