config_bwSuite_server() { # $1: Path to server directory cat > "$1/config.properties" <<-EOF vmstore.path = /srv/openslx/nfs db.uri = jdbc:mysql://localhost/sat?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=utf8&connectionCollation=utf8mb4_unicode_ci db.username = sat db.password = %MYSQL_SAT_PASS% db.location-table = openslx.location master.address = bwlp-masterserver.ruf.uni-freiburg.de EOF chown root:images "$1/config.properties" chmod 0640 "$1/config.properties" } install_bwSuite_service() { # $1: Path to server directory cat > "/etc/systemd/system/dmsd.service" <<-EOF [Unit] Description=DMSD is the Dozentenmodul server daemon Wants=mysql.service After=mysql.service [Service] User=dmsd Group=images WorkingDirectory=$1 ExecStart=$1/dmsd.sh Restart=always RestartSec=5 SyslogIdentifier=dmsd StandardOutput=syslog StandardError=syslog [Install] WantedBy=multi-user.target EOF cat > "$1/dmsd.sh" <<-EOF #!/bin/sh KB=\$($(which grep) ^MemTotal /proc/meminfo | $(which awk) '{print \$2}') [ -z "\$KB" ] && KB=600000 if [ "\$KB" -gt 4096000 ]; then MB=\$(( \$KB / ( 1024 * 3 ) + 667 )) else MB=\$(( \$KB / ( 1024 * 2 ) )) fi if [ "\$MB" -gt 2000 ] && ! $(which java) -version 2>&1 | $(which grep) -q '64-Bit'; then MB=2000 fi [ "\$MB" -lt 190 ] && MB=190 [ "\$MB" -gt 4500 ] && MB=4500 exec $(which java) -Xmx\${MB}M -jar dmsd.jar EOF chmod +x "$1/dmsd.sh" } install_bwSuite_server() { # $1: directory to install server to echo "# Installing server part of bwSuite... " mkdir -p "$1" 2>/dev/null install -m 0644 -p -o root -g root "$BASEDIR/static_files/dmsd.jar" "$1/dmsd.jar" \ || perror "Could not install dmsd.jar" chown -R root:root "$1" chmod -R go-w "$1" config_bwSuite_server "$1" install_bwSuite_service "$1" }