diff --git a/Java Containerization/resource/tomcat/tomcat9.service b/Java Containerization/resource/tomcat/tomcat9.service index 76ff569..75778d2 100644 --- a/Java Containerization/resource/tomcat/tomcat9.service +++ b/Java Containerization/resource/tomcat/tomcat9.service @@ -1,5 +1,3 @@ -# add the following to the /etc/systemd/system/tomcat9.service file - [Unit] Description=Apache Tomcat Web Application Container After=network.target @@ -8,12 +6,16 @@ After=network.target Type=forking +Environment=MYSQL_SERVER_ADMIN_LOGIN_NAME= +Environment=MYSQL_SERVER_ADMIN_PASSWORD= +Environment=MYSQL_DATABASE_NAME= +Environment=MYSQL_SERVER_FULL_NAME= Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64 Environment=CATALINA_PID=/opt/tomcat9/temp/tomcat.pid Environment=CATALINA_HOME=/opt/tomcat9 Environment=CATALINA_BASE=/opt/tomcat9 Environment='CATALINA_OPTS=-Xms8192M -Xmx8192M -server -XX:+UseParallelGC' -Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom -Dairsonic.home=/var/airsonic' +Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom -Dairsonic.home=/var' ExecStart=/opt/tomcat9/bin/startup.sh ExecStop=/opt/tomcat9/bin/shutdown.sh @@ -25,7 +27,7 @@ RestartSec=10 Restart=always # dont do this until dir is created -ReadWritePaths=/var/airsonic/ +ReadWritePaths=/var/ [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/Java Containerization/scripts/vm/airsonic-install.sh b/Java Containerization/scripts/vm/airsonic-install.sh index 3deed7a..27ffbc6 100644 --- a/Java Containerization/scripts/vm/airsonic-install.sh +++ b/Java Containerization/scripts/vm/airsonic-install.sh @@ -20,7 +20,7 @@ rm -rf airsonic.war mv * /opt/tomcat9/webapps/airsonic #AIRSONIC_BASEDIR=/datadrive/airsonic -AIRSONIC_BASEDIR=/var/airsonic +AIRSONIC_BASEDIR=/var mkdir -p $AIRSONIC_BASEDIR # create music, media, podcasts and playlists folders @@ -32,21 +32,16 @@ mkdir media chown -R tomcat9:tomcat9 $AIRSONIC_BASEDIR chmod 777 $AIRSONIC_BASEDIR/music +# reload the systemd daemon so that it knows about our service file +sudo systemctl daemon-reload - - -# setup env vars -#echo "Setting env vars" -#echo "CATALINA_OPTS='-Xms512M -Xmx1024M -server -XX:+UseParallelGC'" >> /opt/tomcat9/bin/setenv.sh -#echo "JAVA_OPTS='-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom -Dairsonic.home=$MEDIA_BASEDIR'" >> /opt/tomcat9/bin/setenv.sh -#echo "Setting env vars complete" +# Enable the service file so that Tomcat automatically starts at boot: +sudo systemctl enable tomcat9 # Start/Stop tomcat to generate airsonic properties file echo "Starting tomcat" -#/opt/tomcat9/bin/startup.sh sudo systemctl start tomcat9 sleep 30 echo "Stopping tomcat" -#/opt/tomcat9/bin/shutdown.sh sudo systemctl stop tomcat9 sleep 30 \ No newline at end of file diff --git a/Java Containerization/scripts/vm/java-tomcat-install.sh b/Java Containerization/scripts/vm/java-tomcat-install.sh index 85e1322..ee30711 100644 --- a/Java Containerization/scripts/vm/java-tomcat-install.sh +++ b/Java Containerization/scripts/vm/java-tomcat-install.sh @@ -82,16 +82,6 @@ sudo chmod g+x conf # Make the tomcat user the owner of the Web apps, work, temp, and logs directories: sudo chown -R tomcat9 webapps/ work/ temp/ logs/ bin/ -# reload the systemd daemon so that it knows about our service file -sudo systemctl daemon-reload -#sudo systemctl start tomcat9 - -# Enable the service file so that Tomcat automatically starts at boot: -sudo systemctl enable tomcat9 - - - - echo "Installing Tomcat complete" echo "" echo "" \ No newline at end of file diff --git a/Java Containerization/scripts/vm/mysql-bind.sh b/Java Containerization/scripts/vm/mysql-bind.sh index b7a8ae2..155e8f5 100644 --- a/Java Containerization/scripts/vm/mysql-bind.sh +++ b/Java Containerization/scripts/vm/mysql-bind.sh @@ -19,19 +19,18 @@ tar xvzf mysql-connector-java-*tar.gz # copy to Tomcat9/lib folder cp mysql-connector-java-*/mysql-connector-java-*.jar /opt/tomcat9/lib -echo 'DatabaseConfigType=jndi' >> /var/airsonic/airsonic.properties -echo 'DatabaseConfigJNDIName=jdbc/airsonicDB' >> /var/airsonic/airsonic.properties -#echo 'DatabaseConfigType=jndi' >> /datadrive/airsonic/airsonic.properties -#echo 'DatabaseConfigJNDIName=jdbc/airsonicDB' >> /datadrive/airsonic/airsonic.properties +echo 'DatabaseConfigType=jndi' >> /var/airsonic.properties +echo 'DatabaseConfigJNDIName=jdbc/airsonicDB' >> /var/airsonic.properties + +# write to tomcat9.service +sed -i "s%Environment=MYSQL_SERVER_ADMIN_LOGIN_NAME=%Environment=MYSQL_SERVER_ADMIN_LOGIN_NAME='$MYSQL_ADMIN_USER'%" /etc/systemd/system/tomcat9.service +sed -i "s%Environment=MYSQL_SERVER_ADMIN_PASSWORD=%Environment=MYSQL_SERVER_ADMIN_PASSWORD='$MYSQL_ADMIN_PASS'%" /etc/systemd/system/tomcat9.service +sed -i "s%Environment=MYSQL_DATABASE_NAME=%Environment=MYSQL_DATABASE_NAME='$MYSQL_DBNAME'%" /etc/systemd/system/tomcat9.service +sed -i "s%Environment=MYSQL_SERVER_FULL_NAME=%Environment=MYSQL_SERVER_FULL_NAME'$MYSQL_HOSTNAME'%" /etc/systemd/system/tomcat9.service +sed -i "s%-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom -Dairsonic.home=/var%-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom -Dairsonic.home=/var -DMYSQL_SERVER_FULL_NAME='$MYSQL_HOSTNAME' -DMYSQL_DATABASE_NAME='$MYSQL_DBNAME' -DMYSQL_SERVER_ADMIN_LOGIN_NAME='$MYSQL_ADMIN_USER' -DMYSQL_SERVER_ADMIN_PASSWORD='$MYSQL_ADMIN_PASS%" /etc/systemd/system/tomcat9.service + + -# replace setenv -rm -rf /opt/tomcat9/bin/setenv.sh -echo "MYSQL_SERVER_ADMIN_LOGIN_NAME='$MYSQL_ADMIN_USER'" >> /opt/tomcat9/bin/setenv.sh -echo "MYSQL_SERVER_ADMIN_PASSWORD='$MYSQL_ADMIN_PASS'" >> /opt/tomcat9/bin/setenv.sh -echo "MYSQL_DATABASE_NAME='$MYSQL_DBNAME'" >> /opt/tomcat9/bin/setenv.sh -echo "MYSQL_SERVER_FULL_NAME='$MYSQL_HOSTNAME'" >> /opt/tomcat9/bin/setenv.sh -echo "CATALINA_OPTS='-Xms8192M -Xmx8192M -server -XX:+UseParallelGC'" >> /opt/tomcat9/bin/setenv.sh -echo "JAVA_OPTS='-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom -Dairsonic.home=/var/airsonic -DMYSQL_SERVER_FULL_NAME=\$MYSQL_SERVER_FULL_NAME -DMYSQL_DATABASE_NAME=\$MYSQL_DATABASE_NAME -DMYSQL_SERVER_ADMIN_LOGIN_NAME=\$MYSQL_SERVER_ADMIN_LOGIN_NAME -DMYSQL_SERVER_ADMIN_PASSWORD=\$MYSQL_SERVER_ADMIN_PASSWORD'" >> /opt/tomcat9/bin/setenv.sh # Move to db creation diff --git a/Java Containerization/scripts/vm/setup-vm.sh b/Java Containerization/scripts/vm/setup-vm.sh index 511ede6..b50ec2f 100644 --- a/Java Containerization/scripts/vm/setup-vm.sh +++ b/Java Containerization/scripts/vm/setup-vm.sh @@ -24,5 +24,5 @@ mkdir $LOG_HOME sh java-tomcat-install.sh $JAVA_PACKAGE $TOMCAT_PACKAGE $TOMCAT_SERVICE $TOMCAT_USERS $TOMCAT_SERVERCONF $TOMCAT_MANAGERCONTEXT $TOMCAT_HOSTMANAGERCONTEXT >> $LOG_HOME/java-tomcat-install.log sh airsonic-install.sh $AIRSONIC_PACKAGE >> $LOG_HOME/airsonic-install.log -#sh mysql-install.sh $MYSQL_CLIENT_PACKAGE $MYSQL_ADMIN_USER $MYSQL_SERVER_HOST $MYSQL_ADMIN_PASS >> $LOG_HOME/mysql-install.log -#sh mysql-bind.sh $TOMCAT_CONTEXT $MYSQL_DRIVER $MYSQL_ADMIN_USER $MYSQL_ADMIN_PASS $MYSQL_DBNAME $MYSQL_SERVER_HOST >> $LOG_HOME/mysql-bind.log \ No newline at end of file +sh mysql-install.sh $MYSQL_CLIENT_PACKAGE $MYSQL_ADMIN_USER $MYSQL_SERVER_HOST $MYSQL_ADMIN_PASS >> $LOG_HOME/mysql-install.log +sh mysql-bind.sh $TOMCAT_CONTEXT $MYSQL_DRIVER $MYSQL_ADMIN_USER $MYSQL_ADMIN_PASS $MYSQL_DBNAME $MYSQL_SERVER_HOST >> $LOG_HOME/mysql-bind.log \ No newline at end of file