Showing posts with label OSX. Show all posts
Showing posts with label OSX. Show all posts

Thursday, October 30, 2014

Putting an iTunes Library on a NAS, Reliably

I have tried for years to get my iTunes library to reside, reliably, on my home NAS.  After all the NAS offers a ton of storage, resilience with RAID, and allows me to run lean on an SSD in my Mac Mini.  But for years I've run into issues where the network burps, or the NAS reboots, or coronal mass ejections cause my Mini to be disconnected from the NAS.  OK, not so much the last one, but when the Mini is disconnected from the NAS, I get the inevitable sequence of events.  First I get the little "Volume Disconnected" popup on my Mini.  Then something causes iTunes to realize that the network share with the library no longer exists.  Then iTunes silently creates a new iTunes library in my home folder, under Music.  Then I have two libraries to reconcile when I finally figure it all out -- usually when 95% of my library goes missing.

So naturally I think, "There's got to be a better way.  Microsoft figured out long ago in Windows how to automatically reconnect network shares if the NAS is disconnected from the server or workstation, why not Apple?"  Well, it turns out Apple has this figured out as well.  They just don't provide the user-friendly checkbox to enable the capability.

I found a couple of very useful resources on my latest search for an answer (thanks Google).  The first was this white paper that Apple released in 2009 that details how to use autofs.  For those that want to understand the full capability, it's the place to start.  For those that want the Cliff's Notes version, there's a great post on Superuser.com that explains how to get the solution up and running quickly.  I've read both, and I chose the indirect mapping method described in the post for setting up my auto-mounted share.  And so far, so good.  I purposely held off on a software upgrade on the NAS until after I made the auto-mount change to see how resilient the solution is, and it works great.  Be sure to tune down the AUTOMOUNT_TIMEOUT value in /etc/autofs.conf.  The default value is 3600 seconds.  I've tuned it down to 300 (5 minutes), and all seems well.

One side note: when you change from traditional mounting of the share via Finder to mounting via autofs, the mount point for the share changes as well.  While Finder will automatically mount the share under the /Volumes directory, autofs pretty much lets you mount anywhere.  Best practice (Greg practice?) is to mount the NAS shares under the /Network directory.  I mount mine as /Network/NAS_Name/share_name/ just in case I ever run multiple NAS'es in my house.  The good news is that it seems applications like iTunes and Carbon Copy Cloner identify the share by its network name (e.g., afp://user@NAS/share_name/) rather than the mount point (e.g., /Volumes/share_name/).  So when I changed from Finder-based mounting to autofs, I didn't have to tell any of the applications about the change in directory structure.  They simply picked up the /Network/NAS_Name/share_name/ change automagically.

One last note: you will lose the little drive icons that Finder puts on your desktop when you mount network shares with it.  Not a big deal, but if it bothers you, you can always just create aliases on the desktop instead.

Well, happy auto-mounting!

Update:  November 25, 2015
So while all seemed well when I originally wrote this blog, I've noticed on several occasions where iTunes opens before the NAS volume is mounted.  When this happens, iTunes silently reverts the location of my iTunes library to my local SSD.  So now rather than launch iTunes directly, I wrote this handy Automator script that will test for the existence of a file on the volume, and only launch iTunes if the file exists.  The beauty is that testing for the file will automatically mount the volume if it can be mounted:

if [ -f /Network/NAS/media/00-media-is-alive ]; then
    open /Applications/iTunes.app
else
    osascript -e 'display notification "Folder media is missing. Failed to start iTunes." with title "Automator"'
fi


Then just run the command "touch /Network/NAS/media/00-media-is-alive" from a terminal window and you're good to go.  Instead of launching iTunes directly, run the script instead.  If the script can verify that the file 00-media-is-alive exists, meaning that the volume is mounted, it will start up iTunes.  If not, then you will get a message in Notification Center telling you that iTunes failed to start because the volume with the iTunes library couldn't be mounted.

Thursday, September 13, 2012

A Serial Console on OSX

A lot of times I find myself needing to recover passwords on old routers and switches that the world has forgotten about (along with their passwords, hence the password recovery).  It was easy in my PC days to simply fire up HyperTerm and go, and most Linux distributions still come with Minicom, if you know where to look.  But OSX is different.  There are 3rd party apps available, and I used zTerm for a while, but then I found you could simply use the OSX terminal app and a couple of quick commands to get a very capable, tabbed environment for mixing console and SSH access to a bunch of devices.  Perfect!

So you will need to start with a USB-to-Serial adapter that's supported by OSX.  I've had lots of success with PL2303 variants, so look for that chip in your adapter of choice.  Once you have it, plug it in and run the following command and watch the output:


bigmac:~ greg$ ls -l /dev/tty.*
crw-rw-rw-  1 root  wheel   18,   2 Sep 13 06:03 /dev/tty.Bluetooth-Modem
crw-rw-rw-  1 root  wheel   18,   0 Sep 13 06:03 /dev/tty.Bluetooth-PDA-Sync
crw-rw-rw-  1 root  wheel   18,   4 Sep 13 09:28 /dev/tty.PL2303-00001004

Now unplug the adapter and repeat:

bigmac:~ greg$ ls -l /dev/tty.*
crw-rw-rw-  1 root  wheel   18,   2 Sep 13 06:03 /dev/tty.Bluetooth-Modem
crw-rw-rw-  1 root  wheel   18,   0 Sep 13 06:03 /dev/tty.Bluetooth-PDA-Sync

Notice the entry that went away?  That's my adapter's device name.  In my case the naming was pretty obvious, but that may not always be the case.

Anyway, now that I know the name of my device, I can plug it back in and use the screen utility to open up a console session:

gbensimon-sslvpn-nc:~ greg$ screen /dev/tty.PL2303-00001004 9600

This will open a session at 9600 bps via my USB-to-Serial adapter.  Once engaged, A-? will bring up a useful help screen:

                       Screen key bindings, page 1 of 1.

                       Command key:  ^A   Literal ^A:  a

  break       ^B b         license     ,            reset       Z         
  clear       C            lockscreen  ^X x         screen      ^C c      
  colon       :            log         H            select      '         
  copy        ^[ [         meta        a            silence     _         
  detach      ^D d         monitor     M            split       S         
  digraph     ^V           next        ^@ ^N sp n   suspend     ^Z z      
  displays    *            number      N            time        ^T t      
  dumptermcap .            only        Q            title       A         
  fit         F            other       ^A           vbell       ^G        
  flow        ^F f         pow_break   B            version     v         
  focus       ^I           pow_detach  D            width       W         
  hardcopy    h            prev        ^H ^P p ^?   windows     ^W w      
  help        ?            quit        ^\           wrap        ^R r      
  history     { }          readbuf     <            writebuf    >         
  info        i            redisplay   ^L l         xoff        ^S s      
  kill        ^K k         remove      X            xon         ^Q q      
  lastmsg     ^M m         removebuf   =         

^]  paste .
"   windowlist -b
-   select -
0   select 0
1   select 1
2   select 2
3   select 3
4   select 4
5   select 5
6   select 6
7   select 7
8   select 8
9   select 9
]   paste .


                        [Press Space or Return to end.]

You'll see it's pretty full-featured.

I've been using this since the Tiger (10.4) days.  I had some issues with Snow Leopard (10.6) and 64-bit support, but updated drivers seem to have resolved the problems.  I'm currently on Mountain Lion (10.8), and it's still working great.

Tuesday, September 04, 2012

Safari 6 and Mountain Lion Hell

Once upon a time, OSX was rock-solid.  You could upgrade from one release to the next on Day 1 and have supreme confidence that things were going to "just work" as they had in the past.  Lion broke that, and Mountain Lion seems to have added more problems without fixing what Lion broke.  This time it's Safari.

Once I completed my ML upgrade and restarted, I opened up Safari as I always do.  My standard start page (http://www.apple.com/startpage/) came up fine.  Then I tried to browse to GMail.  The progress bar quickly moved to about 25% complete, but then it just hung, and the page was never rendered.  Thinking it was a GMail issue, I tried CNN...and Facebook...and my company SSL portal...all the same.  Meanwhile I had the Pinwheel of Death spinning in my browser while the Safari Web Content process spiked to near 100%.  The Console app showed nothing relating to Safari.

I reset Safari and cleared everything I could check -- no change.  I disabled Java, JavaScript, and all plugins from the Safari preferences -- no change.  So I tried some Google-Fu, looking for terms related to Safari, Mountain Lion, "Web Content", and CPU looking for ideas -- nothing.  So I bailed on Safari and started using Chrome in the interim (which has been nice).

I didn't want to give up, so I tried again today.  I came a bit closer when I found this article on the Apple Support Community.  The process didn't solve my problem, but I keyed on the following quote:

Flash CONTENT itself was not sucking up the CPU, but merely the Flash PLUGIN BEING INSTALLED was what sucked up the CPU time.

So I went General Sherman on my plugins.  Typically you find plugins in one of two places:

/Library/Internet Plugins/
~/Library/Internet Plugins/

Granted, the second location isn't a single location (every user potentially has his own plugins), but you get the idea.  So I closed all my browsers, opened a terminal session and ran the following three commands:

sudo rm -rf /Library/Internet Plugins/*
cd ~
rm -rf Library/Internet Plugins/*

I restarted my laptop, opened Safari, and viola!  Safari opened every page I navigated to.  Of course it complained of missing plugins, but I have installed the latest releases of Flash and Java 6 so far without issue.  In order to get Java 6 running in Safari again, I also needed this command:

sudo ln -s /System/Library/Java/Support/CoreDeploy.bundle/Contents/JavaAppletPlugin.plugin /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin

Just make sure you get the whole command on a single line (no carriage returns).