503 Error caused by Subsonic being launched twice?

Need help? Post your questions here.

Moderator: moderators

503 Error caused by Subsonic being launched twice?

Postby Revenant » Wed Jun 26, 2013 5:49 pm

I've been receiving the 503 error on every reboot recently and at first I thought there was an issue with my boot/shutdown not working correctly. I followed the advice of other threads here and repeatedly backed up and restored the 'db' folder in /var/subsonic/ and restarted the service to get it working.

After getting fed up of doing this at least once a day I tried to look for the cause of the issue and have discovered that Subsonic is being launched twice upon start of my machine.

The command 'ps aux | grep subsonic' after a fresh reboot displays the following output. If I kill either process and restart the other, Subsonic works fine so I imagine the 503 error is being causes by the 'db' folder being accessed by different instances of Subsonic at the same time.

Code: Select all
services  3207  2.8  7.0 2037476 265824 ?      Sl   18:18   0:11 java -Xmx512m -Dsubsonic.home=/var/subsonic -Dsubsonic.host=0.0.0.0 -Dsubsonic.port=8080 -Dsubsonic.httpsPort=0 -Dsubsonic.contextPath=/ -Dsubsonic.defaultMusicFolder=/var/music -Dsubsonic.defaultPodcastFolder=/var/music/Podcast -Dsubsonic.defaultPlaylistFolder=/var/playlists -Djava.awt.headless=true -verbose:gc -jar subsonic-booter-jar-with-dependencies.jar
services  3208  1.2  2.4 1769152 93932 ?       Sl   18:18   0:04 java -Xmx512m -Dsubsonic.home=/var/subsonic -Dsubsonic.host=0.0.0.0 -Dsubsonic.port=8080 -Dsubsonic.httpsPort=0 -Dsubsonic.contextPath=/ -Dsubsonic.defaultMusicFolder=/var/music -Dsubsonic.defaultPodcastFolder=/var/music/Podcast -Dsubsonic.defaultPlaylistFolder=/var/playlists -Djava.awt.headless=true -verbose:gc -jar subsonic-booter-jar-with-dependencies.jar
root      3695  0.0  0.0  11124   908 pts/0    S+   18:24   0:00 grep --color=auto subsonic


If I remove the 'subsonic' script from '/etc/init.d/' Subsonic does not launch at start up, but if I replace it Subsonic will launch twice and cause the problems I've mentioned.

I'm currently running Subsonic 4.8 (build 3434) on Ubuntu 13.04. Does anyone have any idea on how to prevent Subsonic from launching twice upon start up?

Thanks.
Revenant
 
Posts: 5
Joined: Fri Apr 30, 2010 5:55 pm

Re: 503 Error caused by Subsonic being launched twice?

Postby stozher » Wed Jun 26, 2013 6:31 pm

Kill all Subsonic... Test start of init.d script with "sudo invoke-rc.d subsonic start" and stop "sudo invoke-rc.d subsonic stop". Next is a my files from working server (see link at my profile or signature bellow). Files is a modified (extra code)!

My server started as "nobody", and my music folders under /srv/subsonic/<music> is a links to /home/<music>, and also /home/stozher/Music is a link to /home/<music>. Server not permitted to change my music, covers, tags (only read). Owner of /home/<music> is a stozher:stozher (my user), but owner of /srv/subsonic/Playlists and Podcasts is a nobody:stozher (775). I have write access to all folders under my user, also read-only access to /var/lib/subsonic...

/etc/default/subsonic
Code: Select all
# Configuration file for the Subsonic service (/etc/init.d/subsonic).
# Type "subsonic --help" on the command line to read an explanation...

SUBSONIC_ARGS=

# The user which should run the Subsonic process. Default "root". Note
# that non-root users are by default not allowed to use ports below
# 1024. Also make sure to grant the user write permissions in the music
# directories, otherwise changing album art and tags will fail.

SUBSONIC_USER="nobody"
SUBSONIC_GROUP="stozher"


/etc/init.d/subsonic
Code: Select all
#! /bin/sh
### BEGIN INIT INFO
# Provides:          subsonic
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Subsonic daemon
# Description:       Starts the Subsonic daemon. Subsonic is a web-based
#                    music streamer, jukebox and podcast receiver.
#                    See http://subsonic.org/ for more details.
### END INIT INFO

## To change the startup parameters of Subsonic, modify the service
## configuration file /etc/default/subsonic rather than this file.
[ -r "/etc/default/subsonic" ] && . /etc/default/subsonic

PATH="/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin"
DESC="Subsonic Daemon"
NAME="subsonic"
PIDFILE="/var/run/$NAME.pid"
DAEMON="/usr/local/bin/$NAME"
DAEMON_ARGS="--pidfile=$PIDFILE $SUBSONIC_ARGS"
SCRIPTNAME="/etc/init.d/$NAME"

## Exit if the package is not installed.
[ -x "$DAEMON" ] || exit 0 ## EXIT

## Run as root if SUBSONIC_USER is not set.
[ "$SUBSONIC_USER" = "" ] && SUBSONIC_USER="root"
[ "$SUBSONIC_GROUP" = "" ] && SUBSONIC_GROUP="root"

## Make sure Subsonic is started with system locale.
if [ -r "/etc/default/locale" ]; then
  . /etc/default/locale
  export LANG
fi

## Load the VERBOSE setting and other rcS variables.
. /lib/init/vars.sh

## Define LSB log_* functions (depend on lsb-base >= 3.0-6).
. /lib/lsb/init-functions

## =====================================================================
## FUNCTION THAT STARTS THE DAEMON/SERVICE
## =====================================================================
do_start() {
  ## Return:
  ##   0 - if daemon has been started
  ##   1 - if daemon was already running
  ##   2 - if daemon could not be started

  if [ -e "$PIDFILE" ]; then
    ps -p $(cat "$PIDFILE") > /dev/null
    [ "$?" = "0" ] && return 1
  fi

  touch "$PIDFILE"
  chown "$SUBSONIC_USER:$SUBSONIC_GROUP" "$PIDFILE"
  [ -e "/var/local/lib/subsonic" ] && chown -R "$SUBSONIC_USER:$SUBSONIC_GROUP" /var/local/lib/subsonic
  [ -e "/tmp/subsonic" ] && chown -R "$SUBSONIC_USER" /tmp/subsonic

  start-stop-daemon --start -c "$SUBSONIC_USER" --pidfile "$PIDFILE" --exec "$DAEMON" -- $DAEMON_ARGS || return 2
}

## =====================================================================
## FUNCTION THAT STOPS THE DAEMON/SERVICE
## =====================================================================
do_stop() {
  ## Return:
  ##   0 - if daemon has been stopped
  ##   1 - if daemon was already stopped
  ##   2 - if daemon could not be stopped
  ##   * - other if a failure occurred

  start-stop-daemon --stop --quiet --retry "TERM/30/KILL/5" --pidfile "$PIDFILE"
  RETVAL="$?"
  [ "$RETVAL" = "2" ] && return 2

  ## Many daemons don't delete their pidfiles when they exit.
  rm -f "$PIDFILE"
  return "$RETVAL"
}

## =====================================================================

case "$1" in
  start)
    [ "$VERBOSE" != "no" ] && log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
      0|1)
        [ "$VERBOSE" != "no" ] && log_end_msg 0
        ;;
      2)
        [ "$VERBOSE" != "no" ] && log_end_msg 1
        ;;
    esac
    ;;
  stop)
    [ "$VERBOSE" != "no" ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
      0|1)
        [ "$VERBOSE" != "no" ] && log_end_msg 0
        ;;
      2)
        [ "$VERBOSE" != "no" ] && log_end_msg 1
        ;;
    esac
    ;;
  status)
    status_of_proc "$DAEMON" "$NAME" && exit 0 || exit "$?" ## EXIT
    ;;
  restart|force-reload)
    ## If the "reload" option is implemented
    ## then remove the 'force-reload' alias.
    log_daemon_msg "Restarting $DESC" "$NAME"
    do_stop
    case "$?" in
      0|1)
        do_start
        case "$?" in
          0)
            log_end_msg 0
            ;;
          1)
            log_end_msg 1 # Old process is still running
            ;;
          *)
            log_end_msg 1 # Failed to start
            ;;
        esac
        ;;
      *)
        log_end_msg 1 # Failed to stop
        ;;
    esac
    ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
    exit 3 ## EXIT
    ;;
esac

:


/usr/bin/subsonic
Code: Select all
#!/bin/sh
# <prefix>/bin/subsonic                                       2013-06-19
## =====================================================================
## Subsonic 4.8 (Debian Wheezy i386)
## =====================================================================

PREFIX=$(cd $(dirname $(readlink -nf "$0")) && cd ".." && pwd -P)
LD_LIBRARY_PATH="$PREFIX/lib:$LD_LIBRARY_PATH"

quiet="0"
SUBSONIC_HOME="/usr/local/var/lib/subsonic"
SUBSONIC_PIDFILE=
SUBSONIC_HOST="0.0.0.0"
SUBSONIC_PORT="8080"
SUBSONIC_HTTPS_PORT="0"
SUBSONIC_CONTEXT_PATH="/"
SUBSONIC_MAX_MEMORY="512"
SUBSONIC_DEFAULT_MUSIC_FOLDER="/srv/subsonic/Progressive"
SUBSONIC_DEFAULT_PODCAST_FOLDER="/srv/subsonic/Podcasts"
SUBSONIC_DEFAULT_PLAYLIST_FOLDER="/srv/subsonic/Playlists"

# Use JAVA_HOME if set, otherwise assume java is in the path.
JAVA="java"; [ -e "$JAVA_HOME" ] && JAVA="$JAVA_HOME/bin/$JAVA"

## =====================================================================
## DON'T EDIT BELOW THIS LINE !!!
## =====================================================================

set -eu; ERROR="0"

usage() { ## FIXME ##
  echo "Usage: subsonic [options]"
  echo "  --help               This small usage guide."
  echo "  --quiet              Don't print anything to standard out. Default false."
  echo "  --home=DIR           The directory where Subsonic will create files."
  echo "                       Make sure it is writable. Default: /var/subsonic"
  echo "  --pidfile=PIDFILE    Write PID to this file. Default not created."
  echo "  --host=HOST          The host name or IP address on which to bind Subsonic."
  echo "                       Only relevant if you have multiple network interfaces and want"
  echo "                       to make Subsonic available on only one of them. The default value"
  echo "                       will bind Subsonic to all available network interfaces. Default: 0.0.0.0"
  echo "  --port=PORT          The port on which Subsonic will listen for"
  echo "                       incoming HTTP traffic. Default: 4040"
  echo "  --https-port=PORT    The port on which Subsonic will listen for"
  echo "                       incoming HTTPS traffic. Default: 0 (disabled)"
  echo "  --context-path=PATH  The context path, i.e., the last part of the Subsonic"
  echo "                       URL. Typically '/' or '/subsonic'. Default '/'"
  echo "  --max-memory=MB      The memory limit (max Java heap size) in megabytes."
  echo "                       Default: 100"
  echo "  --default-music-folder=DIR    Configure Subsonic to use this folder for music.  This option "
  echo "                                only has effect the first time Subsonic is started. Default '/var/music'"
  echo "  --default-podcast-folder=DIR  Configure Subsonic to use this folder for Podcasts.  This option "
  echo "                                only has effect the first time Subsonic is started. Default '/var/music/Podcast'"
  echo "  --default-playlist-folder=DIR Configure Subsonic to use this folder for playlists.  This option "
  echo "                                only has effect the first time Subsonic is started. Default '/var/playlists'"
  exit 127 ## EXIT
}

while [ "$#" -ge "1" ]; do
  case "$1" in
    --quiet)
      quiet="1"
      ;;
    --home=?*)
      SUBSONIC_HOME="${1#--home=}"
      ;;
    --pidfile=?*)
      SUBSONIC_PIDFILE="${1#--pidfile=}"
      ;;
    --host=?*)
      SUBSONIC_HOST="${1#--host=}"
      ;;
    --port=?*)
      SUBSONIC_PORT="${1#--port=}"
      ;;
    --https-port=?*)
      SUBSONIC_HTTPS_PORT="${1#--https-port=}"
      ;;
    --context-path=?*)
      SUBSONIC_CONTEXT_PATH="${1#--context-path=}"
      ;;
    --max-memory=?*)
      SUBSONIC_MAX_MEMORY="${1#--max-memory=}"
      ;;
    --default-music-folder=?*)
      SUBSONIC_DEFAULT_MUSIC_FOLDER="${1#--default-music-folder=}"
      ;;
    --default-podcast-folder=?*)
      SUBSONIC_DEFAULT_PODCAST_FOLDER="${1#--default-podcast-folder=}"
      ;;
    --default-playlist-folder=?*)
      SUBSONIC_DEFAULT_PLAYLIST_FOLDER="${1#--default-playlist-folder=}"
      ;;
    --help|*)
      usage
      ;;
  esac
  shift
done

mkdir -p "$SUBSONIC_HOME"
LOG="$SUBSONIC_HOME/subsonic.log"; rm -f "$LOG"
cd "$PREFIX/share/subsonic"; export LD_LIBRARY_PATH

${JAVA} -Xmx${SUBSONIC_MAX_MEMORY}M \
  -Dsubsonic.home="$SUBSONIC_HOME" \
  -Dsubsonic.host="$SUBSONIC_HOST" \
  -Dsubsonic.port="$SUBSONIC_PORT" \
  -Dsubsonic.httpsPort="$SUBSONIC_HTTPS_PORT" \
  -Dsubsonic.contextPath="$SUBSONIC_CONTEXT_PATH" \
  -Dsubsonic.defaultMusicFolder="$SUBSONIC_DEFAULT_MUSIC_FOLDER" \
  -Dsubsonic.defaultPodcastFolder="$SUBSONIC_DEFAULT_PODCAST_FOLDER" \
  -Dsubsonic.defaultPlaylistFolder="$SUBSONIC_DEFAULT_PLAYLIST_FOLDER" \
  -Djava.awt.headless=true -verbose:gc \
  -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC \
  -jar subsonic-booter-jar-with-dependencies.jar > "$LOG" 2>&1 &
ERROR="$?"

[ "$SUBSONIC_PIDFILE" ] && echo "$!" > "$SUBSONIC_PIDFILE"
[ "$quiet" = "0" ] && echo "Started Subsonic [PID $!, $LOG]"

exit "$ERROR" ## EXIT
http://music.stozher.com:8080/login.view?user=guest&password=
User avatar
stozher
 
Posts: 313
Joined: Tue Nov 16, 2010 10:56 am
Location: Sofia, Bulgaria

Re: 503 Error caused by Subsonic being launched twice?

Postby Revenant » Thu Jun 27, 2013 12:53 am

I found the cause of the problem. I'm using the program Monit to monitor several daemons for crashes and it seems to have been launching it before the script in /etc/init.d/ was executed.

Feel free to delete this thread.
Revenant
 
Posts: 5
Joined: Fri Apr 30, 2010 5:55 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 27 guests