0

I am new to lanuchctl. On my Mac running macos-ventura, I have created several plists that all load fine but will not run (neither by launchctl start nor by specifying RunAtLoad in the plist.

(Thanks to Martin R for pointing me to the log directory).

It turns out that the issue seems to be with trying to use /usr/local/bin (and other /usr/local/* folders) that have been mounted to external volumes for space reasons.

To get to the root of the matter, I have created the following plist stored at ~/Library/LaunchAgents/it_works.plist. It does indeed load my script, with some interesting results.

The plist is:

<?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>EnvironmentVariables</key>
        <dict>
            <key>PATH</key><string>/Users/dennis/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/usr/local/bin:/homebrew/bin:/homebrew/Cellar/php@7.4/7.4.29/bin</string>
        </dict>
    <key>Label</key><string>local.itWorks</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/dennis/bin/itWorks</string>
    </array>
    <key>WorkingDirectory</key><string>/Users/dennis</string>
    <key>StandardOutPath</key>  <string>/Users/dennis/local.itWorks.stdout</string>
    <key>StandardErrorPath</key><string>/Users/dennis/local.itWorks.stderr</string>
    <key>RunAtLoad</key><true/>
    <key>Debug</key><false/>
</dict>
</plist>

The script merely outputs some environmental information:

#!/usr/bin/env ksh
LOG=local.itWorks.hmmm...
exec 1>>$LOG
exec 2>&1

cd /Users/dennis echo "it works." echo HOME=$HOME echo PATH=$PATH echo '<?php printf("realpath(/usr/local/bin) returns %s\n", realpath("/usr/local/bin"));'|php set -x ls -ld /usr/local/bin ls -l /usr/local/bin ls -l /usr/local/bin/* ls -l /Volumes/Satechi.SSD.M2 ls -l /Volumes/Satechi.SSD.m2/usrlocal ls -l /Volumes/Satechi.SSD.M2/usrlocal/bin ls -l /Volumes/Satechi.SSD.M2/usrlocal/bin/* echo ''

After execution, the resultant output file ~/local.itWorks.hmmm... contains

it works.
HOME=/Users/dennis
PATH=/Users/dennis/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/usr/local/bin:/homebrew/bin:/homebrew/Cellar/php@7.4/7.4.29/bin
realpath(/usr/local/bin) returns /Volumes/Satechi.SSD.M2/usrlocal/bin
+ ls -ld /usr/local/bin
lrwxr-xr-x  1 root  wheel  36 Apr 28  2022 /usr/local/bin -> /Volumes/Satechi.SSD.M2/usrlocal/bin
+ ls -l /usr/local/bin
lrwxr-xr-x  1 root  wheel  36 Apr 28  2022 /usr/local/bin -> /Volumes/Satechi.SSD.M2/usrlocal/bin
+ ls -l '/usr/local/bin/*'
ls: /usr/local/bin/*: No such file or directory
+ ls -l /Volumes/Satechi.SSD.M2
ls: /Volumes/Satechi.SSD.M2: Operation not permitted
total 0
+ ls -l /Volumes/Satechi.SSD.m2/usrlocal
ls: /Volumes/Satechi.SSD.m2/usrlocal: Operation not permitted
total 0
+ ls -l /Volumes/Satechi.SSD.M2/usrlocal/bin
ls: /Volumes/Satechi.SSD.M2/usrlocal/bin: Operation not permitted
total 0
+ ls -l '/Volumes/Satechi.SSD.M2/usrlocal/bin/*'
ls: /Volumes/Satechi.SSD.M2/usrlocal/bin/*: No such file or directory
+ echo ''

As we can see, use of our nonstandard /usr/local/bin (and friends) is completely fouled, not working anything like manual execution, whose output starts like this:

it works.
HOME=/Users/dennis
PATH=/Users/dennis/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/usr/local/bin:/homebrew/bin:/homebrew/Cellar/php@7.4/7.4.29/bin
realpath(/usr/local/bin) returns /Volumes/Satechi.SSD.M2/usrlocal/bin
+ ls -ld /usr/local/bin
lrwxr-xr-x  1 root  wheel  36 Apr 28  2022 /usr/local/bin -> /Volumes/Satechi.SSD.M2/usrlocal/bin
+ ls -l /usr/local/bin
lrwxr-xr-x  1 root  wheel  36 Apr 28  2022 /usr/local/bin -> /Volumes/Satechi.SSD.M2/usrlocal/bin
+ ls -l /usr/local/bin/HandBrakeCLI /usr/local/bin/addGPSfromSRT /usr/local/bin/adddate /usr/local/bin/all-systems /usr/local/bin/appcontrol /usr/local/bin/archiveUserLogs.php /usr/local/bin/atjobs 

As soon as I add anything in the plist referencing an external volume (even by name /Volumes/VolumeName/folder/whatever), launchd just gives me a "not found" in the log file.

Hopefully there is a way to reference external volumes in scripts that launchd runs, else I'm pretty much out of business - and I'll have to drop back to crontab stuff.

Any help here? I'll be happy to clarify or provide more information.

Dennis
  • 115
  • Check /var/log/com.apple.xpc.launchd/ for log messages. – Martin R Jul 18 '23 at 15:13
  • Please summarise your problem in the first paragraph as there's an awful lot to parse before getting to your problem. Stating it briefly in the title doesn't give anyone enough immediate information. – Andy Griffiths Jul 18 '23 at 15:46
  • There is too much complexity here. Can you start small, by having a simply launch agent which just touches a file in /tmp. If this works, have it start a shell script to do the same, and then add php. – nohillside Jul 18 '23 at 15:47
  • @Andy Griiffiths - II agree and I will rewrite the body from scratch. New information demands it – Dennis Jul 18 '23 at 15:58
  • @Martin R - You led me right to the root of the issue. Thank you. – Dennis Jul 18 '23 at 15:59
  • Agreed @nohillside - rewritten accordingly – Dennis Jul 18 '23 at 16:33
  • Good to see the rewrite, and good to see you've reached a solution (unless I'm reading it wrong and you still have a problem, and your comment re /usr/local is just supporting info..), however, putting the solution in the question is not recommended. You can answer your own question (and get rep for it). – Andy Griffiths Jul 18 '23 at 16:57
  • 1
    No, it's an issue @AndyGriffiths - a big one for me. Seems that any reference to external volumes will cause launchctl/launchd failure. And apparently any reference to external volumes within a working script will also fail. Since ALL my data - and apps, scripts, et cetera - are offloaded due limited (and by Apple design, not upgradable) storage available, this means there is next to nothing I can do in a launchd job. UNLESS I am missing something (This question is a search for what I am missing). – Dennis Jul 18 '23 at 17:16
  • @GordonDavisson ah, that seems to be it. I will withhold my comment about Apple's decision here, and simply say I wish there was a way to indicate particular mount points (ALL, in my case) are NOT private. A setting in /etc/fstab would seem an ideal solution. But alas! For now, seems there's nothing I can do to fix this in the next week or more since there seems to be no command-line way to whitelist. (I'm away, with only ssh access to my Mac.) I look forward to exploring what you've pointed out to me - disjointed as it has become. I deeply appreciate your succinct & clear help. – Dennis Jul 18 '23 at 20:07
  • @GordonDavisson please make this an Answer; I will accept it. – Dennis Jul 18 '23 at 21:23

0 Answers0