OpenSuse 11.2 & Subsonic

Need help? Post your questions here.

Moderator: moderators

OpenSuse 11.2 & Subsonic

Postby daniell » Sat Jan 16, 2010 10:08 am

I still have problems with autostart of subsonic.sh in OpenSuse 11.2
Can't find where to put the startup routine.. And there is no (/etc/rc.local)
Anybody.. pls..
daniell
 
Posts: 90
Joined: Fri Nov 13, 2009 6:44 am
Location: Stavanger, Norway

Postby touchstone » Tue Feb 16, 2010 12:23 am

I'm running subsonic with openSuSE 11.2. In fact I just donated because I think this program is so well-executed. But it doesn't have a good initscript for openSuSE.

Here is the script that I'm using, made by combining the script that came with subsonic and a suse startup script. I don't want to run subsonic as root, so the script uses sudo to run it as another user of my choice.

It assumes that you've already created a user for subsonic to run as and a directory for it (this should command create a system account: useradd --system -s /bin/false -g nobody -D <YOUR SUBSONIC DIRECTORY> subsonic). It assumes your settings are in /etc/sysconfig/subsonic.

Your mileage may vary. Review the script and use at own risk. In particular I am not a programmer or sysadmin (anymore), so I'm merely assuming that using sudo here makes things more secure.

/etc/init.d/subsonic
Code: Select all
# /etc/init.d/subsonic
#
# System startup/shutdown script for subsonic
#
### BEGIN INIT INFO
# Provides:            subsonic
# Required-Start:      $local_fs $remote_fs $syslog
# Required-Stop:       $remote_fs $syslog
# Should-Start:        dbus $named
# Should-Stop:         $portmap
# Default-Start:       2 3 5
# Default-Stop:        0 1 6
# Short-Description:   Subsonic media streamer daemon
# Description:   Subsonic media streamer daemon
### END INIT INFO

# Source SuSE config, only if exists with size greater zero
test -s /etc/rc.config && \
    . /etc/rc.config

test -s /etc/rc.status && \
     . /etc/rc.status

# Load default settings (make changes in /etc/sysconfig/subsonic)
SUBSONIC_USER=subsonic
SUBSONIC_HOME=/var/subsonic
SUBSONIC_HOST=0.0.0.0
SUBSONIC_PORT=8080
SUBSONIC_CONTEXT_PATH=/
SUBSONIC_MAX_MEMORY=64
SUBSONIC_PIDFILE=/var/run/subsonic.pid
SUBSONIC_DEFAULT_MUSIC_FOLDER=/mnt/music
SUBSONIC_DEFAULT_PODCAST_FOLDER=/var/music/Podcast
SUBSONIC_DEFAULT_PLAYLIST_FOLDER=/mnt/music/playlists
SUBSONIC_LOG=/var/log/subsonic.log
JAVA=java
if [ -e "${JAVA_HOME}" ]
    then
    JAVA=${JAVA_HOME}/bin/java
fi

test -s /etc/sysconfig/subsonic && \
     . /etc/sysconfig/subsonic

# This is the java command line we use to start subsonic
JAVA_COMMAND_LINE="${JAVA} -Xmx${SUBSONIC_MAX_MEMORY}m
-Dsubsonic.home=${SUBSONIC_HOME} \
-Dsubsonic.host=${SUBSONIC_HOST} \
-Dsubsonic.port=${SUBSONIC_PORT} \
-Dsubsonic.contextPath=${SUBSONIC_CONTEXT_PATH} \
-Dsubsonic.defaultMusicFolder=${SUBSONIC_DEFAULT_MUSIC_FOLDER} \
-Dsubsonic.defaultPodcastFolder=${SUBSONIC_DEFAULT_PODCAST_FOLDER} \
-Dsubsonic.defaultPlaylistFolder=${SUBSONIC_DEFAULT_PLAYLIST_FOLDER} -jar subsonic-booter-jar-with-dependencies.jar"

# First reset status of this service
rc_reset

# Make a list of currently-running processes for this user
# grep through them for ones that appear to be subsonic
# (they start with the Java command line and contain the phrase
# "subsonic.home"); getting PID list by removing else from ps
# output.  This will obviously not included any processes we start
# here.  We use this to make sure subsonic isn't already running,
# to decide what processes to kill, and to display status.
SUBSONIC_PIDS=`ps -u $SUBSONIC_USER -o pid= -wwo args= | \
   grep -e "$JAVA_HOME.*subsonic\.home.*" | \
   sed "s/ *\([0-9][0-9]*\) .*/\1/"`

case "$1" in
  start)
    echo -n "Starting subsonic (as user $SUBSONIC_USER)"

    # Don't start Subsonic if it's already running
    if [ -n "$SUBSONIC_PIDS" ] ; then
       echo -e "\\nSubsonic appears to already be running as user $SUBSONIC_USER with PID(s) $SUBSONIC_PIDS."
       rc_failed 1
    else

   # Ensure effective user can write to logfile by giving ownership
   if [ -n "$SUBSONIC_LOG" ] ; then
      touch "$SUBSONIC_LOG"
      chown $SUBSONIC_USER "$SUBSONIC_LOG"
      echo "--------------------------------------" >> $SUBSONIC_LOG
      echo `date`": Starting subsonic restart:" >> $SUBSONIC_LOG
   fi

   # sudo to effective user and run java command line from above
   # to start subsonic.
   sudo -b -u $SUBSONIC_USER sh -c \
      "cd $SUBSONIC_HOME; \
      $JAVA_COMMAND_LINE >> ${SUBSONIC_LOG} 2>&1 &"

   # These versions attempted to get PID written to file --
   # Haven't figured out how to do it w/sudo yet...
   #   $JAVA_COMMAND_LINE >> ${SUBSONIC_LOG} 2>&1 & \
   #   [ -n "$SUBSONIC_PIDFILE" ] && echo $! > ${SUBSONIC_PIDFILE}"
   # Remember status and be verbose
    fi
    rc_status -v
    ;;
  stop)
    echo -n "Shutting down subsonic... "

    if [ -n "$SUBSONIC_PIDS" ] ; then
   echo -n "killing pid(s)"
   for subpid in $SUBSONIC_PIDS ; do
      echo -n " $subpid"
      kill -TERM $subpid
   done
   echo -n .
    else
   echo -n "No subsonic java process found."
    fi
    rc_status -v
    ;;
  restart)
    ## Stop the service and regardless of whether it was
    ## running or not, start it again.
    $0 stop
    $0 start

    # Remember status and be quiet
    rc_status
    ;;
  status)
    if [ -n "$SUBSONIC_PIDS" ] ; then
         echo -n "Subsonic apparently running w/user $SUBSONIC_USER, pid(s): $SUBSONIC_PIDS."
    else
   echo "No Subsonic java process found running as user $SUBSONIC_USER."
    fi
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart}"
    exit 1
  ;;
esac
rc_exit


/etc/sysconfig/subsonic (This happens to be my configuration -- you should of course edit it to suit your system):
Code: Select all
SUBSONIC_USER=subsonic
SUBSONIC_HOME=/var/subsonic
SUBSONIC_HOST=0.0.0.0
SUBSONIC_PORT=8080
SUBSONIC_CONTEXT_PATH=/
SUBSONIC_MAX_MEMORY=64
#PID file not currently used
SUBSONIC_PIDFILE=/var/run/subsonic.pid
SUBSONIC_DEFAULT_MUSIC_FOLDER=/var/music
SUBSONIC_DEFAULT_PODCAST_FOLDER=/var/music/podcast
SUBSONIC_DEFAULT_PLAYLIST_FOLDER=/var/music/playlists
touchstone
 
Posts: 2
Joined: Mon Feb 15, 2010 11:02 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 10 guests