Startup Script

Status
Not open for further replies.

warllo

Contributor
Joined
Nov 22, 2012
Messages
117
Hi,

I installed Subsonic in a jail.

The command to run subsonic is /var/subsonic/subsonic.sh.

I would like to have this command run when the jail is started, I am new to freenas/freebsd and can not figure this out. I have tried adding the command to the /etc/rc.local file however this does not work.

Any suggestions? I am using the command in the /etc/rc.local method for running another application within a different jail under the old UI within warden and it works great however I am not trying to do this in the 11.2 Beta.

Thanks in advance for any input.
 

kdragon75

Wizard
Joined
Aug 7, 2016
Messages
2,457
If using iocage for the new jail, try iocage exec JAILNAME /var/subsonic/subsonic.sh
this way you can setup the post init command in FreeNAS from the GUI.... Not sure if that will work as teh jail may not be up yet...
Note: This will run as root inside the jail.

Anyone else know off the top of their heads? I need to get lunch and may test when I get back.
 

warllo

Contributor
Joined
Nov 22, 2012
Messages
117
If using iocage for the new jail, try iocage exec JAILNAME /var/subsonic/subsonic.sh
this way you can setup the post init command in FreeNAS from the GUI.... Not sure if that will work as teh jail may not be up yet...
Note: This will run as root inside the jail.

Anyone else know off the top of their heads? I need to get lunch and may test when I get back.

The command you listed worked great, it even started the jail that was not running. Where would you set the post init command in the freenas gui?
 

kdragon75

Wizard
Joined
Aug 7, 2016
Messages
2,457
Its under Tasks. As mentioned use post init but this may still be too early in the boot process. If your feeling ambitious, you could test and report back! :D
 

warllo

Contributor
Joined
Nov 22, 2012
Messages
117
Unfortunately this doesn't work when configured under tasks. I'm guessing the Post Init occurs before the jail is started. Why it will start the jail when you run the command manually and not when it's a task is a mystery.
 

kdragon75

Wizard
Joined
Aug 7, 2016
Messages
2,457
Unfortunately this doesn't work when configured under tasks. I'm guessing the Post Init occurs before the jail is started. Why it will start the jail when you run the command manually and not when it's a task is a mystery.
I though that might be an issue.
When you are talking about rc.local, are you referring to inside the jail or the base system? You should still be able to do that inside the jail. Is the subsonic.sh a full service wrapper? perhaps we can symlink it into /etc/rc.d/subsonic and then just add subsonic_enable=yes (I forget the exact syntax for it but that's the idea
 

warllo

Contributor
Joined
Nov 22, 2012
Messages
117
I was trying to do this all from within the jail. I don't think it's a full wrapper.
 

warllo

Contributor
Joined
Nov 22, 2012
Messages
117
I was trying to do this all from within the jail. I don't think it's a full wrapper.


This is the script.


Code:
#!/bin/sh

###################################################################################
# Shell script for starting Subsonic.  See http://subsonic.org.
#
# Author: Sindre Mehus
###################################################################################

# Note: default to environment variables, if set.

SUBSONIC_HOME=${SUBSONIC_HOME:-/var/subsonic}
SUBSONIC_HOST=${SUBSONIC_HOST:-0.0.0.0}
SUBSONIC_PORT=${SUBSONIC_PORT:-4040}
SUBSONIC_HTTPS_PORT=${SUBSONIC_HTTPS_PORT:-0}
SUBSONIC_CONTEXT_PATH=${SUBSONIC_CONTEXT_PATH:-/}
SUBSONIC_DB=${SUBSONIC_DB}
SUBSONIC_MAX_MEMORY=${SUBSONIC_MAX_MEMORY:-150}
SUBSONIC_PIDFILE=${SUBSONIC_PIDFILE}
SUBSONIC_DEFAULT_MUSIC_FOLDER=${SUBSONIC_DEFAULT_MUSIC_FOLDER:-/var/music}
SUBSONIC_DEFAULT_PODCAST_FOLDER=${SUBSONIC_DEFAULT_PODCAST_FOLDER:-/var/music/Podcast}
SUBSONIC_DEFAULT_PLAYLIST_FOLDER=${SUBSONIC_DEFAULT_PLAYLIST_FOLDER:-/var/playlists}

quiet=0

usage() {
	echo "Usage: subsonic.sh [options]"
	echo "  --help			   This small usage guide."
	echo "  --home=DIR		   The directory where Subsonic will create files."
	echo "					   Make sure it is writable. Default: /var/subsonic"
	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 "  --db=JDBC_URL		Use alternate database. MySQL, PostgreSQL and MariaDB are currently supported."
	echo "  --max-memory=MB	  The memory limit (max Java heap size) in megabytes."
	echo "					   Default: 100"
	echo "  --pidfile=PIDFILE	Write PID to this file. Default not created."
	echo "  --quiet			  Don't print anything to standard out. Default false."
	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 playlist imports.  This option "
	echo "								only has effect the first time Subsonic is started. Default '/var/playlists'"
	exit 1
}

# Parse arguments.
while [ $# -ge 1 ]; do
	case $1 in
		--help)
			usage
			;;
		--home=?*)
			SUBSONIC_HOME=${1#--home=}
			;;
		--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=}
			;;
		--db=?*)
			SUBSONIC_DB=${1#--db=}
			;;
		--max-memory=?*)
			SUBSONIC_MAX_MEMORY=${1#--max-memory=}
			;;
		--pidfile=?*)
			SUBSONIC_PIDFILE=${1#--pidfile=}
			;;
		--quiet)
			quiet=1
			;;
		--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=}
			;;
		*)
			usage
			;;
	esac
	shift
done

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

# Create Subsonic home directory.
mkdir -p ${SUBSONIC_HOME}
LOG=${SUBSONIC_HOME}/subsonic_sh.log
rm -f ${LOG}

cd $(dirname $0)
if [ -L $0 ] && ([ -e /bin/readlink ] || [ -e /usr/bin/readlink ]); then
	cd $(dirname $(readlink $0))
fi

${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.db="${SUBSONIC_DB}" \
  -Dsubsonic.defaultMusicFolder=${SUBSONIC_DEFAULT_MUSIC_FOLDER} \
  -Dsubsonic.defaultPodcastFolder=${SUBSONIC_DEFAULT_PODCAST_FOLDER} \
  -Dsubsonic.defaultPlaylistFolder=${SUBSONIC_DEFAULT_PLAYLIST_FOLDER} \
  -Djava.awt.headless=true \
  -verbose:gc \
  -jar subsonic-booter-jar-with-dependencies.jar > ${LOG} 2>&1 &

# Write pid to pidfile if it is defined.
if [ $SUBSONIC_PIDFILE ]; then
	echo $! > ${SUBSONIC_PIDFILE}
fi

if [ $quiet = 0 ]; then
	echo Started Subsonic [PID $!, ${LOG}]
fi

 

warllo

Contributor
Joined
Nov 22, 2012
Messages
117
This actually works to start subsonic once the jail has started. It needs some cleanup but it does indeed work.


Code:
#!/bin/sh

# PROVIDE: myscript

. /etc/rc.subr

name="myscript"
rcvar=`set_rcvar`
start_cmd="myscript_start"
stop_cmd=":"

load_rc_config $name

myscript_start()
{
	if checkyesno ${rcvar}; then
	  echo "Starting Subsonic"
   export
PATH=$PATH:/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin
   cd /var/subsonic/
   sh subsonic.sh

	fi
}

run_rc_command "$1"
 

kdragon75

Wizard
Joined
Aug 7, 2016
Messages
2,457
Quick and dirty. Just the way all RC scripts should be!
 
Status
Not open for further replies.
Top