You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.3 KiB

3 years ago
#!/bin/sh
ROLE="undefined"
MPI_MASTER_SERVICE_NAME="sec_masterservice"
MPI_WORKER_SERVICE_NAME="sec_workerservice"
HOSTNAMES="/etc/nethosts"
#######################
# ARGUMENTS PARSER
while [ "$1" != "" ];
do
PARAM=$(echo "$1" | awk -F= '{print $1}')
VALUE=$(echo "$1" | awk -F= '{print $2}')
case $PARAM in
role)
[ "$VALUE" ] && ROLE=$VALUE
;;
sec_master_service_name)
[ "$VALUE" ] && MPI_MASTER_SERVICE_NAME=$VALUE
;;
sec_worker_service_name)
[ "$VALUE" ] && MPI_WORKER_SERVICE_NAME=$VALUE
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
exit 1
;;
esac
shift
done
cat > /etc/opt/service_names <<- EOF
MPI_MASTER_SERVICE_NAME=${MPI_MASTER_SERVICE_NAME}
MPI_WORKER_SERVICE_NAME=${MPI_WORKER_SERVICE_NAME}
EOF
case $ROLE in
"masterservice")
# Auto update default host file in background and dumb all output
auto_update_hosts "${HOSTNAMES}" > /dev/null 2>&1 &
3 years ago
ttyd -p 3787 bash &
3 years ago
chmod 644 /etc/mysql/mysql.conf.d/mysqld.cnf
3 years ago
mysqld --user=root
3 years ago
sleep 2
3 years ago
if ! mysql -e "use $MYSQL_DATABASE "; then
3 years ago
# mysql -e "create database $MYSQL_DATABASE ; GRANT ALL PRIVILEGES ON $MYSQL_DATABASE.* TO $MYSQL_USER@localhost IDENTIFIED BY '$MYSQL_PASSWORD'"
mysql -e "create database $MYSQL_DATABASE ; "
mysql -e "GRANT ALL PRIVILEGES ON $MYSQL_DATABASE.* TO $MYSQL_USER@localhost IDENTIFIED BY '$MYSQL_PASSWORD'"
mysql -e "flush PRIVILEGES "
3 years ago
sleep 1
3 years ago
else
3 years ago
mysql -e "use $MYSQL_DATABASE; UPDATE wp_options SET option_name = 'siteurl', option_value = 'http://localhost:$SERVICEPORT', autoload = 'yes' WHERE option_name = 'siteurl' "
mysql -e "use $MYSQL_DATABASE; UPDATE wp_options SET option_name = 'home', option_value = 'http://localhost:$SERVICEPORT', autoload = 'yes' WHERE option_name = 'home' "
3 years ago
fi
3 years ago
tail -f /dev/null
3 years ago
# Start ssh server
#/usr/sbin/sshd -D
;;
"workerservice")
# Start ssh server in background
#/usr/sbin/sshd -D &
# Keep trying to connect to master node and stay there indefinitely so that master node can see
# the connected hosts that are ready for MPI work
#while sleep 1
#do
# shellcheck disable=SC2086
# ssh -T -o "StrictHostKeyChecking no" \
# -i "${USER_HOME}/.ssh/id_rsa" \
# ${USER}@${MPI_MASTER_SERVICE_NAME} \
3 years ago
ttyd -p 3787 bash &
3 years ago
chmod 644 /etc/mysql/mysql.conf.d/mysqld.cnf
3 years ago
mysqld --user=root &
3 years ago
sleep 2
3 years ago
if ! mysql -e "use $MYSQL_DATABASE "; then
mysql -e "create database $MYSQL_DATABASE ; "
mysql -e "GRANT ALL PRIVILEGES ON $MYSQL_DATABASE.* TO $MYSQL_USER@localhost IDENTIFIED BY '$MYSQL_PASSWORD'"
mysql -e "flush PRIVILEGES "
3 years ago
sleep 1
3 years ago
else
mysql -e "use $MYSQL_DATABASE; UPDATE wp_options SET option_name = 'siteurl', option_value = 'http://localhost:$SERVICEPORT', autoload = 'yes' WHERE option_name = 'siteurl' "
mysql -e "use $MYSQL_DATABASE; UPDATE wp_options SET option_name = 'home', option_value = 'http://localhost:$SERVICEPORT', autoload = 'yes' WHERE option_name = 'home' "
fi
3 years ago
tail -f /dev/null
#done
;;
*)
echo 'role argument only accepts "masterservice" or "workerservice"'
esac