#!bin/bash
# define vars
if grep -qv 'release 7' /etc/redhat-release ; then echo o ; fi
sudo yum -y install openssl wget
password=$(openssl rand -base64 48)
if [ ! -e ~/password.txt ] ; then echo "password=$password" > ~/password.txt ; fi
source ~/password.txt
jira_version="8.12.0"
jira_source_url="https://www.atlassian.com/software/jira/downloads/binary"
jira_archive="atlassian-jira-software-${jira_version}.tar.gz"
jira_binary="atlassian-jira-software-${jira_version}-x64.bin"
root_db_password=$password
dbuser="jira"
dbuser_password=$password
dbname="jiradb"
msql57() {
cd /tmp
# install mysql 5.7
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm
sudo yum -y install mysql-server
# configure mysql for jira
sudo cp /etc/my.cnf ./
sudo chown $USER my.cnf
sudo echo "default-storage-engine=INNODB" >> my.cnf
sudo echo "character_set_server=utf8mb4" >> my.cnf
sudo echo "innodb_default_row_format=DYNAMIC" >> my.cnf
sudo echo "innodb_large_prefix=ON" >> my.cnf
sudo echo "innodb_file_format=Barracuda" >> my.cnf
sudo echo "innodb_log_file_size=2G" >> my.cnf
sudo cp my.cnf /etc/
sudo chown root my.cnf
# restart mysqld
sudo systemctl start mysqld
sudo systemctl status mysqld
# mysql_secure_installation
db_password=$(sudo grep 'temporary password' /var/log/mysqld.log | rev | cut -f1 -d' ' | rev)
sudo mysql --user=root --password=${db_password} --connect-expired-password -e \
"UPDATE mysql.user SET Password = PASSWORD('${root_db_password}') WHERE User = 'root'"
sudo mysql --user=root --password=${db_password} --connect-expired-password -e \
"SET Password = PASSWORD('${root_db_password}')"
sudo mysql --user=root --password=${root_db_password} --connect-expired-password -e \
"DROP USER ''@'localhost'"
sudo mysql --user=root --password=${root_db_password} --connect-expired-password -e \
"DROP USER ''@'$(hostname)'"
sudo mysql --user=root --password=${root_db_password} --connect-expired-password -e \
"DROP DATABASE test"
sudo mysql --user=root --password=${root_db_password} --connect-expired-password -e \
"FLUSH PRIVILEGES"
}
mysql_jira() {
# create the jira database
sudo mysql --user=root --password=${root_db_password} --connect-expired-password -e \
"CREATE USER ${dbuser}@localhost IDENTIFIED BY '${dbuser_password}'"
sudo mysql --user=root --password=${root_db_password} --connect-expired-password -e \
"CREATE DATABASE ${dbname} DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin"
sudo mysql --user=root --password=${root_db_password} --connect-expired-password -e \
"GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,REFERENCES,ALTER,INDEX ON ${dbname}.* TO ${dbuser}@localhost"
sudo mysql --user=root --password=${root_db_password} --connect-expired-password -e \
"FLUSH PRIVILEGES"
}
jira() {
# create a jira installation response file
cd /tmp
cat << EOF >> response.varfile
# install4j response file for Jira Software 8.12.0
app.install.service$Boolean=true
existingInstallationDir=/usr/local/Jira Software
launch.application$Boolean=true
sys.adminRights$Boolean=true
sys.confirmedUpdateInstallationString=false
sys.installationDir=/opt/atlassian/jira
sys.languageId=en
EOF
# install java-11-openjdk
sudo yum -y install java-11-openjdk java-11-openjdk-devel wget
# jira installation by binary
wget $jira_source_url/$jira_binary
chmod 755 $jira_binary
sudo ./$jira_binary -q -varfile response.varfile
# mysql-connector installation
wget https://cdn.mysql.com/Downloads/Connector-J/mysql-connector-java-5.1.49.tar.gz
tar xvfz mysql-connector-java-5.1.49.tar.gz
sudo cp mysql-connector-java-5.1.49/mysql-connector-java-5.1.49.jar /opt/atlassian/jira/atlassian-jira/WEB-INF/lib/
sudo /etc/init.d/jira stop
sudo /etc/init.d/jira start
url="http://$(ip a show dev eth0 | grep 'inet ' | awk '{print $2 }' | sed 's/\/24/:8080/g')"
echo "$url"
}
backup() {
cd /tmp
mysqldump -h localhost --user=root --password=${root_db_password} --triggers --single-transaction --no-create-db ${dbname} > ${dbname}.sql
sudo tar cvf data.tar /var/atlassian/application-data/jira/data
}
restoredb() {
cd /tmp
mysql -h localhost --user=root --password=${root_db_password} ${dbname} < ${dbname}.sql
}
restorejira() {
cd /tmp
cat << EOF >> dbconfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<jira-database-config>
<name>defaultDS</name>
<delegator-name>default</delegator-name>
<database-type>mysql57</database-type>
<jdbc-datasource>
<url>jdbc:mysql://address=(protocol=tcp)(host=localhost)(port=3306)/${dbname}?sessionVariables=default_storage_engine=InnoDB</url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<username>${dbuser}</username>
<password>${dbuser_password}</password>
<pool-min-size>30</pool-min-size>
<pool-max-size>30</pool-max-size>
<pool-max-wait>30000</pool-max-wait>
<validation-query>select 1</validation-query>
<min-evictable-idle-time-millis>60000</min-evictable-idle-time-millis>
<time-between-eviction-runs-millis>300000</time-between-eviction-runs-millis>
<pool-max-idle>30</pool-max-idle>
<pool-remove-abandoned>true</pool-remove-abandoned>
<pool-remove-abandoned-timeout>300</pool-remove-abandoned-timeout>
<pool-test-on-borrow>false</pool-test-on-borrow>
<pool-test-while-idle>true</pool-test-while-idle>
<validation-query-timeout>3</validation-query-timeout>
</jdbc-datasource>
</jira-database-config>
EOF
sudo cp dbconfig.xml /var/atlassian/application-data/jira/
sudo tar xvf data.tar -C /
sudo /etc/init.d/jira stop
sudo /etc/init.d/jira start
}
help() {
echo "HELP :"
echo "$0 install : install jira with msql57 database"
echo "$0 backup : dump the db and the data folder in /tmp"
echo "$0 restore : restore all the installation from backuped files"
}
if [ "$1" == "install" ] ; then msql57 ; mysql_jira ; jira
elif [ "$1" == "backup" ] ; then backup
elif [ "$1" == "restore" ] ; then msql57 ; mysql_jira ; restoredb ; jira ; restorejira
elif [ "$1" == "msql57" ] ; then msql57
elif [ "$1" == "restoredb" ] ; then mysql_jira ; restoredb
elif [ "$1" == "jira" ] ; then jira
elif [ "$1" == "restorejira" ] ; then restorejira
else help ; fi
nginx_jira() {
hostname="jira1"
fqdn="$hostname.test.tf"
#https://confluence.atlassian.com/jirakb/configure-jira-server-to-run-behind-a-nginx-reverse-proxy-426115340.html
#/opt/atlassian/jira/conf/server.xml
sudo yum -y install nginx
cat << EOF >> /etc/nginx/conf.d/jira.conf
server {
listen 80;
server_name ${fqdn};
location / {
proxy_set_header X-Forwarded-Host \$host;
proxy_set_header X-Forwarded-Server \$host;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_pass http://${hostname}:8080;
client_max_body_size 10M;
}
}
EOF
sudo systemctl enable --now nginx
}
### Notes
#sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent ; sudo firewall-cmd --reload
#https://confluence.atlassian.com/doc/using-apache-with-mod_proxy-173669.html