From a3f6fdf3d0807e0fab8dce925563c78785838cc7 Mon Sep 17 00:00:00 2001 From: Wil Gieseler Date: Sun, 9 Feb 2014 13:12:17 -0800 Subject: [PATCH 1/9] try that no-ip --- minecloud/launcher/tasks.py | 11 +++++++++++ templates/launcher/index.html | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/minecloud/launcher/tasks.py b/minecloud/launcher/tasks.py index cbed400..893cece 100644 --- a/minecloud/launcher/tasks.py +++ b/minecloud/launcher/tasks.py @@ -12,6 +12,8 @@ from .models import Instance from .sseview import send_event +import urllib2 + @task def launch(instance_id): # Retrive instance obj from DB. @@ -64,6 +66,15 @@ def launch(instance_id): instance.save() send_event('instance_state', instance.state) + # Update dynamic IP + dynamic_ip_hostname = os.getenv('NO_IP_HOSTNAME', None) + dynamic_ip_username = os.getenv('NO_IP_USERNAME', None) + dynamic_ip_password = os.getenv('NO_IP_PASSWORD', None) + if dynamic_ip_hostname and dynamic_ip_username and dynamic_ip_password: + opener = urllib2.build_opener() + opener.addheaders = [('User-agent', 'Minecloud-No-IP/1.0 http://github.com/toffer/minecloud')] + response = opener.open("http://" + urllib2.urlencode(dynamic_ip_username) + ":" + urllib2.urlencode(dynamic_ip_password) + "@dynupdate.no-ip.com/nic/update?hostname=" + urllib2.urlencode(dynamic_ip_hostname) + "&myip=" + urllib2.urlencode(server.ip_address)) + # Send task to check if instance is running check_state.delay(instance_id, 'running') diff --git a/templates/launcher/index.html b/templates/launcher/index.html index 001b4ff..6d23da4 100644 --- a/templates/launcher/index.html +++ b/templates/launcher/index.html @@ -41,6 +41,12 @@

Server Info

IP Address {{ instance.ip_address }} + {% if os.getenv('NO_IP_HOSTNAME', None) %} + + Hostname + {{ os.getenv('NO_IP_HOSTNAME', None) }} + + {% endif %} Start Time {{ instance.start }} @@ -74,6 +80,12 @@

Server Info

IP Address {{ instance.ip_address }} + {% if os.getenv('NO_IP_HOSTNAME', None) %} + + Hostname + {{ os.getenv('NO_IP_HOSTNAME', None) }} + + {% endif %} Start Time {{ instance.start }} @@ -177,6 +189,6 @@

Server is sleeping.

location.reload(true) }, false); - }); + }); {% endblock content %} \ No newline at end of file From a9963d11c3a039c7ada465163383d08e77560284 Mon Sep 17 00:00:00 2001 From: Wil Gieseler Date: Sun, 9 Feb 2014 13:30:46 -0800 Subject: [PATCH 2/9] oh right django --- minecloud/launcher/views.py | 1 + templates/launcher/index.html | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/minecloud/launcher/views.py b/minecloud/launcher/views.py index 3560070..26803d2 100644 --- a/minecloud/launcher/views.py +++ b/minecloud/launcher/views.py @@ -13,6 +13,7 @@ @login_required def index(request): + no_ip_hostname = os.getenv('NO_IP_HOSTNAME', None) instance = None current_sessions = None err_msg = None diff --git a/templates/launcher/index.html b/templates/launcher/index.html index 6d23da4..3f9c2d1 100644 --- a/templates/launcher/index.html +++ b/templates/launcher/index.html @@ -41,10 +41,10 @@

Server Info

IP Address {{ instance.ip_address }} - {% if os.getenv('NO_IP_HOSTNAME', None) %} + {% if no_ip_hostname %} Hostname - {{ os.getenv('NO_IP_HOSTNAME', None) }} + {{ no_ip_hostname }} {% endif %} @@ -80,10 +80,10 @@

Server Info

IP Address {{ instance.ip_address }} - {% if os.getenv('NO_IP_HOSTNAME', None) %} + {% if no_ip_hostname %} Hostname - {{ os.getenv('NO_IP_HOSTNAME', None) }} + {{ no_ip_hostname }} {% endif %} From 99afdbedfdd286b50e169f15871b42a6063da936 Mon Sep 17 00:00:00 2001 From: Wil Gieseler Date: Sun, 9 Feb 2014 13:32:10 -0800 Subject: [PATCH 3/9] import os --- minecloud/launcher/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/minecloud/launcher/views.py b/minecloud/launcher/views.py index 26803d2..4c9e86e 100644 --- a/minecloud/launcher/views.py +++ b/minecloud/launcher/views.py @@ -10,6 +10,7 @@ from .models import Instance, Session from .sseview import SseView, send_event +import os @login_required def index(request): From fbabbe82dc4be51e6304d5638e5eb90c3f973621 Mon Sep 17 00:00:00 2001 From: Wil Gieseler Date: Sun, 9 Feb 2014 13:44:58 -0800 Subject: [PATCH 4/9] correctly send that get request --- minecloud/launcher/tasks.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/minecloud/launcher/tasks.py b/minecloud/launcher/tasks.py index 893cece..b16e740 100644 --- a/minecloud/launcher/tasks.py +++ b/minecloud/launcher/tasks.py @@ -12,7 +12,10 @@ from .models import Instance from .sseview import send_event +import urllib import urllib2 +import base64 +import string @task def launch(instance_id): @@ -72,8 +75,10 @@ def launch(instance_id): dynamic_ip_password = os.getenv('NO_IP_PASSWORD', None) if dynamic_ip_hostname and dynamic_ip_username and dynamic_ip_password: opener = urllib2.build_opener() - opener.addheaders = [('User-agent', 'Minecloud-No-IP/1.0 http://github.com/toffer/minecloud')] - response = opener.open("http://" + urllib2.urlencode(dynamic_ip_username) + ":" + urllib2.urlencode(dynamic_ip_password) + "@dynupdate.no-ip.com/nic/update?hostname=" + urllib2.urlencode(dynamic_ip_hostname) + "&myip=" + urllib2.urlencode(server.ip_address)) + auth = base64.encodestring('%s:%s' % (dynamic_ip_username, dynamic_ip_password)).replace('\n', '') + opener.addheaders = [('User-agent', 'Minecloud-No-IP/1.0 http://github.com/toffer/minecloud'), ("Authorization", "Basic %s" % auth)] + url = "http://dynupdate.no-ip.com/nic/update?hostname=" + urllib.quote_plus(dynamic_ip_hostname) + "&myip=" + urllib.quote_plus(server.ip_address) + opener.open(url) # Send task to check if instance is running check_state.delay(instance_id, 'running') From d95e5affbb1cfed282c71852f27b62d8d962fccf Mon Sep 17 00:00:00 2001 From: Wil Gieseler Date: Sun, 9 Feb 2014 13:51:12 -0800 Subject: [PATCH 5/9] correctly pass hostname to view --- minecloud/launcher/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/minecloud/launcher/views.py b/minecloud/launcher/views.py index 4c9e86e..4032447 100644 --- a/minecloud/launcher/views.py +++ b/minecloud/launcher/views.py @@ -14,12 +14,11 @@ @login_required def index(request): - no_ip_hostname = os.getenv('NO_IP_HOSTNAME', None) instance = None current_sessions = None err_msg = None running_instances = Instance.objects.exclude(state__exact='terminated') - if len(running_instances) == 1: + if len(running_instances) == 1: instance = running_instances[0] current_sessions = (Session.objects .filter(instance_id__exact=instance.id) @@ -27,12 +26,13 @@ def index(request): ) elif len(running_instances) > 1: err_msg = "Error: Multiple instances are running at once." - return render(request, + return render(request, 'launcher/index.html', {'instance': instance, 'sessions': current_sessions, + 'no_ip_hostname': os.getenv('NO_IP_HOSTNAME', None), 'err_msg': err_msg}) - + @login_required @require_POST def launch(request): From 75482d56e532f0e922ccaffa4e5fe2e5bd0c58b5 Mon Sep 17 00:00:00 2001 From: Wil Gieseler Date: Sun, 9 Feb 2014 13:59:48 -0800 Subject: [PATCH 6/9] display the hostname prominently if available --- templates/launcher/index.html | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/templates/launcher/index.html b/templates/launcher/index.html index 3f9c2d1..65c0d3f 100644 --- a/templates/launcher/index.html +++ b/templates/launcher/index.html @@ -30,7 +30,14 @@

Server Info

{% elif instance and instance.state == 'pending' %}
-

Server is waking up at {{ instance.ip_address }}.

+

Server is waking up at + + {% if no_ip_hostname %} + {{ no_ip_hostname }} + {% else %} + {{ instance.ip_address }} + {% endif %} + .

Now, it's restoring saved game data. Almost ready...

@@ -62,7 +69,15 @@

Server Info

{% elif instance and instance.state == 'running' %}
-

Server is running at {{ instance.ip_address }}.

+

Server is running at + + {% if no_ip_hostname %} + {{ no_ip_hostname }} + {% else %} + {{ instance.ip_address }} + {% endif %} + . +

From e63be498f1330a0e892293bfbdb06cee3ac2244b Mon Sep 17 00:00:00 2001 From: Wil Gieseler Date: Sun, 9 Feb 2014 14:02:51 -0800 Subject: [PATCH 7/9] explanatory text changes if you have a hostname --- templates/launcher/index.html | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/templates/launcher/index.html b/templates/launcher/index.html index 65c0d3f..991759f 100644 --- a/templates/launcher/index.html +++ b/templates/launcher/index.html @@ -37,7 +37,8 @@

Server is waking up at {% else %} {{ instance.ip_address }} {% endif %} - .

+ +

Now, it's restoring saved game data. Almost ready...

@@ -50,7 +51,7 @@

Server Info

{% if no_ip_hostname %} - Hostname + DDNS Hostname {{ no_ip_hostname }} {% endif %} @@ -76,15 +77,21 @@

Server is running at {% else %} {{ instance.ip_address }} {% endif %} - . +

Join the server!

    + {% if no_ip_hostname %} +
  • Open Minecraft, click Multiplayer, and add a new server.
  • +
  • Copy above hostname into the Server Address field.
  • + {% else %}
  • Open Minecraft, click Multiplayer, and edit the Server Info.
  • Copy the IP address into the Server Address field.
  • +
  • This IP address will change each time the server is restarted.
  • + {% endif %}
@@ -97,7 +104,7 @@

Server Info

{% if no_ip_hostname %} - Hostname + DDNS Hostname {{ no_ip_hostname }} {% endif %} From ee0962ccad4cf1a23206928e0416b83c017015e1 Mon Sep 17 00:00:00 2001 From: Wil Gieseler Date: Sun, 9 Feb 2014 14:09:41 -0800 Subject: [PATCH 8/9] Add DDNS config vars to readme --- README.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.rst b/README.rst index efa3f69..570c596 100644 --- a/README.rst +++ b/README.rst @@ -109,6 +109,14 @@ Steps to get up-and-running on Heroku: # to set the MCL_EC2_REGION variable $ heroku config:set MCL_EC2_REGION= + # Optional Dynamic DNS Settings + # If you don't want to have a constantly-changing IP address, you can add your + # login credentials for https://www.noip.com (a free service that will give you) + # a URL that Minecloud will automatically point to your server IP. + $ heroku config:set NO_IP_HOSTNAME=my-great-hostname.servegame.com + $ heroku config:set NO_IP_USERNAME=me@example.com + $ heroku config:set NO_IP_PASSWORD=secretpassword + # Review all your settings $ heroku config From 1ce216f084dd58d16d192e50768987730ec55ca5 Mon Sep 17 00:00:00 2001 From: Wil Gieseler Date: Sun, 9 Feb 2014 14:10:52 -0800 Subject: [PATCH 9/9] Fix language in readme --- README.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 570c596..371e5fe 100644 --- a/README.rst +++ b/README.rst @@ -111,8 +111,10 @@ Steps to get up-and-running on Heroku: # Optional Dynamic DNS Settings # If you don't want to have a constantly-changing IP address, you can add your - # login credentials for https://www.noip.com (a free service that will give you) - # a URL that Minecloud will automatically point to your server IP. + # login credentials for https://www.noip.com (which is free!) + # + # This service gives you a URL that Minecloud will automatically point + # to your server IP and keep up to date. $ heroku config:set NO_IP_HOSTNAME=my-great-hostname.servegame.com $ heroku config:set NO_IP_USERNAME=me@example.com $ heroku config:set NO_IP_PASSWORD=secretpassword