diff --git a/odinms/Dockerfile b/odinms/Dockerfile index 176b26cc..a4eb2e2d 100644 --- a/odinms/Dockerfile +++ b/odinms/Dockerfile @@ -1,10 +1,5 @@ FROM java:6 -RUN apt-get update -RUN apt-get install -y vim - -RUN echo 'alias ll="ls -lha --color=auto"' >> ~/.bashrc - WORKDIR /odinms COPY thepack_82 . @@ -14,3 +9,5 @@ EXPOSE 7576 EXPOSE 7577 EXPOSE 7578 EXPOSE 8484 + +CMD ["/bin/bash","compile_and_run.sh"] diff --git a/odinms/thepack_82/ThePack/channel.properties b/odinms/thepack_82/ThePack/channel.properties index b549dfdf..5792a0a2 100644 --- a/odinms/thepack_82/ThePack/channel.properties +++ b/odinms/thepack_82/ThePack/channel.properties @@ -1,4 +1,4 @@ -net.sf.odinms.world.host=THIS_IP +net.sf.odinms.world.host=maplestory net.sf.odinms.channel.count=2 net.sf.odinms.channel.0.key=release1 net.sf.odinms.channel.1.key=release2 diff --git a/odinms/thepack_82/ThePack/db.properties b/odinms/thepack_82/ThePack/db.properties index 12447631..4eee62fd 100644 --- a/odinms/thepack_82/ThePack/db.properties +++ b/odinms/thepack_82/ThePack/db.properties @@ -1,4 +1,4 @@ driver=com.mysql.jdbc.Driver -url=jdbc:mysql://ODINMS_MYSQL_CONTAINER_IP_ADDRESS/odinms +url=jdbc:mysql://maplestory-db/odinms user = root password = root diff --git a/odinms/thepack_82/ThePack/login.properties b/odinms/thepack_82/ThePack/login.properties index b483b497..599f242f 100644 --- a/odinms/thepack_82/ThePack/login.properties +++ b/odinms/thepack_82/ThePack/login.properties @@ -1,2 +1,2 @@ -net.sf.odinms.world.host=THIS_IP +net.sf.odinms.world.host=maplestory net.sf.odinms.login.key=releaselogin diff --git a/odinms/thepack_82/ThePack/run.sh b/odinms/thepack_82/ThePack/run.sh index 28da75fa..68b1c4de 100644 --- a/odinms/thepack_82/ThePack/run.sh +++ b/odinms/thepack_82/ThePack/run.sh @@ -1,12 +1,5 @@ #!/usr/bin/env bash -THIS_IP=`grep $HOSTNAME /etc/hosts | awk '{print $1}'` - -sed -i "s/ODINMS_MYSQL_CONTAINER_IP_ADDRESS/$ODINMS_MYSQL_CONTAINER_IP_ADDRESS/" db.properties -sed -i "s/THIS_IP/$THIS_IP/" world.properties -sed -i "s/THIS_IP/$THIS_IP/" login.properties -sed -i "s/THIS_IP/$THIS_IP/" channel.properties - java -cp '.:dist/*' -Dnet.sf.odinms.recvops=recvops.properties -Dnet.sf.odinms.sendops=sendops.properties -Dnet.sf.odinms.wzpath=wz -Djavax.net.ssl.keyStore=filename.keystore -Djavax.net.ssl.keyStorePassword=passwd -Djavax.net.ssl.trustStore=filename.keystore -Djavax.net.ssl.trustStorePassword=passwd net.sf.odinms.net.world.WorldServer & sleep 10 java -cp '.:dist/*' -Dnet.sf.odinms.recvops=recvops.properties -Dnet.sf.odinms.sendops=sendops.properties -Dnet.sf.odinms.wzpath=wz -Dnet.sf.odinms.login.config=login.properties -Djavax.net.ssl.keyStore=filename.keystore -Djavax.net.ssl.keyStorePassword=passwd -Djavax.net.ssl.trustStore=filename.keystore -Djavax.net.ssl.trustStorePassword=passwd net.sf.odinms.net.login.LoginServer & diff --git a/odinms/thepack_82/compile_and_run.sh b/odinms/thepack_82/compile_and_run.sh index daf32837..bc539a8d 100644 --- a/odinms/thepack_82/compile_and_run.sh +++ b/odinms/thepack_82/compile_and_run.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash +sed -i "s/THIS_IP/$THIS_IP/g" ./ThePack/world.properties + cd ThePack source compile.sh && source run.sh + +sleep infinity diff --git a/run.sh b/run.sh index ed3a8105..99af649e 100644 --- a/run.sh +++ b/run.sh @@ -1,13 +1,38 @@ #!/usr/bin/env bash +# Build images. docker build -t odinms_mysql odinms_mysql docker build -t odinms odinms -ODINMS_MYSQL_CONTAINER_ID=`docker run -d -p 3306:3306 odinms_mysql` +# Create private bridge network - connects the game and database servers. +NETWORK=`docker network ls | grep thepack | awk {'print $2'}` +if [[ ! $NETWORK == "thepack" ]]; then + docker network create thepack +fi -ODINMS_MYSQL_CONTAINER_IP_ADDRESS=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' $ODINMS_MYSQL_CONTAINER_ID` +# Create volume for MySQL data. +VOLUME=`docker volume ls | grep -w thepack-db | awk {'print $2'}` +if [[ ! $VOLUME == "thepack-db" ]]; then + docker volume create thepack-db +fi -#docker run -it --rm -e ODINMS_MYSQL_CONTAINER_IP_ADDRESS=$ODINMS_MYSQL_CONTAINER_IP_ADDRESS -p 7575:7575 -p 7576:7576 -p 7577:7577 -p 7578:7578 -p 8484:8484 odinms bash -c 'source compile_and_run.sh' -docker run -it --rm -e ODINMS_MYSQL_CONTAINER_IP_ADDRESS=$ODINMS_MYSQL_CONTAINER_IP_ADDRESS -p 7575:7575 -p 7576:7576 -p 7577:7577 -p 7578:7578 -p 8484:8484 odinms bash +# Run containers. +DB_CONTAINER=`docker container ps | grep -w odinms_mysql | awk {'print $2'}` +if [[ ! $DB_CONTAINER == "odinms_mysql" ]]; then + docker run -d --volume thepack-db:/var/lib/mysql --network thepack --name maplestory-db odinms_mysql +fi -docker rm -f $ODINMS_MYSQL_CONTAINER_ID +# Sleep needed to avoid race condition. +sleep 5 + +MS_CONTAINER=`docker container ps | grep -w odinms | awk {'print $2'}` +if [[ ! $MS_CONTAINER == "odinms" ]]; then + + # Best effort attempt at getting the server IP address. idk, better than localhost? + HOST_IP=`ifconfig | grep -w inet | grep -v 127.0.0.1 | grep -v broadcast\ 172 | awk {'print $2'} | tail -n 1` + + docker run -d -e THIS_IP=${HOST_IP} -p 7575:7575 -p 7576:7576 -p 7577:7577 -p 7578:7578 -p 8484:8484 --network thepack --name maplestory odinms + + # Add "maplestory" container to the default bridge network - so it can use the host IP. + docker network connect bridge maplestory +fi