I'm trying to get a system startup script running with launchd (in 10.11.6). This script creates a RAM disk, then copies some files to it. The launchd plist is very simple, and seems to be working as I'm getting my 'touched' file every time. But that's all I get through launchd. I don't get a ram disk! This .plist file is in /Library/LaunchDaemons

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.myscript.make-ramdisk</string>
  <key>Program</key>
  <string>/ramdisk-scripts/make-ramdisk</string>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>
^ This does seem to run on boot, when it should. But launchd is voodoo so that doesn't for sure mean the problem isn't still in there.

Here is my script...

Code:
#!/bin/bash

touch /Users/myusername/Desktop/ram-disk-logs/startup-make-ramdisk-$(date +"%Y_%m_%d_%I_%M_%p").log

sleep 2

## make a ram disk that is approximaly 4GB in size
/usr/sbin/diskutil erasevolume HFS+ "webfolder" `/usr/bin/hdiutil attach ram://8000000 -notremovable -nomount`

## copy contents of the ramdisk backup to the ramdisk
cp -R /webfolder-backup/* /Volumes/webfolder/

## make me the owner
chown -R myusername /Volumes/webfolder/
chmod -R 777 /Volumes/webfolder/
When I run the above script from the terminal, as root, it does create the RAM disk properly.

But the really fun part is that when launchd runs this script, it only gets to the `touch` line, and doesn't actually make the RAM disk. I have no idea what could be causing this. This makes it very hard to try to troubleshoot since it WORKS when I try to troubleshoot, it only doesn't work in practice.

I also need to figure out how to make a shutdown script, to save the contents of this RAM disk on shutdown. A feature which seems to be oddly missing from launchd. But first things first, I can't even get the RAM disk created, never mind gracefully removed.