#! /bin/sh
#  --------------------------------------------------------------
#  Company: Software- und Organisations-Service GmbH
#  Purpose: Instance Start Script for JS7 Controller
#  --------------------------------------------------------------

### BEGIN INIT INFO
# Provides:          JS7Controller
# Required-Start:    $syslog $remote_fs
# Required-Stop:     $syslog $remote_fs
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Description:       Start JS7 Controller
### END INIT INFO

### USAGE OF THIS FILE ##########################################
#
# This is a template for the JS7 Controller instance start script.
# It can be used as daemon start script.
# Copy this file 
# 
# './bin/controller_instance.sh-example' 
# -> './bin/controller_instance.sh' 
#
# and set the variables below.
#
# If you move this script outside the bin directory of 
# the JS7 Controller installation, e.g. for use with /etc/init.d,
# then you have to set the JS7_CONTROLLER_HOME variable.
#
#################################################################

### SETTINGS ####################################################

# This variable has to point to the installation path of 
# the JS7 Controller. If this variable is not defined then the parent
# directory of this start script is used.
### NOTE: 
# This variable is required if this start script is used for a  
# JS7 Controller service in /etc/init.d to locate the installation 
# directory of the JS7 Controller.
#
# JS7_CONTROLLER_HOME=


# JS7 Controller Id
# JS7_CONTROLLER_ID=controller


# Sets the user account for the JS7 Controller.
# Without this setting the currently logged in user account is used.
# The JS7 Controller should always be started with the same user
# to avoid problems about permissions in the JS7_CONTROLLER_DATA folder.
# This variable has to be set if this script is used for autostart
# to avoid that the JS7 Controller is started as the 'root' user account.
#
# JS7_CONTROLLER_USER=


# Sets the http port for the JS7 Controller.
# Without this setting the default port 4444 is used.
# If just a port is specified then the JS7 Controller listens to all
# available network interfaces. This corresponds to 0.0.0.0:<port>.
# Use the form <ip address or hostname>:<port> to indicate
# a specific network interface the JS7 Controller should listen to.
# The command line option --http-port beats the environment
# variable JS7_CONTROLLER_HTTP_PORT.
#
# JS7_CONTROLLER_HTTP_PORT=


# In addition to the http port an https port for the
# JS7 Controller can be specified. If just a port is specified
# then the JS7 Controller listens to all available network interfaces.
# This corresponds to using 0.0.0.0:<port>.
# Use the form <ip address or hostname>:<port> to indicate
# a specific network interface the JS7 Controller should listen to.
# The command line option --https-port beats the environment
# variable JS7_CONTROLLER_HTTPS_PORT.
#
# JS7_CONTROLLER_HTTPS_PORT=


# Sets the directory used by the JS7 Controller for configuration
# files, log files, journal files and temporary files.
# This directory has to be unique for any instances of the
# JS7 Controller. The default value is JS7_CONTROLLER_HOME/var.
# Check that the JS7 Controller user account has read/write
# permissions for this directory.
#
# JS7_CONTROLLER_DATA=


# Sets the directory used by the JS7 Controller for configuration
# files. The default value is JS7_CONTROLLER_DATA/config
# The command line option --config-directory beats the environment
# variable JS7_CONTROLLER_CONFIG_DIR.
# Check that the JS7 Controller user account has read/write
# permissions for this directory.
#
# JS7_CONTROLLER_CONFIG_DIR=


# Sets the directory to which the JS7 Controller stores log files.
# The default value is JS7_CONTROLLER_DATA/logs.
# Check that the JS7 Controller user account has read/write
# permissions for this directory.
#
# JS7_CONTROLLER_LOGS=


# Sets the directory to which the JS7 Controller stores its PID file.
# The default value is JS7_CONTROLLER_LOGS.
# Check that the JS7 Controller user account has read/write
# permissions for this directory.
#
# JS7_CONTROLLER_PID_FILE_DIR=


# Sets the file name to which the JS7 Controller stores its PID.
# The default value is controller.pid
#
# JS7_CONTROLLER_PID_FILE_NAME=


# Specifies the Java Runtime Environment to be used by the
# JS7 Controller. If JAVA_HOME is not set then Java is used from
# the PATH.
#
# JAVA_HOME=


# With Java 1.8 initial memory allocation has changed,
# for details see https://kb.sos-berlin.com/x/aIC9
# As a result on start-up of the JS7 Controller the amount of
# virtual memory assigned by Java depends on the physical
# memory and in most cases is by far too high.
# The environment variables JAVA_OPTIONS can be used to apply
# memory settings.
# The default value for JAVA_OPTIONS is -Xmx500m -Dfile.encoding=UTF-8.
#
# JAVA_OPTIONS=


# Sets the path to a customized watchdog script
# The default value is JS7_CONTROLLER_HOME/bin/controller_watchdog.sh
#
# JS7_CONTROLLER_WATCHDOG=


##########################################################

JS7_CONTROLLER_BINDIR="$(dirname "$0")"
test -z "${JS7_CONTROLLER_HOME}" && JS7_CONTROLLER_HOME="$(cd "${JS7_CONTROLLER_BINDIR}/.." >/dev/null && pwd)"

. "${JS7_CONTROLLER_HOME}/bin/controller.sh"
