This is proposed wiki how-to.  I thought I'd roll it out here first to
elicit comments.  Anyone please chime in here.  If I receive enough
positive feedback, I'll author a wiki page on this topic.

Goal:

Using minimal download bandwidth and a minimal on-disc footprint, allow
one to run any branch of squeezeboxserver / logitechmediaserver as a
service and to easily allow switching between installed branches.

Assumptions:

    
- Running on Ubuntu or some debian based distro.
- Service will run under the user account 'lms'.
- Local git repository will reside at /usr/share/lms/server.
- We'll create separate data and log directories for any branch we're
  going to run.
- Those data and log dirs will be at /var/lib/lms_data/${BRANCHNAME}
  and /var/log/lms_log/${BRANCHNAME}
- Those data and log dirs will be linked to /var/lib/lms and
  /var/log/lms
- We'll create a generic 'lms' service for running the code.
- We'll have a script for easily switching between branches.
  
Preparation:

Become root

Code:
--------------------
    sudo su
--------------------


Create the lms user account:

Code:
--------------------
    useradd --gid nogroup --no-create-home --no-user-group --system --shell 
/bin/false "lms"
--------------------


Download the latest version of the repo:

Code:
--------------------
    git clone -n --depth 1 https://github.com/Logitech/slimserver.git 
/usr/share/lms/server
--------------------

Note: by downloading only the latest revisions for every branch, we keep
the downloaded object file to about 250M.  Remove the "--depth 1" from
that command to make previous revisions available.

Checkout branch 7.8 

Code:
--------------------
    
  cd /usr/share/lms/server
  git checkout 7.8
  
--------------------



Create data and log dirs for the 7.8 branch

Code:
--------------------
    
  mkdir -p /var/lib/lms_data/7.8
  chown -R lms:nogroup /var/lib/lms_data
  mkdir -p /var/log/lms_log/7.8
  chown -R lms:nogroup /var/log/lms_log
  
--------------------


Create links to the data and log dirs..

Code:
--------------------
    
  ln -s /var/lib/lms /var/lib/lms_data/7.8
  ln -s /var/log/lms /var/log/lms_log/7.8
  
--------------------


Create a defaults file for the service..
/etc/default/lms:

Code:
--------------------
    SLIMDESC='LMS branch 7.8 git code'
  SLIMUSER='lms'
  SLIMOPTIONS=''
  
--------------------


Create a service control script..
/etc/init.d/lms:

Code:
--------------------
    
  TBD
  
--------------------


Create a service safe script..
/usr/sbin/lms_safe:

Code:
--------------------
    
  TBD
  
--------------------


Create a log rotate script..
/etc/logrotate.d/lms:

Code:
--------------------
    
  TBD
  
--------------------


Create service control links:

Code:
--------------------
    
  update-rc.d -f lms remove >/dev/null 2>&1
  update-rc.d -f lms defaults
  
--------------------


Create a branch switching script:
/usr/local/sbin/lms-switch-branch.sh

Code:
--------------------
    
  #!/bin/sh
  
  NEWBRANCH='7.8'
  ISGOODBRANCH=0
  #Discard local changes...
  DISCARD=0
  #Update repo
  UPDATE=0
  
  if [ ! -z "$1" ]; then
  NEWBRANCH="$1"
  fi
  
  # Change to the repo dir..
  cd /usr/share/lms/server
  
  # Get a list of the available branches..
  BRANCHES=`git branch -r | sed -n -e 's#^.*origin/\(.*\)$#\1#p'`
  
  for BRANCH in $BRANCHES
  do
  if [ "$NEWBRANCH" = "$BRANCH" ]; then
  ISGOODBRANCH=1
  fi
  done
  
  if [ $ISGOODBRANCH -lt 1 ]; then
  echo "Error: ${NEWBRANCH} is not a branch of 
github.com/Logitech/slimserver.git"
  exit 1
  fi
  
  # Stop the service..
  service lms stop
  
  # Do a hard reset of the repo to discard any local changes..
  if [ $DISCARD -gt 0 ]; then
  git reset --hard
  git clean -fd
  fi
  
  # Switch to the new branch
  git checkout "$NEWBRANCH"
  
  # Update the repo
  if [ $UPDATE -gt 0 ]; then
  git pull
  fi
  
  # Create new data & log dirs..
  LIBDIR="/var/lib/lms_data/${NEWBRANCH}"
  LOGDIR="/var/log/lms_log/${NEWBRANCH}"
  
  if [ ! -d "$LIBDIR" ]; then
  mkdir -p "$LIBDIR"
  fi
  
  if [ ! -d "$LOGDIR" ]; then
  mkdir -p "$LOGDIR"
  fi
  
  # Fix permissions
  chown -r lms:nogroup "$LIBDIR"
  chown -r lms:nogroup "$LOGDIR"
  
  # Create new data & log links
  LIBDIRLINK='/var/lib/lms'
  LOGDIRLINK='/var/log/lms'
  
  
  if [ -L "$LIBDIRLINK" ]; then
  rm "$LIBDIRLINK"
  fi
  
  if [ ! -d "$LIBDIRLINK" ]; then
  ln -s "$LIBDIRLINK" "/var/lib/lms_data/${NEWBRANCH}"
  fi
  
  if [ -L "$LOGDIRLINK" ]; then
  rm "$LOGDIRLINK"
  fi
  
  if [ ! -d "$LOGDIRLINK" ]; then
  ln -s "$LOGDIRLINK" "/var/log/lms_log/${NEWBRANCH}"
  fi
  
  # Restart the service..
  service lms start
  exit $?
  
  
--------------------


That's it for now.  I haven't included the service control scripts, etc.
Mostly, I'm looking for comments here on the advisability of this
approach.


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

_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix

Reply via email to