mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-04 10:09:42 +00:00
b5938: setup image_upgrade functions and sailing server
This commit is contained in:
1 parent
556b955a88
commit
cced40a33e
8 files changed
+289
-261
No files matched your search
+133
@@ -0,0 +1,133 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# sailing Starts sailing services
|
||||
#
|
||||
# chkconfig: 2345 95 10
|
||||
# description: Sailing contains all sailing services
|
||||
#
|
||||
### BEGIN INIT INFO
|
||||
# Provides: sailing
|
||||
# Required-Start: $local_fs $network $named $remote_fs
|
||||
# Should-Start:
|
||||
# Required-Stop:
|
||||
# Should-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: The sailing service
|
||||
# Description: Start all sailing services required for this instance
|
||||
### END INIT INFO
|
||||
|
||||
# Source function library.
|
||||
. /etc/init.d/functions
|
||||
|
||||
RETVAL=0
|
||||
|
||||
SERVERS_DIR=/home/sailing/servers
|
||||
cd "${SERVERS_DIR}"
|
||||
JAVA_START_INSTANCES="$(find * -type d -prune)"
|
||||
GIT_REPOSITORY=/home/sailing/code
|
||||
if [ -x /bin/ec2-metadata ]; then
|
||||
EC2_METADATA_CMD=/bin/ec2-metadata
|
||||
elif [ -x /usr/bin/ec2-metadata ]; then
|
||||
EC2_METADATA_CMD=/usr/bin/ec2-metadata
|
||||
else
|
||||
EC2_METADATA_CMD=/opt/aws/bin/ec2-metadata
|
||||
fi
|
||||
REBOOT_INDICATOR=/var/run/is-rebooted
|
||||
SSH_KEY_READER_BEARER_TOKEN=/root/ssh-key-reader.token
|
||||
|
||||
echo "Executing with $1 at `date`" >>/var/log/sailing.err
|
||||
|
||||
start_servers() {
|
||||
/usr/local/bin/update_authorized_keys_for_landscape_managers $( cat ${SSH_KEY_READER_BEARER_TOKEN} ) https://security-service.sapsailing.com /root 2>&1 >>/var/log/sailing.err
|
||||
cp /home/sailing/code/configuration/cp_root_mail_properties /usr/local/bin
|
||||
chown root /usr/local/bin/cp_root_mail_properties
|
||||
chgrp root /usr/local/bin/cp_root_mail_properties
|
||||
chmod 755 /usr/local/bin/cp_root_mail_properties
|
||||
cp /home/sailing/code/configuration/cp_root_mail_properties_sudoers /etc/sudoers.d
|
||||
if which $EC2_METADATA_CMD && $EC2_METADATA_CMD -d | sed "s/user-data\: //g" | grep "^image-upgrade$"; then
|
||||
echo "Found image-upgrade in EC2 user data; upgrading image, then probably shutting down for AMI creation depending on the no-shutdown user data string..." >>/var/log/sailing.err
|
||||
$GIT_REPOSITORY/configuration/imageupgrade.sh
|
||||
else
|
||||
echo "No image-upgrade request found in EC2 user data $($EC2_METADATA_CMD -d); proceeding with regular server launch..." >>/var/log/sailing.err
|
||||
echo "Servers to launch: ${JAVA_START_INSTANCES}" >>/var/log/sailing.err
|
||||
if [ -f "${REBOOT_INDICATOR}" ]; then
|
||||
echo "This is a re-boot. No EC2 user data is evaluated for server configuration; no server configuration is performed. Only configured applications are launched." >>/var/log/sailing.err
|
||||
for conf in ${JAVA_START_INSTANCES}; do
|
||||
su - sailing -c "cd ${SERVERS_DIR}/${conf} && ./start" 2>>/var/log/sailing.err >>/var/log/sailing.err
|
||||
done
|
||||
else
|
||||
echo "This is a first-time boot. EC2 user data is evaluated for potential application deployment and configuration, and applications are launched." >>/var/log/sailing.err
|
||||
echo "Initializing local MongoDB replica set \"replica\"..."
|
||||
while ! echo "rs.initiate()" | mongo; do
|
||||
echo "MongoDB not ready yet; waiting and trying again..."
|
||||
sleep 5
|
||||
done
|
||||
FIRST_SERVER=$( eval $( ${EC2_METADATA_CMD} -d | sed -e 's/^user-data: //' ); echo $SERVER_NAME )
|
||||
if [ "${FIRST_SERVER}" = "" ]; then
|
||||
echo "No SERVER_NAME provided; not configuring/starting any application processes" >>/var/log/sailing.err
|
||||
else
|
||||
echo "Server to configure and start: ${FIRST_SERVER}" >>/var/log/sailing.err
|
||||
configure_and_start_server "${FIRST_SERVER}"
|
||||
fi
|
||||
echo 1 >"${REBOOT_INDICATOR}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Call with the server directory name (not the full path, just a single element from ${JAVA_START_INSTANCE}) as parameter
|
||||
# Example: configure_and_start_server server
|
||||
# This is expected to be called only in case there is only one server to configure; otherwise, the same EC2 user data
|
||||
# would get applied to all application configurations which would not be a good idea.
|
||||
configure_and_start_server() {
|
||||
conf="$1"
|
||||
mkdir -p "${SERVERS_DIR}/${conf}" >/dev/null 2>/dev/null
|
||||
chown sailing "${SERVERS_DIR}/${conf}"
|
||||
chgrp sailing "${SERVERS_DIR}/${conf}"
|
||||
# If there is a secret /root/mail.properties, copy it into the default server's configuration directory:
|
||||
/usr/local/bin/cp_root_mail_properties "${conf}"
|
||||
su - sailing -c "cd ${SERVERS_DIR}/${conf} && ${GIT_REPOSITORY}/java/target/refreshInstance.sh auto-install; ./start" 2>>/var/log/sailing.err >>/var/log/sailing.err
|
||||
pushd ${SERVERS_DIR}/${conf}
|
||||
./defineReverseProxyMappings.sh 2>>/var/log/sailing.err >>/var/log/sailing.err
|
||||
popd
|
||||
RETVAL=$?
|
||||
[ $RETVAL -eq 0 ] && success || failure
|
||||
}
|
||||
|
||||
stop_servers() {
|
||||
for conf in $JAVA_START_INSTANCES; do
|
||||
echo "Stopping Java server $conf" >> /var/log/sailing.err
|
||||
su - sailing -c "cd $SERVERS_DIR/$conf && ./stop"
|
||||
RETVAL=$?
|
||||
[ $RETVAL -eq 0 ] && success || failure
|
||||
sync_logs
|
||||
done
|
||||
}
|
||||
|
||||
sync_logs() {
|
||||
echo "Executing logrotate followed by a sync to ensure that logs are synchronized" >> /var/log/sailing.err
|
||||
logrotate -f /etc/logrotate.conf
|
||||
sync
|
||||
}
|
||||
|
||||
# See how we were called.
|
||||
case "$1" in
|
||||
start)
|
||||
start_servers
|
||||
/usr/sbin/update-motd
|
||||
touch /var/lock/subsys/sailing
|
||||
;;
|
||||
stop)
|
||||
stop_servers
|
||||
rm -f /var/lock/subsys/sailing
|
||||
;;
|
||||
status)
|
||||
status java
|
||||
RETVAL=$?
|
||||
;;
|
||||
*)
|
||||
echo $"Usage: $0 {start|status|stop}"
|
||||
RETVAL=3
|
||||
esac
|
||||
|
||||
exit $RETVAL
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
# Script to be linked from /etc/profile.d
|
||||
# Appends to PATH, sets DISPLAY for VNC running on :2, exports JAVA_HOME and Amazon EC2 variables
|
||||
|
||||
ulimit -n 100000
|
||||
ulimit -u 40000
|
||||
|
||||
# SAP JVM
|
||||
export JAVA_HOME=/opt/sapjvm_8
|
||||
# JDK 11.0.1:
|
||||
#export JAVA_HOME=/opt/jdk-11.0.1+13
|
||||
#export JAVA_HOME=/opt/jdk1.8.0_45
|
||||
export ANDROID_HOME=/opt/android-sdk-linux
|
||||
export PATH=$PATH:$JAVA_HOME/bin
|
||||
export DISPLAY=:2.0
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Upgrades the AWS EC2 instance that this script is assumed to be executed on.
|
||||
# The steps are as follows:
|
||||
|
||||
. `dirname $0`/imageupgrade_functions.sh
|
||||
|
||||
run_yum_update
|
||||
run_git_pull
|
||||
download_and_install_latest_sap_jvm_8
|
||||
clean_logrotate_target
|
||||
clean_httpd_logs
|
||||
clean_servers_dir
|
||||
clean_startup_logs
|
||||
update_root_crontab
|
||||
finalize
|
||||
@@ -0,0 +1,122 @@
|
||||
#!/bin/bash
|
||||
# Usage: Launch an Amazon EC2 instance from an Amazon Linux 2 AMI with
|
||||
# 100GB of root partition size and the "Sailing Analytics App" security group
|
||||
# using an SSH key for which you have a working private key available.
|
||||
# Then, run this script on your local computer, using the external IP address
|
||||
# of the instance you just launched in AWS as only argument. This will then
|
||||
# turn the instance into an application server for the SAP Sailing Analytics
|
||||
# application. When the script is done you may log in to look around and check
|
||||
# things. When done, shut down the instance (Stop, not Terminate) and create
|
||||
# an image off of it, naming it, e.g., "SAP Sailing Analytics 2.0" and
|
||||
# also tagging its root volume snapshot as, e.g., "SAP Sailing Analytics 2.0 (Root)".
|
||||
# If you want to use the resulting image in production, also tag it with
|
||||
# tag key "image-type" and tag value "sailing-analytics-server".
|
||||
if [ $# != 0 ]; then
|
||||
SERVER=$1
|
||||
scp "${0}" ec2-user@${SERVER}:
|
||||
ssh -A ec2-user@${SERVER} ./$( basename "${0}" )
|
||||
else
|
||||
if ec2-metadata | grep -q instance-id; then
|
||||
echo "Running on an AWS EC2 instance as user ${USER} / $(whoami), starting setup..."
|
||||
# Allow root ssh login with the same key used for the ec2-user for now;
|
||||
# later, a cron job will be installed that keeps the /root/authorized_keys file
|
||||
# up to date with all landscape managers' public SSH keys
|
||||
sudo cp /home/ec2-user/.ssh/authorized_keys /root/.ssh
|
||||
sudo chown root /root/.ssh/authorized_keys
|
||||
sudo chgrp root /root/.ssh/authorized_keys
|
||||
sudo adduser sailing
|
||||
sudo su - sailing -c "mkdir servers"
|
||||
# Create an SSH key pair with empty passphrase for ec2-user, deploy it to trac@sapsailing.com
|
||||
# and then move it to the sailing user's .ssh directory
|
||||
ssh-keygen -t ed25519 -P '' -f /home/ec2-user/.ssh/id_ed25519
|
||||
cat /home/ec2-user/.ssh/id_ed25519.pub | ssh -o StrictHostKeyChecking=false root@sapsailing.com "cat >>/home/trac/.ssh/authorized_keys"
|
||||
sudo mkdir /home/sailing/.ssh
|
||||
sudo mv /home/ec2-user/.ssh/id* /home/sailing/.ssh
|
||||
sudo chown -R sailing /home/sailing/.ssh
|
||||
sudo chgrp -R sailing /home/sailing/.ssh
|
||||
sudo chmod 700 /home/sailing/.ssh
|
||||
# Install crontab and copy key files using build-crontab
|
||||
#TODO
|
||||
# Install standard packages:
|
||||
sudo yum -y update
|
||||
sudo yum -y install git tmux nvme-cli chrony cronie cronie-anacron jq telnet mailx
|
||||
# Force acceptance of sapsailing.com's host key:
|
||||
sudo su - sailing -c "ssh -o StrictHostKeyChecking=false trac@sapsailing.com ls" >/dev/null
|
||||
# Clone Git to /home/sailing/code
|
||||
sudo su - sailing -c "git clone ssh://trac@sapsailing.com/home/trac/git code"
|
||||
# Install SAP JVM 8:
|
||||
sudo mkdir -p /opt
|
||||
sudo su - -c "source /home/sailing/code/configuration/imageupgrade_functions.sh; download_and_install_latest_sap_jvm_8"
|
||||
# Keep Amazon Linux from patching root's authorized_keys file:
|
||||
sudo sed -i -e 's/disable_root: *true/disable_root: false/' /etc/cloud/cloud.cfg
|
||||
# Configure SSH daemon:
|
||||
sudo su - -c "cat << EOF >>/etc/ssh/sshd_config
|
||||
PermitRootLogin without-password
|
||||
PermitRootLogin Yes
|
||||
MaxStartups 100
|
||||
EOF
|
||||
"
|
||||
# Increase limits
|
||||
sudo su - -c "cat << EOF >>/etc/sysctl.conf
|
||||
# number of connections the firewall can track
|
||||
net.ipv4.ip_conntrac_max = 131072
|
||||
EOF
|
||||
"
|
||||
# Install mountnvmeswap stuff
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable mountnvmeswap.service
|
||||
# Install MongoDB 4.4 and configure as replica set "replica"
|
||||
sudo su - -c "cat << EOF >/etc/yum.repos.d/mongodb-org.4.4.repo
|
||||
[mongodb-org-4.4]
|
||||
name=MongoDB Repository
|
||||
baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/4.4/x86_64/
|
||||
gpgcheck=1
|
||||
enabled=1
|
||||
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
|
||||
EOF
|
||||
"
|
||||
sudo yum -y update
|
||||
sudo yum -y install mongodb-org-server mongodb-org-shell mongodb-org-tools
|
||||
sudo su - -c "cat << EOF >>/etc/mongod.conf
|
||||
replication:
|
||||
replSetName: replica
|
||||
EOF
|
||||
"
|
||||
sudo sed -i -e 's/bindIp: *[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/bindIp: 0.0.0.0/' /etc/mongod.conf
|
||||
# Install cron job for ssh key update for landscape managers
|
||||
sudo su - -c "crontab /root/crontab"
|
||||
scp root@sapsailing.com:ssh-key-reader.token /tmp
|
||||
sudo mv /tmp/ssh-key-reader.token /root
|
||||
sudo chown root /root/ssh-key-reader.token
|
||||
sudo chgrp root /root/ssh-key-reader.token
|
||||
sudo chmod 600 /root/ssh-key-reader.token
|
||||
# Install /etc/init.d/sailing start-up / shut-down service
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable sailing.service
|
||||
# Install secrets
|
||||
scp root@sapsailing.com:secrets /tmp
|
||||
scp root@sapsailing.com:mail.properties /tmp
|
||||
sudo mv /tmp/secrets /root
|
||||
sudo mv /tmp/mail.properties /root
|
||||
sudo chown root /root/secrets
|
||||
sudo chgrp root /root/secrets
|
||||
sudo chmod 600 /root/secrets
|
||||
sudo chown root /root/mail.properties
|
||||
sudo chgrp root /root/mail.properties
|
||||
sudo chmod 600 /root/mail.properties
|
||||
# Create some swap space for the case mountnvmeswap hasn't created any
|
||||
sudo dd if=/dev/zero of=/var/cache/swapfile bs=1M count=6000
|
||||
sudo chown root /var/cache/swapfile
|
||||
sudo chgrp root /var/cache/swapfile
|
||||
sudo chmod 600 /var/cache/swapfile
|
||||
sudo mkswap /var/cache/swapfile
|
||||
# And while adding to /etc/fstab, also add the NFS mount of /home/scores:
|
||||
sudo mkdir /home/scores
|
||||
sudo su - -c 'echo "/var/cache/swapfile none swap pri=0 0 0
|
||||
logfiles.internal.sapsailing.com:/home/scores /home/scores nfs tcp,intr,timeo=100,retry=0" >>/etc/fstab'
|
||||
else
|
||||
echo "Not running on an AWS instance; refusing to run setup!" >&2
|
||||
echo "To prepare an instance running in AWS, provide its external IP as argument to this script." >&2
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Upgrades the AWS EC2 instance that this script is assumed to be executed on.
|
||||
# The steps are as follows:
|
||||
|
||||
. `dirname $0`/imageupgrade_functions.sh
|
||||
|
||||
run_yum_update
|
||||
run_git_pull
|
||||
download_and_install_latest_sap_jvm_8
|
||||
clean_logrotate_target
|
||||
clean_httpd_logs
|
||||
clean_servers_dir
|
||||
clean_startup_logs
|
||||
update_root_crontab
|
||||
finalize
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
environments_scripts/sailing_server/files/usr/local/bin/imageupgrade.sh
|
||||
@@ -1,102 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Upgrades the AWS EC2 instance that this script is assumed to be executed on.
|
||||
# The steps are as follows:
|
||||
|
||||
REBOOT_INDICATOR=/var/run/is-rebooted
|
||||
LOGON_USER_HOME=/root
|
||||
|
||||
run_yum_update() {
|
||||
echo "Updating packages using yum" >>/var/log/sailing.err
|
||||
yum -y update
|
||||
}
|
||||
|
||||
run_apt_update_upgrade() {
|
||||
echo "Updating packages using apt" >>/var/log/sailing.err
|
||||
apt-get -y update; apt-get -y upgrade
|
||||
apt-get -y install linux-image-cloud-amd64
|
||||
apt-get -y autoremove
|
||||
}
|
||||
|
||||
run_git_pull() {
|
||||
echo "Pulling git to /home/sailing/code" >>/var/log/sailing.err
|
||||
su - sailing -c "cd code; git pull"
|
||||
}
|
||||
|
||||
download_and_install_latest_sap_jvm_8() {
|
||||
echo "Downloading and installing latest SAP JVM 8 to /opt/sapjvm_8" >>/var/log/sailing.err
|
||||
vmpath=$( curl -s --cookie eula_3_1_agreed=tools.hana.ondemand.com/developer-license-3_1.txt https://tools.hana.ondemand.com | grep additional/sapjvm-8\..*-linux-x64.zip | head -1 | sed -e 's/^.*a href="\(additional\/sapjvm-8\..*-linux-x64\.zip\)".*/\1/' )
|
||||
if [ -n "${vmpath}" ]; then
|
||||
echo "Found VM version ${vmpath}; upgrading installation at /opt/sapjvm_8" >>/var/log/sailing.err
|
||||
if [ -z "${TMP}" ]; then
|
||||
TMP=/tmp
|
||||
fi
|
||||
echo "Downloading SAP JVM 8 as ZIP file to ${TMP}/sapjvm8-linux-x64.zip" >>/var/log/sailing.err
|
||||
curl --cookie eula_3_1_agreed=tools.hana.ondemand.com/developer-license-3_1.txt "https://tools.hana.ondemand.com/${vmpath}" > ${TMP}/sapjvm8-linux-x64.zip 2>>/var/log/sailing.err
|
||||
cd /opt
|
||||
rm -rf sapjvm_8
|
||||
if [ -f SIGNATURE.SMF ]; then
|
||||
rm -f SIGNATURE.SMF
|
||||
fi
|
||||
unzip ${TMP}/sapjvm8-linux-x64.zip >>/var/log/sailing.err
|
||||
rm -f ${TMP}/sapjvm8-linux-x64.zip
|
||||
rm -f SIGNATURE.SMF
|
||||
else
|
||||
echo "Did not find SAP JVM 8 at tools.hana.ondemand.com; not trying to upgrade" >>/var/log/sailing.err
|
||||
fi
|
||||
}
|
||||
|
||||
clean_logrotate_target() {
|
||||
echo "Clearing logrorate-targets" >>/var/log/sailing.err
|
||||
rm -rf /var/log/logrotate-target/*
|
||||
}
|
||||
|
||||
clean_httpd_logs() {
|
||||
echo "Clearing httpd logs" >>/var/log/sailing.err
|
||||
service httpd stop
|
||||
rm -rf /var/log/httpd/*
|
||||
rm -f /etc/httpd/conf.d/001-internals.conf
|
||||
}
|
||||
|
||||
clean_startup_logs() {
|
||||
echo "Clearing bootstrap logs" >>/var/log/sailing.err
|
||||
rm -f /var/log/sailing*
|
||||
# Ensure that upon the next boot the reboot indicator is not present, indicating that it's the first boot
|
||||
rm "${REBOOT_INDICATOR}"
|
||||
}
|
||||
|
||||
clean_servers_dir() {
|
||||
rm -rf /home/sailing/servers/*
|
||||
}
|
||||
|
||||
update_root_crontab() {
|
||||
# The following assumes that /root/crontab is a symbolic link to /home/sailing/code/configuration/crontabs/<the crontab appropriate
|
||||
# to the environment or user>
|
||||
# which has previously been updated by a git pull:
|
||||
cd /root
|
||||
crontab crontab
|
||||
}
|
||||
|
||||
clean_root_ssh_dir_and_tmp() {
|
||||
echo "Cleaning up ${LOGON_USER_HOME}/.ssh" >>/var/log/sailing.err
|
||||
rm -rf ${LOGON_USER_HOME}/.ssh/*
|
||||
rm -f /var/run/last_change_aws_landscape_managers_ssh_keys
|
||||
rm -rf /tmp/image-upgrade-finished
|
||||
}
|
||||
|
||||
get_ec2_user_data() {
|
||||
/opt/aws/bin/ec2-metadata -d | sed -e 's/^user-data: //'
|
||||
}
|
||||
|
||||
finalize() {
|
||||
# Finally, shut down the node unless "no-shutdown" was provided in the user data, so that a new AMI can be constructed cleanly
|
||||
if get_ec2_user_data | grep "^no-shutdown$"; then
|
||||
echo "Shutdown disabled by no-shutdown option in user data. Remember to clean /root/.ssh when done."
|
||||
touch /tmp/image-upgrade-finished
|
||||
else
|
||||
# Only clean ${LOGON_USER_HOME}/.ssh directory and /tmp/image-upgrade-finished if the next step is shutdown / image creation
|
||||
clean_root_ssh_dir_and_tmp
|
||||
rm -f /var/log/sailing.err
|
||||
shutdown -h now &
|
||||
fi
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
environments_scripts/sailing_server/files/usr/local/bin/imageupgrade_functions.sh
|
||||
@@ -1,14 +0,0 @@
|
||||
# Script to be linked from /etc/profile.d
|
||||
# Appends to PATH, sets DISPLAY for VNC running on :2, exports JAVA_HOME and Amazon EC2 variables
|
||||
|
||||
ulimit -n 100000
|
||||
ulimit -u 40000
|
||||
|
||||
# SAP JVM
|
||||
export JAVA_HOME=/opt/sapjvm_8
|
||||
# JDK 11.0.1:
|
||||
#export JAVA_HOME=/opt/jdk-11.0.1+13
|
||||
#export JAVA_HOME=/opt/jdk1.8.0_45
|
||||
export ANDROID_HOME=/opt/android-sdk-linux
|
||||
export PATH=$PATH:$JAVA_HOME/bin
|
||||
export DISPLAY=:2.0
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
environments_scripts/sailing_server/files/etc/profile.d/sailing.sh
|
||||
@@ -1,129 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Usage: Launch an Amazon EC2 instance from an Amazon Linux 2 AMI with
|
||||
# 100GB of root partition size and the "Sailing Analytics App" security group
|
||||
# using an SSH key for which you have a working private key available.
|
||||
# Then, run this script on your local computer, using the external IP address
|
||||
# of the instance you just launched in AWS as only argument. This will then
|
||||
# turn the instance into an application server for the SAP Sailing Analytics
|
||||
# application. When the script is done you may log in to look around and check
|
||||
# things. When done, shut down the instance (Stop, not Terminate) and create
|
||||
# an image off of it, naming it, e.g., "SAP Sailing Analytics 2.0" and
|
||||
# also tagging its root volume snapshot as, e.g., "SAP Sailing Analytics 2.0 (Root)".
|
||||
# If you want to use the resulting image in production, also tag it with
|
||||
# tag key "image-type" and tag value "sailing-analytics-server".
|
||||
if [ $# != 0 ]; then
|
||||
SERVER=$1
|
||||
scp "${0}" ec2-user@${SERVER}:
|
||||
ssh -A ec2-user@${SERVER} ./$( basename "${0}" )
|
||||
else
|
||||
if ec2-metadata | grep -q instance-id; then
|
||||
echo "Running on an AWS EC2 instance as user ${USER} / $(whoami), starting setup..."
|
||||
# Allow root ssh login with the same key used for the ec2-user for now;
|
||||
# later, a cron job will be installed that keeps the /root/authorized_keys file
|
||||
# up to date with all landscape managers' public SSH keys
|
||||
sudo cp /home/ec2-user/.ssh/authorized_keys /root/.ssh
|
||||
sudo chown root /root/.ssh/authorized_keys
|
||||
sudo chgrp root /root/.ssh/authorized_keys
|
||||
sudo adduser sailing
|
||||
sudo su - sailing -c "mkdir servers"
|
||||
# Create an SSH key pair with empty passphrase for ec2-user, deploy it to trac@sapsailing.com
|
||||
# and then move it to the sailing user's .ssh directory
|
||||
ssh-keygen -t ed25519 -P '' -f /home/ec2-user/.ssh/id_ed25519
|
||||
cat /home/ec2-user/.ssh/id_ed25519.pub | ssh -o StrictHostKeyChecking=false root@sapsailing.com "cat >>/home/trac/.ssh/authorized_keys"
|
||||
sudo mkdir /home/sailing/.ssh
|
||||
sudo mv /home/ec2-user/.ssh/id* /home/sailing/.ssh
|
||||
sudo chown -R sailing /home/sailing/.ssh
|
||||
sudo chgrp -R sailing /home/sailing/.ssh
|
||||
sudo chmod 700 /home/sailing/.ssh
|
||||
# Install standard packages:
|
||||
sudo yum -y update
|
||||
sudo yum -y install git tmux nvme-cli chrony cronie cronie-anacron jq telnet mailx
|
||||
# Force acceptance of sapsailing.com's host key:
|
||||
sudo su - sailing -c "ssh -o StrictHostKeyChecking=false trac@sapsailing.com ls" >/dev/null
|
||||
# Clone Git to /home/sailing/code
|
||||
sudo su - sailing -c "git clone ssh://trac@sapsailing.com/home/trac/git code"
|
||||
# Install SAP JVM 8:
|
||||
sudo mkdir -p /opt
|
||||
sudo su - -c "source /home/sailing/code/configuration/imageupgrade_functions.sh; download_and_install_latest_sap_jvm_8"
|
||||
# Install sailing.sh script to /etc/profile.d
|
||||
sudo ln -s /home/sailing/code/configuration/sailing.sh /etc/profile.d
|
||||
# Keep Amazon Linux from patching root's authorized_keys file:
|
||||
sudo sed -i -e 's/disable_root: *true/disable_root: false/' /etc/cloud/cloud.cfg
|
||||
# Configure SSH daemon:
|
||||
sudo su - -c "cat << EOF >>/etc/ssh/sshd_config
|
||||
PermitRootLogin without-password
|
||||
PermitRootLogin Yes
|
||||
MaxStartups 100
|
||||
EOF
|
||||
"
|
||||
# Increase limits
|
||||
sudo su - -c "cat << EOF >>/etc/sysctl.conf
|
||||
# number of connections the firewall can track
|
||||
net.ipv4.ip_conntrac_max = 131072
|
||||
EOF
|
||||
"
|
||||
# Install mountnvmeswap stuff
|
||||
sudo ln -s /home/sailing/code/configuration/sailing_server_setup/mountnvmeswap /usr/local/bin
|
||||
sudo ln -s /home/sailing/code/configuration/sailing_server_setup/mountnvmeswap.service /etc/systemd/system
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable mountnvmeswap.service
|
||||
# Install MongoDB 4.4 and configure as replica set "replica"
|
||||
sudo su - -c "cat << EOF >/etc/yum.repos.d/mongodb-org.4.4.repo
|
||||
[mongodb-org-4.4]
|
||||
name=MongoDB Repository
|
||||
baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/4.4/x86_64/
|
||||
gpgcheck=1
|
||||
enabled=1
|
||||
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
|
||||
EOF
|
||||
"
|
||||
sudo yum -y update
|
||||
sudo yum -y install mongodb-org-server mongodb-org-shell mongodb-org-tools
|
||||
sudo su - -c "cat << EOF >>/etc/mongod.conf
|
||||
replication:
|
||||
replSetName: replica
|
||||
EOF
|
||||
"
|
||||
sudo sed -i -e 's/bindIp: *[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/bindIp: 0.0.0.0/' /etc/mongod.conf
|
||||
# Install cron job for ssh key update for landscape managers
|
||||
sudo ln -s /home/sailing/code/configuration/update_authorized_keys_for_landscape_managers /usr/local/bin
|
||||
sudo ln -s /home/sailing/code/configuration/update_authorized_keys_for_landscape_managers_if_changed /usr/local/bin
|
||||
sudo ln -s /home/sailing/code/configuration/sailing_server_setup/crontab-root /root/crontab
|
||||
sudo su - -c "crontab /root/crontab"
|
||||
scp root@sapsailing.com:ssh-key-reader.token /tmp
|
||||
sudo mv /tmp/ssh-key-reader.token /root
|
||||
sudo chown root /root/ssh-key-reader.token
|
||||
sudo chgrp root /root/ssh-key-reader.token
|
||||
sudo chmod 600 /root/ssh-key-reader.token
|
||||
# Install /etc/init.d/sailing start-up / shut-down service
|
||||
sudo ln -s /home/sailing/code/configuration/sailing /etc/init.d/sailing
|
||||
sudo ln -s /home/sailing/code/configuration/sailing_server_setup/sailing.service /etc/systemd/system
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable sailing.service
|
||||
# Install secrets
|
||||
scp root@sapsailing.com:secrets /tmp
|
||||
scp root@sapsailing.com:mail.properties /tmp
|
||||
sudo mv /tmp/secrets /root
|
||||
sudo mv /tmp/mail.properties /root
|
||||
sudo chown root /root/secrets
|
||||
sudo chgrp root /root/secrets
|
||||
sudo chmod 600 /root/secrets
|
||||
sudo chown root /root/mail.properties
|
||||
sudo chgrp root /root/mail.properties
|
||||
sudo chmod 600 /root/mail.properties
|
||||
# Create some swap space for the case mountnvmeswap hasn't created any
|
||||
sudo dd if=/dev/zero of=/var/cache/swapfile bs=1M count=6000
|
||||
sudo chown root /var/cache/swapfile
|
||||
sudo chgrp root /var/cache/swapfile
|
||||
sudo chmod 600 /var/cache/swapfile
|
||||
sudo mkswap /var/cache/swapfile
|
||||
# And while adding to /etc/fstab, also add the NFS mount of /home/scores:
|
||||
sudo mkdir /home/scores
|
||||
sudo su - -c 'echo "/var/cache/swapfile none swap pri=0 0 0
|
||||
logfiles.internal.sapsailing.com:/home/scores /home/scores nfs tcp,intr,timeo=100,retry=0" >>/etc/fstab'
|
||||
else
|
||||
echo "Not running on an AWS instance; refusing to run setup!" >&2
|
||||
echo "To prepare an instance running in AWS, provide its external IP as argument to this script." >&2
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
@@ -0,0 +1 @@
|
||||
../environments_scripts/sailing_server/setup-sailing-server.sh
|
||||
Reference in new issue
Block a user