diff --git a/site/get_hosts b/site/get_hosts new file mode 100644 index 0000000..c3f6ed7 --- /dev/null +++ b/site/get_hosts @@ -0,0 +1,3 @@ +#!/bin/sh + +nslookup tasks.ondemand_mpi2_worker | grep Addr | cut -d':' -f2 | grep -v 127.0. diff --git a/site/mpi_bootstrap b/site/mpi_bootstrap new file mode 100644 index 0000000..f13381a --- /dev/null +++ b/site/mpi_bootstrap @@ -0,0 +1,73 @@ +#!/bin/sh + +ROLE="undefined" +MPI_MASTER_SERVICE_NAME="mpi2_master" +MPI_WORKER_SERVICE_NAME="mpi2_worker" + +####################### +# 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 + ;; + + mpi_master_service_name) + [ "$VALUE" ] && MPI_MASTER_SERVICE_NAME=$VALUE + ;; + + mpi_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 + "master") + + # Auto update default host file in background and dumb all output + auto_update_hosts "${HYDRA_HOST_FILE}" > /dev/null 2>&1 & + + /bin/bash /home/ubuntu/startup.sh + # Start ssh server + #/usr/sbin/sshd -D + ;; + + + "worker") + + # Start ssh server in background + /bin/bash /home/ubuntu/startup.sh & + /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} \ + "tail -f /dev/null" + done + ;; + *) + echo 'role argument only accepts "master" or "worker"' +esac diff --git a/site/startup.sh b/site/startup.sh new file mode 100644 index 0000000..3f01999 --- /dev/null +++ b/site/startup.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +#if [ ! -f $HOME/.vnc/passwd ] ; then +# +# if [ -z "$PASSWORD" ] ; then +# PASSWORD=`pwgen -c -n -1 12` +# echo -e "PASSWORD = $PASSWORD" > $HOME/password.txt +# fi +# +# echo "$USER:$PASSWORD" | chpasswd +# +# # Set up vncserver +# su $USER -c "mkdir $HOME/.vnc && echo '$PASSWORD' | vncpasswd -f > $HOME/.vnc/passwd && chmod 600 $HOME/.vnc/passwd && touch $HOME/.Xresources" +##vncpasswd -f <<<"write"$'\n'"view" >"$HOME/.vnc/passwd" +#vncpasswd -f >"$HOME/.vnc/passwd" < $HOME/ngrok/Ngrok_URL.txt" +# esac +#fi +# +#if [ "$SERVERROLE" == "master" ] ; then +#nslookup tasks.$SERVICENAME | grep Addr | cut -d':' -f2 | grep -v 127.0. > /tmp/hoststmp +#echo "" > /home/ubuntu/vnc.config.d/token.list +#c=1 +#while read -r line; +# do +# echo "s$c: $line:5901" >> /home/ubuntu/vnc.config.d/token.list +# ((c++)) +#done < /tmp/hoststmp +#fi +# + +/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf diff --git a/site/supervisor.conf b/site/supervisor.conf new file mode 100644 index 0000000..95bbfea --- /dev/null +++ b/site/supervisor.conf @@ -0,0 +1,10 @@ +[program:apache2] +command=bash -c 'sleep 5 && /usr/sbin/apache2 -DFOREGROUND' +autorestart=true + +[program:sshd] +#command=bash -c 'sleep 5 && /usr/sbin/sshd -D' +command=/usr/sbin/sshd -D +stdout_logfile=/var/log/sshd.log +autorestart=true +