mfo wrote: 
> Hi Gordon,
> 
> I just discovered you plugin and I'm wondering if it could help me (I'm
> suspecting it's a no but asking nonetheless, someone could have an idea
> to help solve it).
> I'm running an unusual setup to feed my SB (a radio and a boom):
> - Machine hosting LMS is a Cubox from SolidRun runnning a Debian
> - Cubox doesn't have large disk space attached so my music files are
> stored on a NAS (Iomega IX2-200 Cloud Edition)
> - I have a NFS mount on Cubox to the NAS to give the LMS access to my
> music files
> - NAS is not always on (power consumption, heat dissipation, noise)
> - NAS is a bit old, doesn't support WOL (a crying shame if you ask me)
> - NAS is plugged on a remote controlled electric plug which can be
> controlled by Cubox (using RFXCOM and XPL technos)
> 
> Knowing all the above, here's what I'm trying to achieve:
> - Whenever a SB is requesting a media file to Cubox that is stored on
> the NAS: power up the NAS (through remote controlled plug), wait for it
> to come up and mount the NFS share.
> - When SB is powered off (with remote or button), unmount the NFS share
> as I experience LMS hangs if the NAS is switched off while SB are still
> depending on it for playing files.
> 
> I've got custom Bash scripts trying to achieve the above, they are
> somewhat working, most of the time but it is globally not satisfying.
> 
> Is there an elegant solution to solve this ? Can the plugin help ? Do I
> have to improve my scripts because there's no hope elsewhere ?
> 
> Thanks in advance to anyone bringing thoughts on this mess, which was
> intended to be a master piece at the beginning :-)
> 
> Marc
I'm going to suggest that you not try to have SrvrPowerCtrl perform
these chores for you.  A much better fit, I think, would be to use Peter
Watkin's PowerCenter plugin:
http://www.tux.org/~peterw/slim/PowerCenter.html  By using this plugin,
you could have your powerup/mount -- unmount/powerdown procedures happen
automatically any time your Squeezebox player is turned "on" or "off". 


You can take your existing bash scripts and make a new bash script named
/usr/local/sbin/heyu.  Your 'fake' heyu script stands in for  a real X10
control heyu binary executable.  Configure PowerCenter to call your
script on Squeezebox power events.  When PowerCenter calls your fake
heyu script, the args it will pass will be 'on' or 'off' for $1, and a
'housecode' for $2.  The 'housecode' (e.g. 'A2') could identify which
Squeezebox is being powered on or off...or your could ignore it in your
script.

With this approach, all the heavy lifting is done for you.  PowerCenter
monitors the power state of the Squeezeboxes and will call your script
whenever that state changes.

You could also add Jason Holtzapple's PowerSave plugin.  That plugin
will automatically "power off" Squeezeboxes after they've been idle for
a set period of time.  When that happens, then PowerCenter will
automatically call your fake heyu script and the NAS unmount/poweroff
routine could get run.

I use both these plugins to automatically power on and off my big amps
connected to my Transporter.  Even though the amps are on an X10
appliance module, I'm using a fake heyu script to communicate with a
CM19A USB x10 transceiver via mocahd.

Here's my fake /usr/local/sbin/heyu script:

Code:
--------------------
    
  #!/bin/bash
  # Script to emulate heyu utility.  Called by Peter Watkin's LMS PowerCenter 
plugin.  
  # Uses netcat to send X10 commands via mochad controlling a CM19A USB 
transciever.
  #
  # Args:
  # $1 == command (i.e. off|on)
  # $2 == house code (i.e. A2, etc.)
  
  SCRIPT=$(basename "$0")
  LOGFILE=/var/log/heyu.log
  
  
####################################################################################
  # Stamp a message with the date and the script name (and process id) using
  # the same format as found in the squeezeboxserver server.log
  #
  date_message(){
        DATE=$(date '+%F %H:%M:%S.%N')
        DATE=${DATE#??}
        DATE=${DATE%?????}
        echo "[${DATE}] ${SCRIPT} ($$)" $@
  }
  
  
####################################################################################
  # Check to see that we can write to our logfile
  #
  check_log(){
        if [ ! -w $LOGFILE ]; then
                echo "Configuring log file ${LOGFILE}.."
                touch "$LOGFILE"
                chmod 666 "$LOGFILE"
        fi
  }
  
  
####################################################################################
  # Check to see that mochad is running.  It may very well not be if we've
  # resumed from S3 sleep.
  #
  check_mochad(){
        BINFILE=$(cat /etc/udev/rules.d/91-usb-x10-controllers.rules | sed -n 
-e '0,/^.*\"\(\/.*\)\"/s//\1/p')
  
        if [ $(pgrep -f "$BINFILE" | wc -l) -lt 1 ]; then
                LOGFILE='/var/log/mochad.log'
               DATESTR=$(date "+%b %e %H:%M:%S")
               HOSTNAM=$(hostname)
                date_message "${HOSTNAM} mochad[     ]: Restarting 
${BINFILE}.." >>"$LOGFILE"
                eval "$BINFILE"
                sleep 3
        fi
  }
  
  
  
####################################################################################
  # Transmit the command via mochad's port
  #
  transmit_cmd(){
        local CMD="$1"
        local HOUSECODE="$2"
        echo rf ${HOUSECODE} ${CMD} | nc -w 1 localhost 1099
  }
  
  
  
####################################################################################
  # Get the status of the housecode
  #
  get_status(){
        local HOUSECODE="$1"
        local HOUSE=${HOUSECODE:0:1}
        local CODE=${HOUSECODE:1:1}
        local aSTATUS=( off on )
  
        local STATUS=$(echo st | nc localhost 1099 | egrep "^.*House 
${HOUSE}:.*${CODE}=.*$" | sed -n -e "s/^.* House 
${HOUSE}:.*${CODE}=\([[:digit:]]\).*$/\1/p")
  
        if [ -z "$STATUS" ]; then
                return 1
        fi
  
        date_message "${HOUSECODE} == ${aSTATUS[$STATUS]}" >>$LOGFILE
  }
  
  # Make sure we can write to our log file..
  check_log
  
  # Make sure mochad is running
  check_mochad
  
  #date_message "$@" >>$LOGFILE
  
  date_message "rf ${2} ${1} | nc localhost 1099" >>$LOGFILE
  
  # As X10 appliance module switches wear out, may have to increase the REPCOUNT
  REPCOUNT=15
  for (( i=1; i<=$REPCOUNT; i++ )); do
        transmit_cmd $@
  done
  
  #get_status "$2"
  
  exit 0
  
--------------------

The basic logic of your version of the script would be similar.  You'd
add nas_mount, nas_umount and nas_powerup, nas_powerdown functions and
call them depending on if $1 was "on" or "off".  Check the $1 arg via:


Code:
--------------------
    
  case "$1" in
  on)
  nas_powerup
  nas_mount
  ;;
  off)
  nas_umount
  nas_powerdown
  ;;
  esac
  
--------------------

..or somesuch.


------------------------------------------------------------------------
gharris999's Profile: http://forums.slimdevices.com/member.php?userid=115
View this thread: http://forums.slimdevices.com/showthread.php?t=48521

_______________________________________________
plugins mailing list
plugins@lists.slimdevices.com
http://lists.slimdevices.com/mailman/listinfo/plugins

Reply via email to