#!/bin/sh

#################################################
#                                               #
#        Configuraton for WASup manager         #
#                                               #
#################################################

# UMASK Setting
UMASK=022

# Log file path
JAVA_OPTS="$JAVA_OPTS -DLOG_PATH=$CATALINA_HOME/logs/"

# File(agent, engines, templates and etc.) repository path
JAVA_OPTS="$JAVA_OPTS -Dwasup.repository.path=$CATALINA_HOME/webapps/ROOT/static/repository/"

# WASup manager's $IP:$PORT for websocket connection from wasup-agent (eg. 192.168.0.2:8080)
JAVA_OPTS="$JAVA_OPTS -Dwasup.manager.url=$WASUP_MANAGER_URL"

# File encoding
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8 -Dfile.client.encoding=UTF-8"

# Additional config
JAVA_OPTS="$JAVA_OPTS -Xms2048m -Xmx2048m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m"
JAVA_OPTS="$JAVA_OPTS -XX:+UseG1GC"
JAVA_OPTS="$JAVA_OPTS -XX:+UseLargePagesInMetaspace"
JAVA_OPTS="$JAVA_OPTS -XX:+ExplicitGCInvokesConcurrent"
JAVA_OPTS="$JAVA_OPTS -XX:+DisableExplicitGC"
JAVA_OPTS="$JAVA_OPTS -XX:ReservedCodeCacheSize=512m"
JAVA_OPTS="$JAVA_OPTS -XX:-UseCodeCacheFlushing"
JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/urandom"

# Set derby db port to use another one.
# If you change the port, you have to set "spring.datasource.url" parameter too.
# If you want to specify the database path name, add path between localhost:1527 and wasupDB. (eg. localhost:1527//home/bill/DerbyDb/wasupDB)
#JAVA_OPTS="$JAVA_OPTS -Dwasup.derby.server.port=1527"
#JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.url='jdbc:derby://localhost:1527/wasupDB;create=true'"

# Custom DB Configuration (Default is Derby)
# MySQL
#JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.url='jdbc:mysql://localhost:3306/wasupdb?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC'"
#JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver"
#JAVA_OPTS="$JAVA_OPTS -Dspring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect"
#JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.username=wasup"
#JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.password=wasup"

# MariaDB
JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.url='jdbc:mysql://$WASUP_DATABASE_ADDR:$WASUP_DATABASE_PORT/$WASUP_DATABASE_NAME?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC'"
JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.driver-class-name=org.mariadb.jdbc.Driver"
JAVA_OPTS="$JAVA_OPTS -Dspring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect"
JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.username=$WASUP_DATABASE_USERNAME"
JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.password=$WASUP_DATABASE_PASSWORD"

# PostgreSQL
#JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.url='jdbc:postgresql://localhost:5432/wasupdb'"
#JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.driver-class-name=org.postgresql.Driver"
#JAVA_OPTS="$JAVA_OPTS -Dspring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect"
#JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.username=wasup"
#JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.password=wasup"

#################################################
#                                               #
#      Default settings for WASup servers       #
#                                               #
#################################################
# SSH port number for new hosts (Optional)
JAVA_OPTS="$JAVA_OPTS -Dwasup.host.ssh.port=22"

# SSH account for new hosts (Optional)
JAVA_OPTS="$JAVA_OPTS -Dwasup.host.user.name=centos"

# Default agent install path for new hosts (Optional, $USER_HOME will be used if empty)
JAVA_OPTS="$JAVA_OPTS -Dwasup.agent.install.path=/opt/wasup/agent"

# Default engine install path (Optional)
JAVA_OPTS="$JAVA_OPTS -Dwasup.engine.install.path=/opt/wasup/engines/"

# Default server install path (Optional)
JAVA_OPTS="$JAVA_OPTS -Dwasup.server.install.path=/opt/wasup/servers/"

# Default java home (Optional)
JAVA_OPTS="$JAVA_OPTS -Dwasup.java.home=/usr/lib/jvm/java-1.8.0"

# Default run user (Optional)
JAVA_OPTS="$JAVA_OPTS -Dwasup.run.user=centos"

# Java options for new application server (Optional)
JAVA_OPTS="$JAVA_OPTS -Dwasup.app.server.java.options='-Xms1024m -Xmx1024m -XX:MaxMetaspaceSize=256m -XX:MetaspaceSize=256m'"

# Document root for new web server (Optional)
JAVA_OPTS="$JAVA_OPTS -Dwasup.web.server.document.root="

# Java options for new session server (Optional)
JAVA_OPTS="$JAVA_OPTS -Dwasup.session.server.java.options='-Xms2048m -Xmx2048m -XX:MaxMetaspaceSize=256m -XX:MetaspaceSize=256m'"
