Daehyun
6/10/2018 - 3:53 PM

Mount helium as Launch Daemon

Mount helium as Launch Daemon

<?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">
<!--
#
# /Library/LaunchDaemons/daehyun.helium.plist
#
# launchctl load -w /Library/LaunchDaemons/daehyun.helium.plist
# launchctl start daehyun.helium
# launchctl stop daehyun.helium
#
#-->
<dict>
  <key>Label</key>
  <string>daehyun.helium</string>
  <key>Program</key>
  <string>/Users/daehyun/mount-helium.sh</string>
  <key>UserName</key>
  <string>root</string>
  <key>GroupName</key>
  <string>helium</string>
  <key>InitGroups</key>
  <true/>
  <key>WorkingDirectory</key>
  <string>/helium</string>
  <key>StandardOutPath</key>
  <string>/var/log/daehyun.helium.stdout</string>
  <key>StandardErrorPath</key>
  <string>/var/log/daehyun.helium.stderr</string>
</dict>
</plist>
#!/bin/bash
#
# /Users/daehyun/mount-helium.sh
#
umount_and_rmdir () {
  umount analysis && rmdir analysis && echo $(date -u) 'Unmounted helium.uedalab.local/analysis'
  umount exp      && rmdir exp      && echo $(date -u) 'Unmounted helium.uedalab.local/exp'
  umount upload   && rmdir upload   && echo $(date -u) 'Unmounted helium.uedalab.local/upload'
}
trap umount_and_rmdir INT TERM

(
  mkdir -p analysis exp upload && echo $(date -u) 'Made directories' &&
  mount_smbfs -N -f 660 -d 770 -o soft,noatime,rw //linuxmount@helium.uedalab.local:/analysis analysis && echo $(date -u) 'Mounted helium.uedalab.local/analysis' &&
  mount_smbfs -N -f 660 -d 770 -o soft,noatime,rw //linuxmount@helium.uedalab.local:/exp      exp      && echo $(date -u) 'Mounted helium.uedalab.local/exp'      &&
  mount_smbfs -N -f 660 -d 770 -o soft,noatime,rw //linuxmount@helium.uedalab.local:/upload   upload   && echo $(date -u) 'Mounted helium.uedalab.local/upload'
) || exit 1

echo $(date -u) 'All mounted fine'
tail -f /dev/null &
wait

echo $(date -u) 'Done'
exit 0