Skip to content
Permalink
main
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
@echo off
rem *************** VARIABLES ***************
rem *** Docker subnet for the cluster (admin box IP is %SUBNET%.254) ***
set CLUSTERNET=clusternet
set SUBNET=172.16.0
set NETMASK=16
rem *** Local folder to store /home of all the containers ***
set HOMES=clusterhomes
if not exist %HOMES% (mkdir %HOMES%)
set LOCALSHARE=%~dp0%HOMES%
rem *** wipe the user home if exists ? 0/1 ***
set WIPEHOME=1
rem *** cleaning up previous stuff ***
rem docker rm --force $(docker ps -a -q)
docker network rm clusternet
rem *** CREATING NEW DOCKER SUBNET "clusternet" FOR THE CLUSTER ***
docker network create --subnet=%SUBNET%.0/%NETMASK% %CLUSTERNET%
rem *************** CREATING ADMIN NODE IMAGE ***************
cd "admin_node"
docker build . -t admin_node
cd ..
rem *** admin box is hooked up to :99 local VNC display ***
docker run -ti -d -p 5999:5901 --mount src=%LOCALSHARE%,target=/home,type=bind --net %CLUSTERNET% --ip %SUBNET%.254 --name admin --hostname admin admin_node
rem *************** CREATING CLIENT NODES ***************
cd "client_node"
docker build . -t client_node
cd ..
rem *** READING LIST OF USERS AND PASSWORDS ***
set USERLIST="userlist.txt"
set /a n=0
set /a vncport=5900
setlocal ENABLEDELAYEDEXPANSION
FOR /F "tokens=1,2 usebackq delims=. " %%a in (%USERLIST%) do (
set /a n=n+1
rem *** local VNC port to hook up the client to ***
set /a vncport=5900+n
set node=%%a
set passwd=%%b
rem *** username, UID:GID on all clients ***
set user=!node!
set /a uid=1000+!n!
set /a gid=1000+!n!
set /a IP=100+!n!
echo starting node: !node!, IP=172.16.0.!IP!, user !user!, UID !uid!, GID !gid!, password !passwd!, vncport !vncport!
docker run -ti -d -p !vncport!:5901 --mount src=!LOCALSHARE!,target=/home,type=bind --net !CLUSTERNET! --ip !SUBNET!.!IP! --name !node! --hostname !node! client_node
rem *** ADD USER and CHANGE PASSWORDS ***
docker exec -ti !node! groupadd -g !gid! !user!
rem *** careful here (delete existing home folder of the user? set WIPEHOME to 0 above if not)***
if %WIPEHOME%==1 docker exec -ti !node! rm -fr /home/!user!
docker exec -ti !node! mkdir -p /home/!user!
docker exec -ti !node! useradd -u !uid! -g !gid! -d /home/!user! -s /bin/bash !user!
docker exec -ti !node! chown -R !user!:!user! /home/!user!/
docker exec -ti !node! chmod o-r,o-w,o-x /home/!user!/
docker exec -ti -u !user! !node! mkdir -p /home/!user!/.vnc
docker exec -ti -u !user! !node! mkdir -p /home/!user!/Desktop
docker exec -ti -u !user! !node! cp /opt/seamonkey/Seamonkey.desktop /home/!user!/Desktop/
docker exec -ti -u !user! !node! /bin/bash -c "echo !passwd! | /opt/TurboVNC/bin/vncpasswd -f > /home/!user!/.vnc/passwd"
docker exec -ti -u !user! !node! chmod 600 /home/!user!/.vnc/passwd
docker exec -ti !node! /bin/bash -c "echo !user!:!passwd! | chpasswd"
rem *** sudo for user ? ***
docker exec -ti !node! usermod -aG sudo !user!
rem *** start user's VNC server ***
docker exec -u !user! !node! bash -c "/bin/startvnc"
rem *** SSHD for inside cluster comms only (for root from admin container) ***
docker exec !node! bash -c "service ssh start"
rem *** add client to PDSH list and hosts file on admin node ***
docker exec -ti admin bash -c "echo !node! >> /etc/pdsh/machines"
docker exec -ti admin bash -c "echo %SUBNET%.!IP! !node! >> /etc/hosts"
)
endlocal