#!/bin/sh
#
# Startup script for the Casa Authtoken Service Daemon (casa_atsd)
#
# systemd-casa_atsd
#
# description: casa_atsd is the CASA Authentication Token Service
# (ATS). CASA Client utilize this service to obtain CASA authentication
# tokens to authenticate to other services. The ATS executes as a
# tomcat webapp. casa_atsd is the tomcat process which contains
# the ATS.
#
# Note that some of the content from this file was copied from
# /etc/init.d/tomcat5 whose author was Petr Mladek.
# /etc/init.d/tomcat5 has the following copyrights:
#
# Copyright (c) 1995-2001 SuSE GmbH Nuernberg, Germany.
# Copyright (c) 2002 SuSE Linux AG Nuernberg, Germany.
#
# processname: casa_atsd
# pidfile: None
# config utility: None

. /etc/CASA/authtoken/svc/envvars
  
case "$1" in
start)
    TEST_IBM_JVM=$($JAVA_HOME/bin/java -version 2>&1 | grep -i ibm)

    # Append the java.security.auth.login.conf property on the JAVA_OPTS environment
    # variable if not utilizing the IBM JVM.
    if [ -z "${TEST_IBM_JVM}" ]; then
      export JAVA_OPTS="$JAVA_OPTS -Djava.security.auth.login.config=/etc/CASA/authtoken/svc/jaas.conf"
    fi

  /bin/bash "$CATALINA_HOME/bin/startup.sh" >"$CATALINA_BASE/logs/start.log" 2>&1
  ;;
stop)
  /bin/bash "$CATALINA_HOME/bin/shutdown.sh" >"$CATALINA_BASE/logs/stop.log" 2>&1
  ;;
*)
  echo -n "Usage: $0 {start|stop}"
  exit 1
  ;;
esac

